1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-28 20:53:54 +02:00

lavc/mediacodec_wrapper: fix local reference leaks

This commit is contained in:
Matthieu Bouron 2017-05-21 16:48:30 +02:00
parent 3766aa7343
commit 224bb46fb8

View File

@ -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);
object = (*env)->NewObject(env, format->jfields.mediaformat_class, format->jfields.init_id);
if (!object) {
goto fail;
}
format->object = (*env)->NewGlobalRef(env, object);
if (!format->object) {
goto fail;
}
format->object = (*env)->NewGlobalRef(env, format->object);
fail:
if (object) {
(*env)->DeleteLocalRef(env, object);
}
if (!format->object) {
goto fail;
ff_jni_reset_jfields(env, &format->jfields, jni_amediaformat_mapping, 1, format);
av_freep(&format);
}
return format;
fail:
ff_jni_reset_jfields(env, &format->jfields, jni_amediaformat_mapping, 1, format);
av_freep(&format);
return NULL;
}
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;
}