From ebdedf67ea07b3e4193d446179970b74764eab0b Mon Sep 17 00:00:00 2001 From: Kartik Naik Date: Tue, 11 Aug 2026 23:13:36 +0530 Subject: set cloexec on the socket handle in win32 socketpair setfd --- tests/compat/pipe2.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/compat/pipe2.c b/tests/compat/pipe2.c index c0189db..3e79575 100644 --- a/tests/compat/pipe2.c +++ b/tests/compat/pipe2.c @@ -18,9 +18,10 @@ static int setfd(int fd, int flag) { int rc = -1; if (flag & FD_CLOEXEC) { - HANDLE h = (HANDLE)_get_osfhandle(fd); - if (h != NULL) - rc = SetHandleInformation(h, HANDLE_FLAG_INHERIT, 0) == 0 ? -1 : 0; + /* fd is a Winsock SOCKET, not a CRT descriptor: use it as a + * handle directly rather than translating with _get_osfhandle. */ + HANDLE h = (HANDLE)(LONG_PTR)fd; + rc = SetHandleInformation(h, HANDLE_FLAG_INHERIT, 0) == 0 ? -1 : 0; } return rc; } -- cgit v1.2.3-55-g6feb