From c999902761c69fc034291b82f52bea2f86a60964 Mon Sep 17 00:00:00 2001 From: huydx Date: Mon, 14 Nov 2016 00:45:51 +0900 Subject: [PATCH] Fix possible memory leak by defer inside loop --- storage/local/crashrecovery.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/storage/local/crashrecovery.go b/storage/local/crashrecovery.go index db3cf6eaa..3b29da55e 100644 --- a/storage/local/crashrecovery.go +++ b/storage/local/crashrecovery.go @@ -62,9 +62,9 @@ func (p *persistence) recoverFromCrash(fingerprintToSeries map[model.Fingerprint if err != nil { return err } - defer dir.Close() for fis := []os.FileInfo{}; err != io.EOF; fis, err = dir.Readdir(1024) { if err != nil { + dir.Close() return err } 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))