Merge pull request #38 from kc1212/issue-37

Defer fd.Close() (fixes #37)
This commit is contained in:
Jakob Borg 2016-03-21 14:29:47 +01:00
commit 96afcd90e3

View File

@ -95,6 +95,12 @@ func (s *statssrv) writeToFile(stats stats, secs float64) {
log.Println("stats file:", err) log.Println("stats file:", err)
return return
} }
defer func() {
err = fd.Close()
if err != nil {
log.Println("stats file:", err)
}
}()
bs, err := ioutil.ReadAll(fd) bs, err := ioutil.ReadAll(fd)
if err != nil { if err != nil {
@ -127,10 +133,4 @@ func (s *statssrv) writeToFile(stats stats, secs float64) {
log.Println("stats file:", err) log.Println("stats file:", err)
return return
} }
err = fd.Close()
if err != nil {
log.Println("stats file:", err)
return
}
} }