[vlc-commits] mediacodec: fix LocalRef leaks

Zhao Zhili git at videolan.org
Fri Jan 5 14:33:21 CET 2018


vlc/vlc-3.0 | branch: master | Zhao Zhili <quinkblack at foxmail.com> | Fri Jan  5 16:56:59 2018 +0800| [8af36b302d1f965848117c21fc944cccaa64e6fd] | committer: Thomas Guillem

mediacodec: fix LocalRef leaks

Signed-off-by: Thomas Guillem <thomas at gllm.fr>
(cherry picked from commit 6ef171c102bd61f62aa0593a39873d3aa6975fa3)
Signed-off-by: Thomas Guillem <thomas at gllm.fr>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=8af36b302d1f965848117c21fc944cccaa64e6fd
---

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

diff --git a/modules/codec/omxil/mediacodec_jni.c b/modules/codec/omxil/mediacodec_jni.c
index 9752193dcd..ddf4f785ca 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())
         {
@@ -273,6 +278,8 @@ InitJNIFields (vlc_object_t *p_obj, JNIEnv *env)
                 goto end;
         }
     }
+    if (last_class != NULL)
+        (*env)->DeleteLocalRef(env, last_class);
     /* getInputBuffers and getOutputBuffers are deprecated if API >= 21
      * use getInputBuffer and getOutputBuffer instead. */
     if (jfields.get_input_buffer && jfields.get_output_buffer)



More information about the vlc-commits mailing list