[Android] jni: fix invalid ReleaseStringUTFChars() call

Thomas Guillem git at videolan.org
Thu Jun 13 15:36:46 CEST 2019


vlc-android | branch: master | Thomas Guillem <thomas at gllm.fr> | Thu Jun 13 15:10:59 2019 +0200| [d371e43fb186d8df9dd6bdf3e1080d9641db598e] | committer: Thomas Guillem

jni: fix invalid ReleaseStringUTFChars() call

This function must only be used to release a java string returned by
GetStringUTFChars().

Strings allocated via NewStringUTF() must not be released, only the local ref
should (it will be released by the garbage collector once it's not referenced
anymore).

This fixes a major memory corruption leading to various incoherent crashes.

> https://code.videolan.org/videolan/vlc-android/commit/d371e43fb186d8df9dd6bdf3e1080d9641db598e
---

 libvlc/jni/libvlcjni-vlcobject.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libvlc/jni/libvlcjni-vlcobject.c b/libvlc/jni/libvlcjni-vlcobject.c
index 5233c496d..841fa34ad 100644
--- a/libvlc/jni/libvlcjni-vlcobject.c
+++ b/libvlc/jni/libvlcjni-vlcobject.c
@@ -199,8 +199,8 @@ VLCJniObject_eventCallback(const libvlc_event_t *ev, void *data)
                                      p_obj->p_owner->weakCompat,
                                      jevent.type, jevent.arg1, jevent.arg2,
                                      jevent.argf1, string);
-    if (jevent.argc1)
-        (*env)->ReleaseStringUTFChars(env, string, jevent.argc1);
+    if (string)
+        (*env)->DeleteLocalRef(env, string);
 }
 
 void



More information about the Android mailing list