Skip to content

fix: release native references and session descriptions in JNI glue - #511

Merged
devopvoid merged 2 commits into
mainfrom
fix/jni-local-ref
Nov 1, 2026
Merged

devopvoid merged 2 commits into
mainfrom
fix/jni-local-ref

Conversation

@devopvoid

@devopvoid devopvoid commented Nov 1, 2026 •

Copy link
Copy Markdown
Owner
  • JavaLocalRef clears its handle on delete, so assigning an empty reference no longer deletes the old one a second time in the destructor.
  • Copy assignment takes the new local reference before freeing the old one, which makes self-assignment safe.
  • The default constructor initializes env, and destroying an empty reference no longer attaches the thread.
  • JavaHashMap::put calls Map.put with CallObjectMethod, matching its signature, and frees the returned previous value.
  • CreateSessionDescriptionObserver::OnSuccess takes ownership of the session description WebRTC hands it, so every created offer and answer is freed after its copy to Java, also when the thread cannot attach.

Deleting a local reference now clears the handle, a copy assignment takes the new reference before it frees the old one, and the default constructor initializes env. JavaHashMap::put uses CallObjectMethod and frees the returned previous value.
…bserver

OnSuccess owns the description WebRTC passes in. It is now taken into a unique_ptr on entry, so it is freed after the copy to Java and on the early return when the thread cannot attach.
@devopvoid devopvoid changed the title fix: free JavaLocalRef handles once and call Map.put as an object method fix: release native references and session descriptions in JNI glue Nov 1, 2026
@devopvoid
devopvoid merged commit d9b6aac into main Nov 1, 2026
22 checks passed
@devopvoid
devopvoid deleted the fix/jni-local-ref branch November 1, 2026 14:36
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