bug: file descriptor leak on z/OS s390x when FcntlInt fails (#2255) (#2285)

This commit is contained in:
Erik Dubbelboer
2026-06-06 17:30:35 +08:00
committed by GitHub
parent f3f769f74c
commit 44115f3838
+13 -5
View File
@@ -10,10 +10,18 @@ import (
func newSocketCloexec(domain, typ, proto int) (int, error) { func newSocketCloexec(domain, typ, proto int) (int, error) {
fd, err := unix.Socket(domain, typ, proto) fd, err := unix.Socket(domain, typ, proto)
_, err = unix.FcntlInt(uintptr(fd), unix.F_SETFD, unix.FD_CLOEXEC) if err != nil {
_, err = unix.FcntlInt(uintptr(fd), unix.F_SETFL, unix.O_NONBLOCK) return -1, fmt.Errorf("cannot create listening socket: %w", err)
if err == nil {
return fd, nil
} }
return -1, fmt.Errorf("cannot create listening unblocked socket: %s", err) _, err = unix.FcntlInt(uintptr(fd), unix.F_SETFD, unix.FD_CLOEXEC)
if err != nil {
unix.Close(fd) //nolint:errcheck
return -1, fmt.Errorf("cannot mark listening socket close-on-exec: %w", err)
}
_, err = unix.FcntlInt(uintptr(fd), unix.F_SETFL, unix.O_NONBLOCK)
if err != nil {
unix.Close(fd) //nolint:errcheck
return -1, fmt.Errorf("cannot mark listening socket nonblocking: %w", err)
}
return fd, nil
} }