[Android] LibVLC: handle failures when getting the cache path

Felix Abecassis git at videolan.org
Wed Jul 9 18:58:35 CEST 2014


vlc-ports/android | branch: master | Felix Abecassis <felix.abecassis at gmail.com> | Wed Jul  9 18:51:51 2014 +0200| [774bcd524eaa36f8c904e13b48700b7f3ebac1a6] | committer: Felix Abecassis

LibVLC: handle failures when getting the cache path

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=774bcd524eaa36f8c904e13b48700b7f3ebac1a6
---

 vlc-android/jni/libvlcjni.c                     |    8 +++++---
 vlc-android/src/org/videolan/libvlc/LibVLC.java |    4 +++-
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/vlc-android/jni/libvlcjni.c b/vlc-android/jni/libvlcjni.c
index 821c4f0..9781d76 100644
--- a/vlc-android/jni/libvlcjni.c
+++ b/vlc-android/jni/libvlcjni.c
@@ -262,8 +262,11 @@ void Java_org_videolan_libvlc_LibVLC_nativeInit(JNIEnv *env, jobject thiz)
 
     methodId = (*env)->GetMethodID(env, cls, "getCachePath", "()Ljava/lang/String;");
     jstring cachePath = (*env)->CallObjectMethod(env, thiz, methodId);
-    const char *cache_path = (*env)->GetStringUTFChars(env, cachePath, 0);
-    setenv("DVDCSS_CACHE", cache_path, 1);
+    if (cachePath) {
+        const char *cache_path = (*env)->GetStringUTFChars(env, cachePath, 0);
+        setenv("DVDCSS_CACHE", cache_path, 1);
+        (*env)->ReleaseStringUTFChars(env, cachePath, cache_path);
+    }
 
     /* Don't add any invalid options, otherwise it causes LibVLC to crash */
     const char *argv[] = {
@@ -297,7 +300,6 @@ void Java_org_videolan_libvlc_LibVLC_nativeInit(JNIEnv *env, jobject thiz)
 
     (*env)->ReleaseStringUTFChars(env, chroma, chromastr);
     (*env)->ReleaseStringUTFChars(env, subsencoding, subsencodingstr);
-    (*env)->ReleaseStringUTFChars(env, cachePath, cache_path);
 
     if (!instance)
     {
diff --git a/vlc-android/src/org/videolan/libvlc/LibVLC.java b/vlc-android/src/org/videolan/libvlc/LibVLC.java
index ccc6ade..ec8571f 100644
--- a/vlc-android/src/org/videolan/libvlc/LibVLC.java
+++ b/vlc-android/src/org/videolan/libvlc/LibVLC.java
@@ -20,6 +20,7 @@
 
 package org.videolan.libvlc;
 
+import java.io.File;
 import java.util.ArrayList;
 import java.util.Map;
 
@@ -378,7 +379,8 @@ public class LibVLC {
                 throw new LibVlcException();
             }
 
-            mCachePath = context.getCacheDir().getAbsolutePath();
+            File cacheDir = context.getCacheDir();
+            mCachePath = (cacheDir != null) ? cacheDir.getAbsolutePath() : null;
             nativeInit();
             mMediaList = mPrimaryList = new MediaList(this);
             setEventHandler(EventHandler.getInstance());



More information about the Android mailing list