[Android] libvlc: release native string returned from libvlc_media_get_mrl

Martin Finkel git at videolan.org
Wed Mar 13 11:12:02 CET 2019


vlc-android | branch: 3.1.x | Martin Finkel <martin at videolabs.io> | Fri Mar  8 16:40:44 2019 +0700| [4cca0e883f08c866f2eb3c6a66cdc896125aafb7] | committer: Geoffrey Métais

libvlc: release native string returned from libvlc_media_get_mrl

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

 libvlc/jni/libvlcjni-media.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/libvlc/jni/libvlcjni-media.c b/libvlc/jni/libvlcjni-media.c
index 33ecc5bfa..efcdd7650 100644
--- a/libvlc/jni/libvlcjni-media.c
+++ b/libvlc/jni/libvlcjni-media.c
@@ -356,16 +356,18 @@ jstring
 Java_org_videolan_libvlc_Media_nativeGetMrl(JNIEnv *env, jobject thiz)
 {
     vlcjni_object *p_obj = VLCJniObject_getInstance(env, thiz);
-    const char *psz_mrl;
+    jstring jmrl = NULL;
 
     if (!p_obj)
         return NULL;
 
-    psz_mrl = libvlc_media_get_mrl(p_obj->u.p_m);
-    if (psz_mrl)
-        return (*env)->NewStringUTF(env, psz_mrl);
+    char *psz_mrl = libvlc_media_get_mrl(p_obj->u.p_m);
+    if (psz_mrl) {
+        jmrl = (*env)->NewStringUTF(env, psz_mrl);
+        free(psz_mrl);
+    }
 
-    return NULL;
+    return jmrl;
 }
 
 jint



More information about the Android mailing list