Skip to content

Commit 6749c2f

Browse files
yyatmsftkevpar
andauthored
Fix process handle leak when launching a job container (#2187)
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 <[email protected]> Co-authored-by: Kevin Parsons <[email protected]>
1 parent e59d3d2 commit 6749c2f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

internal/exec/exec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ func (e *Exec) Start() error {
209209
if err != nil {
210210
return fmt.Errorf("failed to create process: %w", err)
211211
}
212-
// Don't need the thread handle for anything.
213212
defer func() {
213+
_ = windows.CloseHandle(windows.Handle(pi.Process))
214214
_ = windows.CloseHandle(windows.Handle(pi.Thread))
215215
}()
216216

0 commit comments

Comments
 (0)