[Android] Fix lolcaRefs leaks in medialibrary

Geoffrey Métais git at videolan.org
Thu Mar 2 15:11:15 CET 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Mar  2 14:44:47 2017 +0100| [352d0526177760c4446970e2fefb05913e6dc73c] | committer: Geoffrey Métais

Fix lolcaRefs leaks in medialibrary

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

 medialibrary/jni/medialibrary.cpp | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index a710dbc..335ff85 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -75,8 +75,9 @@ devices(JNIEnv* env, jobject thiz)
     jobjectArray deviceRefs = (jobjectArray) env->NewObjectArray(devices.size(), env->FindClass("java/lang/String"), NULL);
     int index = -1;
     for(auto device : devices) {
-        std::string path = std::get<1>(device);
-        env->SetObjectArrayElement(deviceRefs, ++index, env->NewStringUTF(path.c_str()));
+        jstring path = env->NewStringUTF(std::get<1>(device).c_str());
+        env->SetObjectArrayElement(deviceRefs, ++index, path);
+        env->DeleteLocalRef(path);
     }
     return deviceRefs;
 }
@@ -108,7 +109,9 @@ entryPoints(JNIEnv* env, jobject thiz)
     jobjectArray mediaRefs = (jobjectArray) env->NewObjectArray(entryPoints.size(), env->FindClass("java/lang/String"), NULL);
     int index = -1;
     for(medialibrary::FolderPtr const& entrypoint : entryPoints) {
-        env->SetObjectArrayElement(mediaRefs, ++index, env->NewStringUTF(entrypoint->mrl().c_str()));
+        jstring mrl = env->NewStringUTF(entrypoint->mrl().c_str());
+        env->SetObjectArrayElement(mediaRefs, ++index, mrl);
+        env->DeleteLocalRef(mrl);
     }
     return mediaRefs;
 }



More information about the Android mailing list