From ef193b1d8ee7a1019c6955f9361400641112c805 Mon Sep 17 00:00:00 2001 From: Yeuoly <45712896+Yeuoly@users.noreply.github.com> Date: Sat, 14 Sep 2024 00:54:57 +0800 Subject: [PATCH] fix: memory leak (#83) --- internal/core/runner/output_capture.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/internal/core/runner/output_capture.go b/internal/core/runner/output_capture.go index d83b3d9..78211de 100644 --- a/internal/core/runner/output_capture.go +++ b/internal/core/runner/output_capture.go @@ -56,16 +56,14 @@ func (s *OutputCaptureRunner) CaptureOutput(cmd *exec.Cmd) error { timeout = 5 * time.Second } - timer := time.NewTimer(timeout) - go func() { - <-timer.C + timer := time.AfterFunc(timeout, func() { if cmd != nil && cmd.Process != nil { // write the error s.WriteError([]byte("error: timeout\n")) // send a signal to the process cmd.Process.Kill() } - }() + }) // create a pipe for the stdout stdout_reader, err := cmd.StdoutPipe()