From: Brian Brazil Date: Thu, 28 Sep 2017 13:24:35 +0000 (+0100) Subject: Fix memory leak in result history (#238) X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=641a05bc536249ae0d30149da8a27847041b1f94;p=blackbox_exporter.git Fix memory leak in result history (#238) Fixes #236 --- diff --git a/history.go b/history.go index c39de0b..8bcec65 100644 --- a/history.go +++ b/history.go @@ -36,7 +36,7 @@ func (rh *resultHistory) Add(moduleName, target, debugOutput string, success boo rh.mu.Lock() defer rh.mu.Unlock() - result := &result{ + r := &result{ id: rh.nextId, moduleName: moduleName, target: target, @@ -45,9 +45,11 @@ func (rh *resultHistory) Add(moduleName, target, debugOutput string, success boo } rh.nextId++ - rh.results = append(rh.results, result) + rh.results = append(rh.results, r) if len(rh.results) > 100 { - copy(rh.results, rh.results[1:]) + results := make([]*result, len(rh.results)-1) + copy(results, rh.results[1:]) + rh.results = results } } diff --git a/main.go b/main.go index 80fbc11..fc9f813 100644 --- a/main.go +++ b/main.go @@ -19,6 +19,7 @@ import ( "fmt" "html" "net/http" + _ "net/http/pprof" "os" "os/signal" "strconv"