Fix JNI reference leak in MediaCodecVideoDecoder
We currently leak one local reference to MediaCodecVideoDecoder in every call to MediaCodecVideoDecoderFactory::CreateVideoDecoder. After the decoder has been re-initialized 512 times, JNI will crash due to local reference table overflow (max=512). The actual leak is in the member initializer list of MediaCodecVideoDecoder. This CL fixes the leak by adding a ScopedLocalRefFrame outside of the ctor. All JNI code that originate from a C++ thread (i.e. the entry point is not a Java thread) must use a ScopedLocalRefFrame in order to avoid leaking local references. BUG=webrtc:6969,b/36713034 Review-Url: https://codereview.webrtc.org/2780273002 Cr-Commit-Position: refs/heads/master@{#17464}
This commit is contained in:
@ -199,7 +199,6 @@ MediaCodecVideoDecoder::MediaCodecVideoDecoder(
|
|||||||
*j_media_codec_video_decoder_class_,
|
*j_media_codec_video_decoder_class_,
|
||||||
"<init>",
|
"<init>",
|
||||||
"()V"))) {
|
"()V"))) {
|
||||||
ScopedLocalRefFrame local_ref_frame(jni);
|
|
||||||
codec_thread_->SetName("MediaCodecVideoDecoder", NULL);
|
codec_thread_->SetName("MediaCodecVideoDecoder", NULL);
|
||||||
RTC_CHECK(codec_thread_->Start()) << "Failed to start MediaCodecVideoDecoder";
|
RTC_CHECK(codec_thread_->Start()) << "Failed to start MediaCodecVideoDecoder";
|
||||||
|
|
||||||
@ -1014,8 +1013,9 @@ webrtc::VideoDecoder* MediaCodecVideoDecoderFactory::CreateVideoDecoder(
|
|||||||
for (VideoCodecType codec_type : supported_codec_types_) {
|
for (VideoCodecType codec_type : supported_codec_types_) {
|
||||||
if (codec_type == type) {
|
if (codec_type == type) {
|
||||||
ALOGD << "Create HW video decoder for type " << (int)type;
|
ALOGD << "Create HW video decoder for type " << (int)type;
|
||||||
return new MediaCodecVideoDecoder(AttachCurrentThreadIfNeeded(), type,
|
JNIEnv* jni = AttachCurrentThreadIfNeeded();
|
||||||
egl_context_);
|
ScopedLocalRefFrame local_ref_frame(jni);
|
||||||
|
return new MediaCodecVideoDecoder(jni, type, egl_context_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ALOGW << "Can not find HW video decoder for type " << (int)type;
|
ALOGW << "Can not find HW video decoder for type " << (int)type;
|
||||||
|
|||||||
Reference in New Issue
Block a user