Skip to content

Fix Java Action.destroy native handle lifetime - #43

Draft
bepcyc wants to merge 1 commit into
openhome:masterfrom
bepcyc:fix/java-action-destroy-handle
Draft

bepcyc wants to merge 1 commit into
openhome:masterfrom
bepcyc:fix/java-action-destroy-handle

Conversation

@bepcyc

@bepcyc bepcyc commented Oct 26, 2026 •

Copy link
Copy Markdown

Change

Action.destroy() currently sets iHandle to zero before passing it to ServiceActionDestroy. The JNI bridge forwards that zero, so the allocated native action and its parameters are not released. Preserve the original handle under the existing lock and pass it to native destruction after making destroy() idempotent.

Reproduction and validation

  • Pinned upstream base: b86dab7ff82cd972ef83cf27aab667e821242440.
  • Built the Java Android binding with JDK 17 (javac --release 8) and Android NDK 30.0.16248370.
  • In an Android arm64 debug probe, 10,000 Action create/destroy cycles with one input and one output parameter increased Debug.getNativeHeapAllocatedSize() by 4,320,336 bytes before library shutdown (78 ms).
  • With this patch and the same probe, 10,000 cycles changed allocated native heap by −9,408 bytes (61 ms). A further 20,000 cycles changed it by −74,144 bytes (127 ms). Negative readings reflect allocator/runtime variation; the repeated linear increase disappeared.
  • Calling destroy() twice on each of 10,000 patched actions completed without a crash or accumulating native heap.
  • A separate read-only UPnP ConnectionManager check created/disposed 1,000 generated proxies. Native heap changed by +400 bytes across those cycles; one SOAP GetProtocolInfo and its initial GENA sink event matched. No playback or volume action was sent.
  • Android debug and release/R8 APK builds succeeded with the patched jar; a debug-only probe was verified absent from the merged release manifest.
  • Source diff is limited to OpenHome/Net/Bindings/Java/org/openhome/net/core/Action.java.

This PR is a draft while broader proxy lifecycle and release checks continue.

Preserve the handle before zeroing the Java field so ServiceActionDestroy receives the allocated native Action. This retains idempotent destroy while preventing a per-action native leak.
@DoomHammer

Copy link
Copy Markdown

The maintainers of this repo haven't accepted a patch in over a decade. I doubt this situation will change, unfortunately.

@bepcyc

bepcyc commented Oct 26, 2026

Copy link
Copy Markdown
Author

The maintainers of this repo haven't accepted a patch in over a decade. I doubt this situation will change, unfortunately.

That's a bummer. Any idea why is that?

@DoomHammer

Copy link
Copy Markdown

I suppose this a classical source-drop development model. The software if developed in a closed fashion and every now and then we get a current source drop. Kinda like Android.

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.

2 participants