Added deferred cancel to prevent context leaks

This commit is contained in:
Charlie Voiselle
2018-05-10 18:52:54 -04:00
parent 7ce1e2393d
commit 41b71b6138

View File

@@ -37,7 +37,8 @@ func Init() error {
}
var cpuInfo []cpu.InfoStat
ctx, _ := context.WithTimeout(context.Background(), cpuInfoTimeout)
ctx, cancel := context.WithTimeout(context.Background(), cpuInfoTimeout)
defer cancel()
if cpuInfo, err = cpu.InfoWithContext(ctx); err != nil {
merrs = multierror.Append(merrs, fmt.Errorf("Unable to obtain CPU information: %v", err))
}