diff --git a/cmd/discosrv/stats.go b/cmd/discosrv/stats.go index 8a2ed9821..3e418897b 100644 --- a/cmd/discosrv/stats.go +++ b/cmd/discosrv/stats.go @@ -95,6 +95,12 @@ func (s *statssrv) writeToFile(stats stats, secs float64) { log.Println("stats file:", err) return } + defer func() { + err = fd.Close() + if err != nil { + log.Println("stats file:", err) + } + }() bs, err := ioutil.ReadAll(fd) if err != nil { @@ -127,10 +133,4 @@ func (s *statssrv) writeToFile(stats stats, secs float64) { log.Println("stats file:", err) return } - - err = fd.Close() - if err != nil { - log.Println("stats file:", err) - return - } }