Skip to content

Commit

Permalink
Fix process handle leak when launching a job container (#2188)
Browse files Browse the repository at this point in the history
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 <kevpar@microsoft.com>
Co-authored-by: Kevin Parsons <kevpar@microsoft.com>
  • Loading branch information
yyatmsft and kevpar authored Jun 27, 2024
1 parent 3ce43fe commit 03a825b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion internal/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}()

Expand Down

0 comments on commit 03a825b

Please sign in to comment.