Fix socket handle leak: always call closesocket/close after shutdown in disconnect#561
Open
dcristoloveanu wants to merge 1 commit intomasterfrom
Open
Fix socket handle leak: always call closesocket/close after shutdown in disconnect#561dcristoloveanu wants to merge 1 commit intomasterfrom
dcristoloveanu wants to merge 1 commit intomasterfrom
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Testing
Fixes AB#37142411