mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-02-13 17:20:09 +00:00
external/jnipp: Fix null pointer exception
Potential null pointer exception if client manually attached the thread.
This commit is contained in:
parent
b621955873
commit
afb56bedc9
8
src/external/jnipp/jnipp.cpp
vendored
8
src/external/jnipp/jnipp.cpp
vendored
|
@ -26,9 +26,13 @@ namespace jni
|
|||
static std::atomic_bool isVm(false);
|
||||
static JavaVM* javaVm = nullptr;
|
||||
|
||||
static bool getEnv(JavaVM *vm, JNIEnv **env) {
|
||||
return vm->GetEnv((void **)env, JNI_VERSION_1_2) == JNI_OK;
|
||||
}
|
||||
|
||||
static bool isAttached(JavaVM *vm) {
|
||||
JNIEnv *env = nullptr;
|
||||
return vm->GetEnv((void **)&env, JNI_VERSION_1_2) == JNI_OK;
|
||||
return getEnv(vm, &env);
|
||||
}
|
||||
/**
|
||||
Maintains the lifecycle of a JNIEnv.
|
||||
|
@ -63,7 +67,7 @@ namespace jni
|
|||
if (vm == nullptr)
|
||||
throw InitializationException("JNI not initialized");
|
||||
|
||||
if (!isAttached(vm))
|
||||
if (!getEnv(vm, &_env))
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
if (vm->AttachCurrentThread(&_env, nullptr) != 0)
|
||||
|
|
Loading…
Reference in a new issue