Skip to content

fix: keep C++ exceptions and string pins inside the media JNI layer - #439

Merged
devopvoid merged 1 commit into
mainfrom
fix/media-jni-exceptions
Oct 24, 2026
Merged

devopvoid merged 1 commit into
mainfrom
fix/media-jni-exceptions

Conversation

@devopvoid

Copy link
Copy Markdown
Owner

The media module's JNI entry points had no C++ exception boundary, so a failed allocation (e.g. copying the source string in MediaReader.open) would end the process, and the Java string's characters stayed pinned.

  • media/JniBoundary.h: CallFromJava turns C++ exceptions into Java ones (bad_alloc → OutOfMemoryError), plus RAII JavaStringChars and LocalRef, and one allocation-free ThrowJavaException. No dependency on the WebRTC library.
  • All reader, player and recorder entry points run behind it; MediaReader.info() makes no JNI call after a failed NewStringUTF.
  • MediaRecorder::AddTrack releases the handed-over frames when it fails, and Start stays stoppable when its thread cannot be created.
  • A test-only AllocationFault hook fails the next string copy on demand.

Every media entry point now runs behind a boundary that turns C++ exceptions into Java ones, Java strings are held by an RAII wrapper, and a recorder track that fails to be added releases its frames.
@devopvoid
devopvoid merged commit 8b5dc4a into main Oct 24, 2026
22 checks passed
@devopvoid
devopvoid deleted the fix/media-jni-exceptions branch October 24, 2026 19:03
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