Merge pull request #1716 from NitroCao/fix/pidfd

fix: release process after os.FindProcess()
pull/1760/head
shirou 3 months ago committed by GitHub
commit 2a70d27e74
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -108,6 +108,7 @@ func PidExistsWithContext(ctx context.Context, pid int32) (bool, error) {
if err != nil { if err != nil {
return false, err 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 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)))) _, err := os.Stat(common.HostProcWithContext(ctx, strconv.Itoa(int(pid))))
@ -144,6 +145,7 @@ func (p *Process) SendSignalWithContext(ctx context.Context, sig syscall.Signal)
if err != nil { if err != nil {
return err return err
} }
defer process.Release()
err = process.Signal(sig) err = process.Signal(sig)
if err != nil { if err != nil {

@ -817,6 +817,7 @@ func (p *Process) KillWithContext(ctx context.Context) error {
if err != nil { if err != nil {
return err return err
} }
defer process.Release()
return process.Kill() return process.Kill()
} }

Loading…
Cancel
Save