Fix possible memory leak by defer inside loop

This commit is contained in:
huydx 2016-11-14 00:45:51 +09:00
parent e193579df8
commit c999902761

View file

@ -62,9 +62,9 @@ func (p *persistence) recoverFromCrash(fingerprintToSeries map[model.Fingerprint
if err != nil { if err != nil {
return err return err
} }
defer dir.Close()
for fis := []os.FileInfo{}; err != io.EOF; fis, err = dir.Readdir(1024) { for fis := []os.FileInfo{}; err != io.EOF; fis, err = dir.Readdir(1024) {
if err != nil { if err != nil {
dir.Close()
return err return err
} }
for _, fi := range fis { for _, fi := range fis {
@ -78,6 +78,7 @@ func (p *persistence) recoverFromCrash(fingerprintToSeries map[model.Fingerprint
} }
} }
} }
dir.Close()
} }
log.Infof("File scan complete. %d series found.", len(fpsSeen)) log.Infof("File scan complete. %d series found.", len(fpsSeen))