From 03a825b338b43a019bf4fc9aab29f6d0c5be39d0 Mon Sep 17 00:00:00 2001 From: Yuanyuan Lei Date: Thu, 27 Jun 2024 10:00:23 -0700 Subject: [PATCH] Fix process handle leak when launching a job container (#2188) CreateProcess gives us back a handle to the newly created process. Previously, we ignored this handle, which meant it was leaking every time we created a new job container (or anything else that uses internal/exec in the future). Process handle leaks can be bad as an exited process is left as a "zombie" until all handles to it have closed, continuing to use memory. Fix this by closing the handle from CreateProcess. Signed-off-by: Kevin Parsons Co-authored-by: Kevin Parsons --- internal/exec/exec.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/exec/exec.go b/internal/exec/exec.go index 79463b3fb2..b40ea69467 100644 --- a/internal/exec/exec.go +++ b/internal/exec/exec.go @@ -209,8 +209,8 @@ func (e *Exec) Start() error { if err != nil { return fmt.Errorf("failed to create process: %w", err) } - // Don't need the thread handle for anything. defer func() { + _ = windows.CloseHandle(windows.Handle(pi.Process)) _ = windows.CloseHandle(windows.Handle(pi.Thread)) }()