Fix sysstat resource leak (#1792)

This commit is contained in:
David Moravek 2016-09-21 11:19:59 +02:00 committed by Cameron Sparr
parent 6648c101dd
commit 90c7475c68
1 changed files with 4 additions and 0 deletions

View File

@ -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