Protect PeerConnection lifecycle and JNI invocations with ReadWriteLock.
Add a ReentrantReadWriteLock in PeerConnection to prevent use-after-free
race conditions between JNI method invocations and dispose().
Concurrent calls to JNI methods while dispose() is executing could lead
to native memory corruption when freeOwnedPeerConnection is executed
while another thread is accessing the C++ PeerConnection instance.
Changes:
* Introduce lifecycleLock (ReentrantReadWriteLock) and wrap JNI-calling
methods with callWithNative/runWithNative under readLock.
* Throw IllegalStateException("PeerConnection has been disposed.") when
invoking methods on a disposed instance.
* In dispose(), execute close() and child disposals prior to acquiring
writeLock to avoid deadlocks with signaling thread observer callbacks.
* Guard freeOwnedPeerConnection and zeroing nativePeerConnection under
writeLock.
* Make dispose() idempotent so duplicate or concurrent calls complete
safely.
Bug: b/533453798
Change-Id: If848b8dd7652c9810256414db890ec206cb8c996
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/500801
Commit-Queue: Linus Nilsson <lnilsson@webrtc.org>
Reviewed-by: ZoƩ Lepaul <zlep@webrtc.org>
Reviewed-by: Sergey Silkin <ssilkin@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#48530}
WebRTC is a free, open software project that provides browsers and mobile applications with Real-Time Communications (RTC) capabilities via simple APIs. The WebRTC components have been optimized to best serve this purpose.
Our mission: To enable rich, high-quality RTC applications to be developed for the browser, mobile platforms, and IoT devices, and allow them all to communicate via a common set of protocols.
The WebRTC initiative is a project supported by Google, Mozilla and Opera, amongst others.
See here for instructions on how to get started developing with the native code.
Authoritative list of directories that contain the native API header files.