From 90c7475c68459b043b1bb6b8ab116a2029beb661 Mon Sep 17 00:00:00 2001 From: David Moravek Date: Wed, 21 Sep 2016 11:19:59 +0200 Subject: [PATCH] Fix sysstat resource leak (#1792) --- plugins/inputs/sysstat/sysstat.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/inputs/sysstat/sysstat.go b/plugins/inputs/sysstat/sysstat.go index 795ad2f60..fe7ee6b38 100644 --- a/plugins/inputs/sysstat/sysstat.go +++ b/plugins/inputs/sysstat/sysstat.go @@ -8,6 +8,7 @@ import ( "errors" "fmt" "io" + "log" "os" "os/exec" "path" @@ -201,6 +202,9 @@ func (s *Sysstat) collect() error { cmd := execCommand(s.Sadc, options...) out, err := internal.CombinedOutputTimeout(cmd, time.Second*time.Duration(collectInterval+parseInterval)) if err != nil { + if err := os.Remove(s.tmpFile); err != nil { + log.Printf("failed to remove tmp file after %s command: %s", strings.Join(cmd.Args, " "), err) + } return fmt.Errorf("failed to run command %s: %s - %s", strings.Join(cmd.Args, " "), err, string(out)) } return nil