1
0
Fork 0
mirror of https://github.com/Luzifer/elb-instance-status.git synced 2024-12-22 10:51:19 +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 (
check = checks[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.Stderr = logger.WithField("stream", "STDERR").Writer()
cmd.Stderr = stderr
if cfg.Verbose {
cmd.Stdout = logger.WithField("stream", "STDOUT").Writer()
cmd.Stdout = stdout
}
err := cmd.Start()