From 445efa40a290da0f72a4b7c213ea991193d51917 Mon Sep 17 00:00:00 2001 From: Yoann Lopes Date: Tue, 24 Sep 2013 15:31:23 +0200 Subject: [PATCH] Fixed QJNIEnvironment reference counting. Change-Id: I02369e0c6472375efeffed577d39b764c591e025 Reviewed-by: Christian Stromme --- src/corelib/kernel/qjni.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/corelib/kernel/qjni.cpp b/src/corelib/kernel/qjni.cpp index 17678fcbba..f26d4379d3 100644 --- a/src/corelib/kernel/qjni.cpp +++ b/src/corelib/kernel/qjni.cpp @@ -160,10 +160,12 @@ QJNIEnvironmentPrivate::QJNIEnvironmentPrivate() : jniEnv(0) { JavaVM *vm = QtAndroidPrivate::javaVM(); - if (vm->GetEnv((void**)&jniEnv, JNI_VERSION_1_6) != JNI_EDETACHED) - return; + if (vm->GetEnv((void**)&jniEnv, JNI_VERSION_1_6) == JNI_EDETACHED) { + if (vm->AttachCurrentThread(&jniEnv, 0) < 0) + return; + } - if (vm->AttachCurrentThread(&jniEnv, 0) < 0) + if (!jniEnv) return; if (!refCount->hasLocalData())