Commit 224bb46f authored by Matthieu Bouron's avatar Matthieu Bouron

lavc/mediacodec_wrapper: fix local reference leaks

parent 3766aa73
...@@ -608,6 +608,7 @@ FFAMediaFormat *ff_AMediaFormat_new(void) ...@@ -608,6 +608,7 @@ FFAMediaFormat *ff_AMediaFormat_new(void)
{ {
JNIEnv *env = NULL; JNIEnv *env = NULL;
FFAMediaFormat *format = NULL; FFAMediaFormat *format = NULL;
jobject object = NULL;
format = av_mallocz(sizeof(FFAMediaFormat)); format = av_mallocz(sizeof(FFAMediaFormat));
if (!format) { if (!format) {
...@@ -625,23 +626,27 @@ FFAMediaFormat *ff_AMediaFormat_new(void) ...@@ -625,23 +626,27 @@ FFAMediaFormat *ff_AMediaFormat_new(void)
goto fail; 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 (!format->object) { if (!object) {
goto fail; goto fail;
} }
format->object = (*env)->NewGlobalRef(env, format->object); format->object = (*env)->NewGlobalRef(env, object);
if (!format->object) { if (!format->object) {
goto fail; goto fail;
} }
return format;
fail: 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) static FFAMediaFormat *ff_AMediaFormat_newFromObject(void *object)
...@@ -1562,6 +1567,7 @@ uint8_t* ff_AMediaCodec_getInputBuffer(FFAMediaCodec* codec, size_t idx, size_t ...@@ -1562,6 +1567,7 @@ uint8_t* ff_AMediaCodec_getInputBuffer(FFAMediaCodec* codec, size_t idx, size_t
JNIEnv *env = NULL; JNIEnv *env = NULL;
jobject buffer = NULL; jobject buffer = NULL;
jobject input_buffers = NULL;
JNI_GET_ENV_OR_RETURN(env, codec, 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 ...@@ -1572,12 +1578,12 @@ uint8_t* ff_AMediaCodec_getInputBuffer(FFAMediaCodec* codec, size_t idx, size_t
} }
} else { } else {
if (!codec->input_buffers) { 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) { if (ff_jni_exception_check(env, 1, codec) < 0) {
goto fail; 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) { if (ff_jni_exception_check(env, 1, codec) < 0) {
goto fail; goto fail;
} }
...@@ -1596,6 +1602,10 @@ fail: ...@@ -1596,6 +1602,10 @@ fail:
(*env)->DeleteLocalRef(env, buffer); (*env)->DeleteLocalRef(env, buffer);
} }
if (input_buffers) {
(*env)->DeleteLocalRef(env, input_buffers);
}
return ret; return ret;
} }
...@@ -1605,6 +1615,7 @@ uint8_t* ff_AMediaCodec_getOutputBuffer(FFAMediaCodec* codec, size_t idx, size_t ...@@ -1605,6 +1615,7 @@ uint8_t* ff_AMediaCodec_getOutputBuffer(FFAMediaCodec* codec, size_t idx, size_t
JNIEnv *env = NULL; JNIEnv *env = NULL;
jobject buffer = NULL; jobject buffer = NULL;
jobject output_buffers = NULL;
JNI_GET_ENV_OR_RETURN(env, codec, 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 ...@@ -1615,12 +1626,12 @@ uint8_t* ff_AMediaCodec_getOutputBuffer(FFAMediaCodec* codec, size_t idx, size_t
} }
} else { } else {
if (!codec->output_buffers) { 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) { if (ff_jni_exception_check(env, 1, codec) < 0) {
goto fail; 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) { if (ff_jni_exception_check(env, 1, codec) < 0) {
goto fail; goto fail;
} }
...@@ -1639,6 +1650,10 @@ fail: ...@@ -1639,6 +1650,10 @@ fail:
(*env)->DeleteLocalRef(env, buffer); (*env)->DeleteLocalRef(env, buffer);
} }
if (output_buffers) {
(*env)->DeleteLocalRef(env, output_buffers);
}
return ret; return ret;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment