Skip to content

Fix socket handle leak: always call closesocket/close after shutdown in disconnect#561

Open
dcristoloveanu wants to merge 1 commit intomasterfrom
users/copilot/fix-socket-transport-leak-37142411
Open

Fix socket handle leak: always call closesocket/close after shutdown in disconnect#561
dcristoloveanu wants to merge 1 commit intomasterfrom
users/copilot/fix-socket-transport-leak-37142411

Conversation

@dcristoloveanu
Copy link
Copy Markdown
Member

Summary

Fixes socket handle leaks in \socket_transport_disconnect()\ detected by VLD in integration tests.

Root cause: When \shutdown()\ failed on non-binding sockets, \closesocket()/\close()\ was skipped due to an \if/else\ structure, leaking the socket handle and associated Winsock internal allocations (\WahInsertHandleContext, 256 bytes each).

Fix: Ensure \closesocket()/\close()\ is always called regardless of \shutdown()\ result. Per Windows/POSIX docs, \shutdown()\ is for graceful connection termination while \closesocket()/\close()\ releases the socket descriptor and must always be called.

Changes

  • win32/src/socket_transport_win32.c: Restructured disconnect to always call \closesocket()\
  • linux/src/socket_transport_linux.c: Restructured disconnect to always call \close()\
  • win32/devdoc/socket_transport_win32_requirements.md: Updated SRS_SOCKET_TRANSPORT_WIN32_09_083
  • linux/devdoc/socket_transport_linux_requirements.md: Updated SRS_SOCKET_TRANSPORT_LINUX_11_026
  • win32/tests/socket_transport_win32_ut: Updated unit test expectations
  • linux/tests/socket_transport_linux_ut: Updated unit test expectations

Testing

  • ✅ Unit tests pass (socket_transport_win32_ut, socket_transport_linux_ut)
  • ✅ Integration tests pass (socket_transport_int)

Fixes AB#37142411

…connect

When socket_transport_disconnect was called on a non-binding socket and
shutdown() failed, closesocket() was not called, leaking the socket
handle and associated Winsock internal allocations (WahInsertHandleContext).

Per Windows/POSIX documentation, closesocket()/close() must always be
called to release socket resources, regardless of whether shutdown()
succeeds or fails. shutdown() is for graceful connection termination
while closesocket()/close() is for releasing the socket descriptor.

This fix ensures closesocket()/close() is always called after shutdown()
is attempted, fixing the memory leaks detected by VLD in the
socket_transport_int integration tests.

Changes:
- win32/src/socket_transport_win32.c: Always call closesocket()
- linux/src/socket_transport_linux.c: Always call close()
- Updated SRS requirements and unit tests for both platforms

Fixes AB#37142411

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant