CBL-8468 : Fix incoming BLE L2CAP socket double-free on connection teardown#499
Merged
Conversation
btAttached() (incoming) now calls c4socket_retain, matching btOpen(), to balance the c4socket_release in NativeC4Socket_closed. Without it the incoming socket was double-freed on teardown (SIGABRT, invalid refCount -6666666).
|
This is a release branch and commits are restricted. Please confirm this PR is one of the following:
|
Collaborator
Author
|
Fix the issue while testing Bluetooth functionality for the release. |
There was a problem hiding this comment.
Pull request overview
Fixes a lifecycle mismatch for incoming BLE L2CAP sockets by retaining the C4Socket in btAttached() to match the existing outgoing path in btOpen(), preventing a double-free during teardown when Java later calls NativeC4Socket_closed (which releases the socket).
Changes:
- Add an explanatory comment and keep the existing
c4socket_retain()inbtOpen()to document the retain/release pairing. - Add
c4socket_retain()inbtAttached()(incoming socket path) so it’s balanced by the existingc4socket_release()inNativeC4Socket_closed.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
borrrden
approved these changes
Jun 15, 2026
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.
The btAttached() (incoming) now calls c4socket_retain, matching btOpen(), to balance the c4socket_release in NativeC4Socket_closed. Without it the incoming socket was double-freed on teardown (SIGABRT, invalid refCount -6666666).