diff options
author | Christian Strømme <christian.stromme@digia.com> | 2014-03-17 15:38:08 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-03-20 10:36:34 +0100 |
commit | f84e72600e70a0e05b9f81db4b89d2451f5b93c3 (patch) | |
tree | 3cc0b66359138620fb328ed60c53d99da4868896 /src/corelib | |
parent | 84c8e4717c70f0f214f84a5c9430dcc024bf2e8b (diff) |
Android: Check for exception before calling NewGlobalRef().
Calling NewGlobalRef() throws an exception if it gets an invalid ref.
If one of the jni object-calls throws an exception and the returned
reference is invalid, the subsequent call to NewGlobalRef() will trigger
the second exception and the process will be terminated.
Change-Id: I50c622e695542373d5b2eebd911c882e8e0f6bf7
Reviewed-by: Yoann Lopes <yoann.lopes@digia.com>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/kernel/qjni.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/corelib/kernel/qjni.cpp b/src/corelib/kernel/qjni.cpp index aaa75c0fb8..623662a628 100644 --- a/src/corelib/kernel/qjni.cpp +++ b/src/corelib/kernel/qjni.cpp @@ -1264,6 +1264,8 @@ QJNIObjectPrivate QJNIObjectPrivate::callObjectMethod(const char *methodName, jmethodID id = getCachedMethodID(env, d->m_jclass, methodName, sig); if (id) { res = env->CallObjectMethodV(d->m_jobject, id, args); + if (res && env->ExceptionCheck()) + res = 0; } QJNIObjectPrivate obj(res); @@ -1342,6 +1344,8 @@ QJNIObjectPrivate QJNIObjectPrivate::callStaticObjectMethod(const char *classNam jmethodID id = getCachedMethodID(env, clazz, methodName, sig, true); if (id) { res = env->CallStaticObjectMethodV(clazz, id, args); + if (res && env->ExceptionCheck()) + res = 0; } } @@ -1372,6 +1376,8 @@ QJNIObjectPrivate QJNIObjectPrivate::callStaticObjectMethod(jclass clazz, jmethodID id = getCachedMethodID(env, clazz, methodName, sig, true); if (id) { res = env->CallStaticObjectMethodV(clazz, id, args); + if (res && env->ExceptionCheck()) + res = 0; } QJNIObjectPrivate obj(res); @@ -1685,8 +1691,11 @@ QJNIObjectPrivate QJNIObjectPrivate::getObjectField(const char *fieldName, QJNIEnvironmentPrivate env; jobject res = 0; jfieldID id = getCachedFieldID(env, d->m_jclass, fieldName, sig); - if (id) + if (id) { res = env->GetObjectField(d->m_jobject, id); + if (res && env->ExceptionCheck()) + res = 0; + } QJNIObjectPrivate obj(res); env->DeleteLocalRef(res); @@ -1713,8 +1722,11 @@ QJNIObjectPrivate QJNIObjectPrivate::getStaticObjectField(jclass clazz, QJNIEnvironmentPrivate env; jobject res = 0; jfieldID id = getCachedFieldID(env, clazz, fieldName, sig, true); - if (id) + if (id) { res = env->GetStaticObjectField(clazz, id); + if (res && env->ExceptionCheck()) + res = 0; + } QJNIObjectPrivate obj(res); env->DeleteLocalRef(res); |