From 41b71b6138a125df3b7f736c9ffb893b64cea8dd Mon Sep 17 00:00:00 2001 From: Charlie Voiselle Date: Thu, 10 May 2018 18:52:54 -0400 Subject: [PATCH] Added deferred cancel to prevent context leaks --- helper/stats/cpu.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/helper/stats/cpu.go b/helper/stats/cpu.go index b3596a428..c9cec2d26 100644 --- a/helper/stats/cpu.go +++ b/helper/stats/cpu.go @@ -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)) }