From c8c6f9abfbbd2f949285a527036a3d0dbd991e74 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 6 Sep 2024 12:19:01 -0700 Subject: [release-branch.go1.23] syscall: on exec failure, close pidfd For #69284 Fixes #69402 Change-Id: I6350209302778ba5e44fa03d0b9e680d2b4ec192 Reviewed-on: https://go-review.googlesource.com/c/go/+/611495 LUCI-TryBot-Result: Go LUCI Reviewed-by: roger peppe Reviewed-by: Tim King Auto-Submit: Ian Lance Taylor Reviewed-by: Dmitri Shuralyov (cherry picked from commit 8926ca9c5ec3ea0b51e413e87f737aeb1422ea48) Reviewed-on: https://go-review.googlesource.com/c/go/+/613616 Reviewed-by: Ian Lance Taylor Auto-Submit: Ian Lance Taylor Reviewed-by: Tobias Klauser --- src/syscall/exec_linux.go | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/syscall/exec_linux.go') diff --git a/src/syscall/exec_linux.go b/src/syscall/exec_linux.go index e4b9ce1bf4..2684412191 100644 --- a/src/syscall/exec_linux.go +++ b/src/syscall/exec_linux.go @@ -735,3 +735,11 @@ func writeUidGidMappings(pid int, sys *SysProcAttr) error { return nil } + +// 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 + } +} -- cgit v1.3