Skip to content

Commit 8bcc237

Browse files
committed
Fix Windows port leak in quiesce_does_not_crash test
MHD_quiesce_daemon transfers the listen socket to the caller. On Windows, MHD sockets are Winsock SOCKETs and POSIX close() from <unistd.h> does not close them, so the prior version leaked the socket and left port 8080 bound. The next test in the same binary (external_event_loop) then failed MHD_start_daemon with "Unable to connect daemon to port: 8080". Use closesocket() on Windows and close() elsewhere.
1 parent a409ca2 commit 8bcc237

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

test/integ/daemon_info.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919
*/
2020

2121
#include <curl/curl.h>
22+
#ifdef _WIN32
23+
#include <winsock2.h>
24+
#else
2225
#include <unistd.h>
26+
#endif
2327
#include <cstring>
2428
#include <memory>
2529
#include <string>
@@ -126,9 +130,17 @@ LT_BEGIN_AUTO_TEST(daemon_info_suite, quiesce_does_not_crash)
126130
// Note: quiesce may return -1 if not supported with current daemon flags
127131
// (e.g., thread-per-connection mode). We just verify it doesn't crash.
128132
int listen_fd = ws.quiesce();
129-
// If quiesce succeeded, the FD should be positive
133+
// If quiesce succeeded, the listen socket ownership transfers to us;
134+
// close it so the port is freed for subsequent tests. On Windows, MHD
135+
// sockets are Winsock SOCKETs and must be closed via closesocket()
136+
// rather than POSIX close(), which would otherwise leak port 8080
137+
// and cause later tests to fail bind.
130138
if (listen_fd > 0) {
139+
#ifdef _WIN32
140+
closesocket(static_cast<SOCKET>(listen_fd));
141+
#else
131142
close(listen_fd);
143+
#endif
132144
}
133145

134146
curl_easy_cleanup(curl);

0 commit comments

Comments
 (0)