[vlc-commits] mediacodec: jni: fix GET_INTEGER crashes

Thomas Guillem git at videolan.org
Tue Jul 28 18:55:45 CEST 2015


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Mon Jul 27 11:19:38 2015 +0200| [b11cd7d1ca4bcff412f486a85fc20e4df59fde64] | committer: Thomas Guillem

mediacodec: jni: fix GET_INTEGER crashes

It happens when fetching the "channel-mask" property.

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

 modules/codec/omxil/mediacodec_jni.c |   28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/modules/codec/omxil/mediacodec_jni.c b/modules/codec/omxil/mediacodec_jni.c
index 43cad37..294c69c 100644
--- a/modules/codec/omxil/mediacodec_jni.c
+++ b/modules/codec/omxil/mediacodec_jni.c
@@ -143,16 +143,6 @@ static const struct member members[] = {
     { NULL, NULL, NULL, 0, 0, false },
 };
 
-static inline int get_integer(JNIEnv *env, jobject obj, const char *psz_name)
-{
-    int i_ret;
-    jstring jname = (*env)->NewStringUTF(env, psz_name);
-    i_ret = (*env)->CallIntMethod(env, obj, jfields.get_integer, jname);
-    (*env)->DeleteLocalRef(env, jname);
-    return i_ret;
-}
-#define GET_INTEGER(obj, name) get_integer(env, obj, name)
-
 static int jstrcmp(JNIEnv* env, jobject str, const char* str2)
 {
     jsize len = (*env)->GetStringUTFLength(env, str);
@@ -177,6 +167,24 @@ static inline bool check_exception(JNIEnv *env)
 #define CHECK_EXCEPTION() check_exception( env )
 #define GET_ENV() if (!(env = android_getEnv(api->p_obj, THREAD_NAME))) return VLC_EGENERIC;
 
+static inline int get_integer(JNIEnv *env, jobject obj, const char *psz_name)
+{
+    jstring jname = (*env)->NewStringUTF(env, psz_name);
+    if (!CHECK_EXCEPTION() && jname)
+    {
+        int i_ret = (*env)->CallIntMethod(env, obj, jfields.get_integer, jname);
+        (*env)->DeleteLocalRef(env, jname);
+        /* getInteger can throw NullPointerException (when fetching the
+         * "channel-mask" property for example) */
+        if (CHECK_EXCEPTION())
+            return 0;
+        return i_ret;
+    }
+    else
+        return 0;
+}
+#define GET_INTEGER(obj, name) get_integer(env, obj, name)
+
 /* Initialize all jni fields.
  * Done only one time during the first initialisation */
 static bool



More information about the vlc-commits mailing list