Skip to content

fix: keep native references until their Java wrapper is created - #516

Merged
devopvoid merged 1 commit into
mainfrom
fix/owning-java-factory
Nov 1, 2026
Merged

devopvoid merged 1 commit into
mainfrom
fix/owning-java-factory

Conversation

@devopvoid

Copy link
Copy Markdown
Owner

Several JNI call sites released the native reference before the Java wrapper existed (JavaFactories::create(env, x.release())), so a failed wrapper allocation leaked the native object.

  • Add JavaFactories::createOwning(env, std::move(ptr)), which releases the reference only once the wrapper exists and holds its handle; an overload with a bind step sets further handles (e.g. observers) before the transfer.
  • Use it at all call sites: tracks, sources, senders, receivers, transceivers, data channels, DTLS transports and the peer connection observer callbacks.
  • createPeerConnection no longer lets a C++ exception escape the JNI function, and frees connection and observer on failure; the frame injectors no longer leak their observer.
  • createOwningObjectArray hands over the references only after the whole array is filled.

JavaFactories::createOwning builds the wrapper from the smart pointer's
get() and releases the reference only once the wrapper exists and holds
its handles, so a failed allocation no longer leaks the native object.
All call sites that handed over released pointers use it now, including
the peer connection and the frame injectors, which bind their observer
before the transfer, and createOwningObjectArray.
@devopvoid
devopvoid merged commit 41cd3ea into main Nov 1, 2026
21 of 22 checks passed
@devopvoid
devopvoid deleted the fix/owning-java-factory branch November 1, 2026 22:04
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