Details
-
Bug
-
Resolution: Done
-
P1: Critical
-
5.4.1
-
None
-
-
6b19eec63190c385a465c29b1f811214c6257034
Description
Qt detaches threads that it did not attach which is an unexpected behaviour and may cause weird effects or crash in apps which also use non-Qt access to JNI. Also it crashes QCoreApplication-based app on Android (e.g. service or app without Qt GUI) with ART because QCoreApplication trashes thread storage in destructor before the thread has actually finished ant it causes ART to terminate application.
The fix is trivial, just move 2 lines:
--- a/qtbase/src/corelib/kernel/qjni.cpp +++ b/qtbase/src/corelib/kernel/qjni.cpp @@ -225,13 +225,9 @@ QJNIEnvironmentPrivate::QJNIEnvironmentPrivate() JavaVMAttachArgs args = { JNI_VERSION_1_6, qJniThreadName, Q_NULLPTR }; if (vm->AttachCurrentThread(&jniEnv, &args) != JNI_OK) return; + if (!jniEnvTLS->hasLocalData()) + jniEnvTLS->setLocalData(new QJNIEnvironmentPrivateTLS); } - - if (!jniEnv) - return; - - if (!jniEnvTLS->hasLocalData()) - jniEnvTLS->setLocalData(new QJNIEnvironmentPrivateTLS); }
Attachments
For Gerrit Dashboard: QTBUG-45110 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
109290,3 | Android: Only take ownership of threads we explicitly attach to. | 5.5 | qt/qtbase | Status: MERGED | +2 | 0 |