Android: fix double-freeing of a global references on app exit
The m_activityObject and m_serviceObjects are no longer plain jobjects. Instead they are constructed with a jobject. The constructor makes it a global ref, which the destructor then frees. The destruction happens when the stdlib exit() is called. However, since the terminateQt() function already had released the global ref, the destruction of the objects crashes the application with a JNI APPLICATION ERROR in Android logs. In addition since the the code only ever freed the reference to a reference, the actual reference was leaked. Change-Id: I6bb637dba2de59e89436685a9d63950d36438fa5 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
This commit is contained in:
parent
4102db752e
commit
c0bc0d0643
@ -583,10 +583,6 @@ static void terminateQt(JNIEnv *env, jclass /*clazz*/)
|
||||
env->DeleteGlobalRef(m_classLoaderObject);
|
||||
if (m_resourcesObj)
|
||||
env->DeleteGlobalRef(m_resourcesObj);
|
||||
if (m_activityObject)
|
||||
env->DeleteGlobalRef(m_activityObject);
|
||||
if (m_serviceObject)
|
||||
env->DeleteGlobalRef(m_serviceObject);
|
||||
if (m_bitmapClass)
|
||||
env->DeleteGlobalRef(m_bitmapClass);
|
||||
if (m_ARGB_8888_BitmapConfigValue)
|
||||
@ -879,10 +875,10 @@ static int registerNatives(JNIEnv *env)
|
||||
clazz = env->GetObjectClass(m_classLoaderObject);
|
||||
GET_AND_CHECK_METHOD(m_loadClassMethodID, clazz, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;");
|
||||
if (serviceObject)
|
||||
m_serviceObject = env->NewGlobalRef(serviceObject);
|
||||
m_serviceObject = serviceObject; // m_serviceObject creates and manages as global ref
|
||||
|
||||
if (activityObject)
|
||||
m_activityObject = env->NewGlobalRef(activityObject);
|
||||
m_activityObject = activityObject; // m_activityObject creates and manages as global ref
|
||||
|
||||
jobject object = activityObject ? activityObject : serviceObject;
|
||||
if (object) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user