[Android] Prevent segfaults

Geoffrey Métais git at videolan.org
Mon Aug 21 17:57:54 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Aug 21 16:49:30 2017 +0200| [7347cde7f94baab7bb3e1e51f9569b3d96d3b440] | committer: Geoffrey Métais

Prevent segfaults

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

 medialibrary/jni/medialibrary.cpp | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index e011fb8ce..9c9698a20 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -644,6 +644,8 @@ getMediaLongMetadata(JNIEnv* env, jobject thiz, jobject medialibrary, jlong id,
 {
     AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, medialibrary);
     medialibrary::MediaPtr media = aml->media(id);
+    if (media == nullptr)
+        return 0L;
     const medialibrary::IMediaMetadata& metadata = media->metadata((medialibrary::IMedia::MetadataType)metadataType);
     return metadata.isSet() ? metadata.integer() : 0L;
 }
@@ -653,6 +655,8 @@ getMediaStringMetadata(JNIEnv* env, jobject thiz, jobject medialibrary, jlong id
 {
     AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, medialibrary);
     medialibrary::MediaPtr media = aml->media(id);
+    if (media == nullptr)
+        return 0L;
     const medialibrary::IMediaMetadata& metadata = media->metadata((medialibrary::IMedia::MetadataType)metadataType);
     return metadata.isSet() ? env->NewStringUTF(metadata.str().c_str()) : nullptr;
 }



More information about the Android mailing list