diff options
author | Matthieu Bouron <matthieu.bouron@gmail.com> | 2017-05-21 16:48:30 +0200 |
---|---|---|
committer | Matthieu Bouron <matthieu.bouron@gmail.com> | 2017-05-23 15:25:03 +0200 |
commit | 224bb46fb857dab589597bdab302ba8ba012008c (patch) | |
tree | 2c70da38e7193ac936e8fb43eaee3c9f921b12be | |
parent | 3766aa7343c43521c8ad67aaec26e3c91f6d91c7 (diff) | |
download | ffmpeg-224bb46fb857dab589597bdab302ba8ba012008c.tar.gz |
lavc/mediacodec_wrapper: fix local reference leaks
-rw-r--r-- | libavcodec/mediacodec_wrapper.c | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/libavcodec/mediacodec_wrapper.c b/libavcodec/mediacodec_wrapper.c index 43fbb511fd..5e1beed43a 100644 --- a/libavcodec/mediacodec_wrapper.c +++ b/libavcodec/mediacodec_wrapper.c @@ -608,6 +608,7 @@ FFAMediaFormat *ff_AMediaFormat_new(void) { JNIEnv *env = NULL; FFAMediaFormat *format = NULL; + jobject object = NULL; format = av_mallocz(sizeof(FFAMediaFormat)); if (!format) { @@ -625,23 +626,27 @@ FFAMediaFormat *ff_AMediaFormat_new(void) goto fail; } - format->object = (*env)->NewObject(env, format->jfields.mediaformat_class, format->jfields.init_id); - if (!format->object) { + object = (*env)->NewObject(env, format->jfields.mediaformat_class, format->jfields.init_id); + if (!object) { goto fail; } - format->object = (*env)->NewGlobalRef(env, format->object); + format->object = (*env)->NewGlobalRef(env, object); if (!format->object) { goto fail; } - return format; fail: - ff_jni_reset_jfields(env, &format->jfields, jni_amediaformat_mapping, 1, format); + if (object) { + (*env)->DeleteLocalRef(env, object); + } - av_freep(&format); + if (!format->object) { + ff_jni_reset_jfields(env, &format->jfields, jni_amediaformat_mapping, 1, format); + av_freep(&format); + } - return NULL; + return format; } static FFAMediaFormat *ff_AMediaFormat_newFromObject(void *object) @@ -1562,6 +1567,7 @@ uint8_t* ff_AMediaCodec_getInputBuffer(FFAMediaCodec* codec, size_t idx, size_t JNIEnv *env = NULL; jobject buffer = NULL; + jobject input_buffers = NULL; JNI_GET_ENV_OR_RETURN(env, codec, NULL); @@ -1572,12 +1578,12 @@ uint8_t* ff_AMediaCodec_getInputBuffer(FFAMediaCodec* codec, size_t idx, size_t } } else { if (!codec->input_buffers) { - codec->input_buffers = (*env)->CallObjectMethod(env, codec->object, codec->jfields.get_input_buffers_id); + input_buffers = (*env)->CallObjectMethod(env, codec->object, codec->jfields.get_input_buffers_id); if (ff_jni_exception_check(env, 1, codec) < 0) { goto fail; } - codec->input_buffers = (*env)->NewGlobalRef(env, codec->input_buffers); + codec->input_buffers = (*env)->NewGlobalRef(env, input_buffers); if (ff_jni_exception_check(env, 1, codec) < 0) { goto fail; } @@ -1596,6 +1602,10 @@ fail: (*env)->DeleteLocalRef(env, buffer); } + if (input_buffers) { + (*env)->DeleteLocalRef(env, input_buffers); + } + return ret; } @@ -1605,6 +1615,7 @@ uint8_t* ff_AMediaCodec_getOutputBuffer(FFAMediaCodec* codec, size_t idx, size_t JNIEnv *env = NULL; jobject buffer = NULL; + jobject output_buffers = NULL; JNI_GET_ENV_OR_RETURN(env, codec, NULL); @@ -1615,12 +1626,12 @@ uint8_t* ff_AMediaCodec_getOutputBuffer(FFAMediaCodec* codec, size_t idx, size_t } } else { if (!codec->output_buffers) { - codec->output_buffers = (*env)->CallObjectMethod(env, codec->object, codec->jfields.get_output_buffers_id); + output_buffers = (*env)->CallObjectMethod(env, codec->object, codec->jfields.get_output_buffers_id); if (ff_jni_exception_check(env, 1, codec) < 0) { goto fail; } - codec->output_buffers = (*env)->NewGlobalRef(env, codec->output_buffers); + codec->output_buffers = (*env)->NewGlobalRef(env, output_buffers); if (ff_jni_exception_check(env, 1, codec) < 0) { goto fail; } @@ -1639,6 +1650,10 @@ fail: (*env)->DeleteLocalRef(env, buffer); } + if (output_buffers) { + (*env)->DeleteLocalRef(env, output_buffers); + } + return ret; } |