From 641a05bc536249ae0d30149da8a27847041b1f94 Mon Sep 17 00:00:00 2001 From: Brian Brazil Date: Thu, 28 Sep 2017 14:24:35 +0100 Subject: [PATCH] Fix memory leak in result history (#238) Fixes #236 --- history.go | 8 +++++--- main.go | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) 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" -- 2.25.1