[Android] Prevent segfaults
Geoffrey Métais
git at videolan.org
Thu Sep 7 11:45:29 CEST 2017
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Sep 7 11:45:05 2017 +0200| [9fbbc2eeacb998ddacac8c6015b34085e63f15cd] | committer: Geoffrey Métais
Prevent segfaults
> https://code.videolan.org/videolan/vlc-android/commit/9fbbc2eeacb998ddacac8c6015b34085e63f15cd
---
medialibrary/jni/AndroidMediaLibrary.cpp | 4 +++-
medialibrary/jni/medialibrary.cpp | 4 ++++
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/medialibrary/jni/AndroidMediaLibrary.cpp b/medialibrary/jni/AndroidMediaLibrary.cpp
index ebb83eebd..7c87b8353 100644
--- a/medialibrary/jni/AndroidMediaLibrary.cpp
+++ b/medialibrary/jni/AndroidMediaLibrary.cpp
@@ -161,7 +161,9 @@ AndroidMediaLibrary::forceParserRetry()
bool
AndroidMediaLibrary::increasePlayCount(int64_t mediaId)
{
- return p_ml->media(mediaId)->increasePlayCount();
+ auto media = p_ml->media(mediaId);
+ if (media != nullptr)
+ return media->increasePlayCount();
}
std::vector<medialibrary::MediaPtr>
diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index 9c9698a20..fb9e250b2 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -667,6 +667,8 @@ setMediaStringMetadata(JNIEnv* env, jobject thiz, jobject medialibrary, jlong id
AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, medialibrary);
const char *char_meta = env->GetStringUTFChars(meta, JNI_FALSE);
medialibrary::MediaPtr media = aml->media(id);
+ if (media == nullptr)
+ return;
media->setMetadata((medialibrary::IMedia::MetadataType)metadataType, char_meta);
env->ReleaseStringUTFChars(meta, char_meta);
}
@@ -676,6 +678,8 @@ setMediaLongMetadata(JNIEnv* env, jobject thiz, jobject medialibrary, jlong id,
{
AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, medialibrary);
medialibrary::MediaPtr media = aml->media(id);
+ if (media == nullptr)
+ return;
media->setMetadata((medialibrary::IMedia::MetadataType)metadataType, meta);
}
More information about the Android
mailing list