[vlc-devel] [PATCH] mediacodec: fix LocalRef leaks

Zhao Zhili quinkblack at foxmail.com
Fri Jan 5 09:56:59 CET 2018


---
 modules/codec/omxil/mediacodec_jni.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/modules/codec/omxil/mediacodec_jni.c b/modules/codec/omxil/mediacodec_jni.c
index 9752193..e6e4ca2 100644
--- a/modules/codec/omxil/mediacodec_jni.c
+++ b/modules/codec/omxil/mediacodec_jni.c
@@ -237,13 +237,18 @@ InitJNIFields (vlc_object_t *p_obj, JNIEnv *env)
         }
         *(jclass*)((uint8_t*)&jfields + classes[i].offset) =
             (jclass) (*env)->NewGlobalRef(env, clazz);
+        (*env)->DeleteLocalRef(env, clazz);
     }
 
-    jclass last_class;
+    jclass last_class = NULL;
     for (int i = 0; members[i].name; i++)
     {
         if (i == 0 || strcmp(members[i].class, members[i - 1].class))
+        {
+            if (last_class != NULL)
+                (*env)->DeleteLocalRef(env, last_class);
             last_class = (*env)->FindClass(env, members[i].class);
+        }
 
         if (CHECK_EXCEPTION())
         {
-- 
2.7.4





More information about the vlc-devel mailing list