diff options
author | ylecollen <ylecollen@amdocs.com> | 2016-12-21 15:17:53 +0100 |
---|---|---|
committer | ylecollen <ylecollen@amdocs.com> | 2016-12-21 15:17:53 +0100 |
commit | ffb40326ff41985904ba74cf83a1b6b71e457626 (patch) | |
tree | 9af9a081c31460ac970bfff4691523baac5a33ac /java/android/OlmLibSdk | |
parent | 643165067f4140d7cb3cba88f21b3fc8dd2d244f (diff) |
Fix a potential memory leak.
Diffstat (limited to 'java/android/OlmLibSdk')
-rw-r--r-- | java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_jni_helper.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_jni_helper.cpp b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_jni_helper.cpp index b52ac30..82c3e28 100644 --- a/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_jni_helper.cpp +++ b/java/android/OlmLibSdk/olm-sdk/src/main/jni/olm_jni_helper.cpp @@ -130,8 +130,8 @@ bool setRandomInBuffer(JNIEnv *env, uint8_t **aBuffer2Ptr, size_t aRandomSize) jlong getInstanceId(JNIEnv* aJniEnv, jobject aJavaObject, const char *aCallingClass) { jlong instanceId = 0; - jfieldID instanceIdField; - jclass loaderClass; + jfieldID instanceIdField = 0; + jclass loaderClass = 0; jclass requiredClass = 0; if(NULL!=aJniEnv) @@ -147,7 +147,6 @@ jlong getInstanceId(JNIEnv* aJniEnv, jobject aJavaObject, const char *aCallingCl if(0 != (instanceIdField=aJniEnv->GetFieldID(loaderClass, "mNativeId", "J"))) { instanceId = aJniEnv->GetLongField(aJavaObject, instanceIdField); - aJniEnv->DeleteLocalRef(loaderClass); LOGD("## getInstanceId(): read from java instanceId=%lld",instanceId); } else @@ -164,7 +163,14 @@ jlong getInstanceId(JNIEnv* aJniEnv, jobject aJavaObject, const char *aCallingCl { LOGE("## getInstanceId() ERROR! aJniEnv=NULL"); } + LOGD("## getInstanceId() success - instanceId=%p (jlong)(intptr_t)instanceId=%lld",(void*)instanceId, (jlong)(intptr_t)instanceId); + + if (loaderClass) + { + aJniEnv->DeleteLocalRef(loaderClass); + } + return instanceId; } |