Fix memory leak in result history (#238)
authorBrian Brazil <brian.brazil@robustperception.io>
Thu, 28 Sep 2017 13:24:35 +0000 (14:24 +0100)
committerGitHub <noreply@github.com>
Thu, 28 Sep 2017 13:24:35 +0000 (14:24 +0100)
Fixes #236

history.go
main.go

index c39de0b3556457996c6b85fa0f71354cdf7d879a..8bcec657054b0f99a3857e40fa38842ba1bf932d 100644 (file)
@@ -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 80fbc112b16e610c2adb1e5f5efd239e129cdbed..fc9f813225563b032264dfb70ae4880963010819 100644 (file)
--- a/main.go
+++ b/main.go
@@ -19,6 +19,7 @@ import (
        "fmt"
        "html"
        "net/http"
+       _ "net/http/pprof"
        "os"
        "os/signal"
        "strconv"