Skip to content

fix: hand native references to Java wrappers only after they are created - #518

Closed
devopvoid wants to merge 1 commit into
mainfrom
fix/factory-ownership-transfer
Closed

devopvoid wants to merge 1 commit into
mainfrom
fix/factory-ownership-transfer

Conversation

@devopvoid

Copy link
Copy Markdown
Owner

Call sites gave up their native reference (JavaFactories::create(env, x.release())) before the Java wrapper existed, so a failed wrapper creation leaked the native object.

  • Add JavaFactories::createOwning(), which keeps the reference in its smart pointer until the wrapper is created and its handle bound, and use it at all such call sites.
  • Frame injectors and peer connections bind their observer handle before either reference is handed over; createPeerConnectionInternal now owns its observer in a unique_ptr and catches C++ exceptions.
  • createOwningObjectArray hands over references only once every element exists.
  • JavaFactory::create() owns the new local reference right away.

JavaFactories::createOwning() keeps the reference in its smart pointer until
the wrapper exists and its handle is bound, so a failed creation no longer
leaks the native object.
@devopvoid

Copy link
Copy Markdown
Owner Author

Superseded by #516, which landed the same fix on main.

@devopvoid devopvoid closed this Nov 1, 2026
@devopvoid
devopvoid deleted the fix/factory-ownership-transfer branch November 1, 2026 22:59
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