Skip to content

Commit

Permalink
Merge pull request #1716 from NitroCao/fix/pidfd
Browse files Browse the repository at this point in the history
fix: release process after os.FindProcess()
  • Loading branch information
shirou authored Dec 14, 2024
2 parents c95f835 + fcdd277 commit 2a70d27
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions process/process_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func PidExistsWithContext(ctx context.Context, pid int32) (bool, error) {
if err != nil {
return false, err
}
defer proc.Release()

if isMount(common.HostProcWithContext(ctx)) { // if /<HOST_PROC>/proc exists and is mounted, check if /<HOST_PROC>/proc/<PID> folder exists
_, err := os.Stat(common.HostProcWithContext(ctx, strconv.Itoa(int(pid))))
Expand Down Expand Up @@ -144,6 +145,7 @@ func (p *Process) SendSignalWithContext(ctx context.Context, sig syscall.Signal)
if err != nil {
return err
}
defer process.Release()

err = process.Signal(sig)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions process/process_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,7 @@ func (p *Process) KillWithContext(ctx context.Context) error {
if err != nil {
return err
}
defer process.Release()
return process.Kill()
}

Expand Down

0 comments on commit 2a70d27

Please sign in to comment.