[PATCH v3 0/1] MR10051: ws2_32: Allow using duplicated socket handles in closesocket().
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=56927 This is similar to a08d6d8b, but just for `closesocket()`. [Testbot run with this patch](https://testbot.winehq.org/JobDetails.pl?Key=161786) -- v3: ws2_32: Allow using duplicated socket handles in closesocket(). https://gitlab.winehq.org/wine/wine/-/merge_requests/10051
From: Bernhard Übelacker <bernhardu@mailbox.org> Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=56927 --- dlls/ws2_32/socket.c | 2 +- dlls/ws2_32/tests/sock.c | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c index 95cb3059022..f5580cab4e3 100644 --- a/dlls/ws2_32/socket.c +++ b/dlls/ws2_32/socket.c @@ -1353,7 +1353,7 @@ int WINAPI closesocket( SOCKET s ) return -1; } - if (!socket_list_remove( s )) + if (!socket_list_remove( s ) && !is_valid_socket( s )) { SetLastError( WSAENOTSOCK ); return -1; diff --git a/dlls/ws2_32/tests/sock.c b/dlls/ws2_32/tests/sock.c index 8d589c63ea3..d861f303367 100644 --- a/dlls/ws2_32/tests/sock.c +++ b/dlls/ws2_32/tests/sock.c @@ -14595,10 +14595,16 @@ static void test_valid_handle(void) ok(ret == -1, "got %d\n", ret); ok(WSAGetLastError() == WSAENOTSOCK, "got error %u\n", WSAGetLastError()); - CloseHandle(invalid); - CloseHandle(duplicated); - closesocket(client); - closesocket(server); + ret = closesocket((SOCKET)invalid); + ok(ret == SOCKET_ERROR, "got %d, expected SOCKET_ERROR.\n", ret); + ret = CloseHandle(invalid); + ok(ret, "CloseHandle failed unexpectedly: %d\n", ret); + ret = closesocket((SOCKET)duplicated); + ok(!ret, "closesocket failed unexpectedly: %d\n", ret); + ret = closesocket(client); + ok(!ret, "closesocket failed unexpectedly: %d\n", ret); + ret = closesocket(server); + ok(!ret, "closesocket failed unexpectedly: %d\n", ret); } static void test_afunix_path( const char *path ) -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10051
v2: - Include checks for closing the invalid handle. v3: - Fixed ok message. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10051#note_129289
On Mon Feb 9 22:57:20 2026 +0000, Elizabeth Figura wrote:
It's probably worth also testing that closesocket() fails on a non-socket (and that a subsequent CloseHandle succeeds.) Thanks, I modified the patch that way in v2/v3.
-- https://gitlab.winehq.org/wine/wine/-/merge_requests/10051#note_129290
This merge request was approved by Elizabeth Figura. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10051
participants (3)
-
Bernhard Übelacker -
Bernhard Übelacker (@bernhardu) -
Elizabeth Figura (@zfigura)