diff --git a/src/syscall/exec_linux.go b/src/syscall/exec_linux.go index 0009080d681f93..43ed57157220a8 100644 --- a/src/syscall/exec_linux.go +++ b/src/syscall/exec_linux.go @@ -839,3 +839,11 @@ func doCheckClonePidfd(pidfd *int32) (pid uintptr, errno Errno) { RawSyscall(SYS_EXIT_GROUP, 0, 0, 0) } } + +// forkAndExecFailureCleanup cleans up after an exec failure. +func forkAndExecFailureCleanup(attr *ProcAttr, sys *SysProcAttr) { + if sys.PidFD != nil && *sys.PidFD != -1 { + Close(*sys.PidFD) + *sys.PidFD = -1 + } +}