Skip to content

tool_doswin: fix to use curl socket functions#18633

Closed
vszakats wants to merge 8 commits intocurl:masterfrom
vszakats:w-closesocket
Closed

tool_doswin: fix to use curl socket functions#18633
vszakats wants to merge 8 commits intocurl:masterfrom
vszakats:w-closesocket

Conversation

@vszakats
Copy link
Member

@vszakats vszakats commented Sep 20, 2025

Replace WSASocketW() with CURL_SOCKET(). Also replace a call
to socketclose() with sclose(). According to a comment,
socketclose() was chosen to silence test 1498 (and 2300) reporting
MEMORY FAILURE. These reports were accurate, and were caused by
calling WSASocketW() instead of socket() (now CURL_SOCKET()).

This also fixes the curl sclose() call on an error branch, which is
now correctly paired with a curl socket open. The mismatched open/close
calls caused an issue in TrackMemory-enabled (aka CURLDEBUG) builds.

Docs confirm that socket() is defaulting to overlapped I/O, matching
the replaced WSASocketW() call:
https://learn.microsoft.com/windows/win32/api/winsock2/nf-winsock2-socket#remarks

Also:

  • checksrc: ban WSASocket*() functions.
  • report SOCKERRNO instead of GetLastError() for socket calls,
    to match the rest of the codebase.

Follow-up to 9a26633 #17572


The comment says that closesocket() is needed (insead of sclose() to avoid failing 1498.
However, in the cleanup section is calls sclose().

I found it interesting that the unpaired socket open/close call only tripped
test 1498 and 2300 in c-ares-enabled builds.

@vszakats vszakats marked this pull request as draft September 20, 2025 11:34
@github-actions github-actions bot added cmdline tool Windows Windows-specific labels Sep 20, 2025
@vszakats
Copy link
Member Author

vszakats commented Sep 20, 2025

[...]
test 1498...[HTTP PUT from stdin using period]

** MEMORY FAILURE
Close without open: FD ../../src/tool_doswin.c:776 sclose(368)
[...]
test 2300...[WebSockets upgrade only]

** MEMORY FAILURE
Close without open: FD ../../src/tool_doswin.c:776 sclose(364)

https://github.com/curl/curl/actions/runs/17879348006/job/50845021761?pr=18633 mingw, AM x86_64 c-ares U (debug-enabled)
https://github.com/curl/curl/actions/runs/17879348006/job/50845021755?pr=18633 mingw, CM x86_64 schannel c-ares U (debug-enabled)

and passes both in mingw, CM clang-x86_64 gnutls libssh (debug-enabled). I wonder why.

edit: → it appears that this error is specific to c-ares-enabled builds:
https://github.com/curl/curl/actions/runs/17880612285/job/50847777809?pr=18633 mingw, CM x86_64 schannel c-ares U (debug-enabled) job but with c-ares disabled.

@github-actions github-actions bot added the CI Continuous Integration label Sep 20, 2025
@vszakats vszakats changed the title tool_doswin: try sclose tool_doswin: fix to use curl socket functions Sep 20, 2025
@vszakats vszakats removed the CI Continuous Integration label Sep 20, 2025
@vszakats vszakats marked this pull request as ready for review September 20, 2025 15:23
@vszakats vszakats closed this in c9eff26 Sep 22, 2025
@vszakats vszakats deleted the w-closesocket branch September 22, 2025 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cmdline tool Windows Windows-specific

Development

Successfully merging this pull request may close these issues.

1 participant