fix: give AudioTrackSource a dispose() to release its native reference - #287
Merged
Merged
Conversation
PeerConnectionFactory.createAudioSource() returns a Java object wrapping a ref-counted native AudioSourceInterface, but AudioTrackSource (unlike every other ref-counted wrapper in the API) exposed no dispose()/release(), so the one reference handed to Java could never be dropped. Every call to createAudioSource() leaked the native audio source for the life of the process, regardless of how the resulting track and peer connection were torn down.
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PeerConnectionFactory.createAudioSource()wraps a ref-counted nativeAudioSourceInterfacein a JavaAudioTrackSource, following the sameJavaFactories::create(env, ptr.release())pattern used forAudioTrack/VideoTrack/MediaStream/etc. — but unlike those,AudioTrackSourcehad nodispose()/release()at all, so the one native reference handed to Java could never be released from the Java side.createAudioSource()leaked one native audio source reference for the life of the process, independent of whether the resulting track, peer connection, or factory were disposed.dispose()native method toAudioTrackSource(mirroringJNI_MediaStreamTrack.cpp's pattern:Release()the underlyingAudioSourceInterface, log a warning if it wasn't the last ref, and null out the handle), with a matchingJNI_AudioTrackSource.h/.cpppair.webrtc-examples(PeerConnectionExample,PeerConnectionManager) and theget-started.mdguide's cleanup snippet to dispose the audio source, since they now demonstrate a real API requirement.Fixes #239 (confirms the leak GPT flagged in the issue's discussion).
Test plan
mvn -pl webrtc test— 150/150 pass, no regressionsMediaSourceTestscoveringdispose()both standalone and after the owning track is disposedmvn -pl webrtc test -Pjni-checkon the affected test classes — noFATAL ERROR in native method, only the pre-existing harmless exception-check warnings