瀏覽代碼

fix: memory leak (#83)

Yeuoly 1 年之前
父節點
當前提交
ef193b1d8e
共有 1 個文件被更改,包括 2 次插入4 次删除
  1. 2 4
      internal/core/runner/output_capture.go

+ 2 - 4
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()