Skip to content

CBL-8468 : Fix incoming BLE L2CAP socket double-free on connection teardown#499

Merged
pasin merged 1 commit into
release/4.1from
CBL-8468
Jun 16, 2026
Merged

CBL-8468 : Fix incoming BLE L2CAP socket double-free on connection teardown#499
pasin merged 1 commit into
release/4.1from
CBL-8468

Conversation

@pasin

@pasin pasin commented Jun 14, 2026

Copy link
Copy Markdown
Collaborator

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).

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).
@github-actions

github-actions Bot commented Jun 14, 2026

Copy link
Copy Markdown

This is a release branch and commits are restricted.

Please confirm this PR is one of the following:

  • A response to a customer ask
  • A change per our security policy
  • A non-functional change (i.e. changes needed for building an older version)
  • A change that has been granted an exception (please comment)

@pasin

pasin commented Jun 14, 2026

Copy link
Copy Markdown
Collaborator Author

Fix the issue while testing Bluetooth functionality for the release.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() in btOpen() to document the retain/release pairing.
  • Add c4socket_retain() in btAttached() (incoming socket path) so it’s balanced by the existing c4socket_release() in NativeC4Socket_closed.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@pasin pasin merged commit 6537871 into release/4.1 Jun 16, 2026
2 checks passed
@pasin pasin deleted the CBL-8468 branch June 16, 2026 04:32
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.

3 participants