From fcdd277935d0e33873265123b3bcd41d579045ba Mon Sep 17 00:00:00 2001 From: NitroCao Date: Fri, 27 Sep 2024 10:37:33 +0800 Subject: [PATCH] fix: release process after os.FindProcess() --- process/process_posix.go | 2 ++ process/process_windows.go | 1 + 2 files changed, 3 insertions(+) diff --git a/process/process_posix.go b/process/process_posix.go index caa9d3f7c..96c5e065c 100644 --- a/process/process_posix.go +++ b/process/process_posix.go @@ -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 //proc exists and is mounted, check if //proc/ folder exists _, 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 { return err } + defer process.Release() err = process.Signal(sig) if err != nil { diff --git a/process/process_windows.go b/process/process_windows.go index b00c671e9..012886d6c 100644 --- a/process/process_windows.go +++ b/process/process_windows.go @@ -817,6 +817,7 @@ func (p *Process) KillWithContext(ctx context.Context) error { if err != nil { return err } + defer process.Release() return process.Kill() }