1
0
Fork 0
mirror of https://github.com/Luzifer/elb-instance-status.git synced 2024-11-08 05:50:06 +00:00

Fix memory leak as of unclosed loggers

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2024-04-28 12:47:46 +02:00
parent 84df5e9f1a
commit 95473e70f3
Signed by: luzifer
SSH key fingerprint: SHA256:/xtE5lCgiRDQr8SLxHMS92ZBlACmATUmF1crK16Ks4E

View file

@ -39,12 +39,22 @@ func executeAndRegisterCheck(ctx context.Context, checkID string) {
var ( var (
check = checks[checkID] check = checks[checkID]
logger = logrus.WithField("check_id", checkID) logger = logrus.WithField("check_id", checkID)
stderr = logger.WithField("stream", "STDERR").Writer()
stdout = logger.WithField("stream", "STDOUT").Writer()
) )
defer func() {
for _, c := range []io.Closer{stderr, stdout} {
if err := c.Close(); err != nil {
logrus.WithError(err).Error("closing check log-writer (leaked mem)")
}
}
}()
cmd := exec.Command("/bin/bash", "-e", "-o", "pipefail", "-c", check.Command) //#nosec G204 // Intended to run an user-defined command cmd := exec.Command("/bin/bash", "-e", "-o", "pipefail", "-c", check.Command) //#nosec G204 // Intended to run an user-defined command
cmd.Stderr = logger.WithField("stream", "STDERR").Writer() cmd.Stderr = stderr
if cfg.Verbose { if cfg.Verbose {
cmd.Stdout = logger.WithField("stream", "STDOUT").Writer() cmd.Stdout = stdout
} }
err := cmd.Start() err := cmd.Start()