diff options
author | Jeff Hamilton <jham@android.com> | 2011-05-24 08:40:48 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-05-24 08:40:48 -0700 |
commit | 662d698534f9cf3c8224ae4083e55a8c2245af4e (patch) | |
tree | 25e822918fe16e0de3e95aa5454a08358c3f589d /jni | |
parent | 30f99b9a446029bac5cb02b6efe5cae2f0349749 (diff) | |
parent | 6a8cddd71f669bb313788eea562c7e01cd587ae5 (diff) | |
download | packages_apps_nfc-662d698534f9cf3c8224ae4083e55a8c2245af4e.zip packages_apps_nfc-662d698534f9cf3c8224ae4083e55a8c2245af4e.tar.gz packages_apps_nfc-662d698534f9cf3c8224ae4083e55a8c2245af4e.tar.bz2 |
Merge "Another attempt at fixing JNI local reference leaks." into gingerbread
Diffstat (limited to 'jni')
-rw-r--r-- | jni/com_android_nfc.cpp | 40 | ||||
-rwxr-xr-x | jni/com_android_nfc_NativeNfcSecureElement.cpp | 9 |
2 files changed, 31 insertions, 18 deletions
diff --git a/jni/com_android_nfc.cpp b/jni/com_android_nfc.cpp index 6187c13..c9b9da1 100644 --- a/jni/com_android_nfc.cpp +++ b/jni/com_android_nfc.cpp @@ -560,23 +560,35 @@ void nfc_jni_get_technology_tree(JNIEnv* e, phLibNfc_RemoteDevList_t* devList, } } } + // Build the Java arrays - *techList = e->NewIntArray(index); - *handleList = e->NewIntArray(index); - *libnfcTypeList = e->NewIntArray(index); - - jint* techItems = e->GetIntArrayElements(*techList, NULL); - jint* handleItems = e->GetIntArrayElements(*handleList, NULL); - jint* typeItems = e->GetIntArrayElements(*libnfcTypeList, NULL); - for (int i = 0; i < index; i++) { - techItems[i] = technologies[i]; - handleItems[i] = handles[i]; - typeItems[i] = libnfctypes[i]; + if (techList != NULL) { + *techList = e->NewIntArray(index); + jint* techItems = e->GetIntArrayElements(*techList, NULL); + for (int i = 0; i < index; i++) { + techItems[i] = technologies[i]; + } + e->ReleaseIntArrayElements(*techList, techItems, 0); + } + + if (handleList != NULL) { + *handleList = e->NewIntArray(index); + jint* handleItems = e->GetIntArrayElements(*handleList, NULL); + for (int i = 0; i < index; i++) { + handleItems[i] = handles[i]; + } + e->ReleaseIntArrayElements(*handleList, handleItems, 0); } - e->ReleaseIntArrayElements(*techList, techItems, 0); - e->ReleaseIntArrayElements(*handleList, handleItems, 0); - e->ReleaseIntArrayElements(*libnfcTypeList, typeItems, 0); + if (libnfcTypeList != NULL) { + *libnfcTypeList = e->NewIntArray(index); + + jint* typeItems = e->GetIntArrayElements(*libnfcTypeList, NULL); + for (int i = 0; i < index; i++) { + typeItems[i] = libnfctypes[i]; + } + e->ReleaseIntArrayElements(*libnfcTypeList, typeItems, 0); + } } } // namespace android diff --git a/jni/com_android_nfc_NativeNfcSecureElement.cpp b/jni/com_android_nfc_NativeNfcSecureElement.cpp index 1e70839..f309122 100755 --- a/jni/com_android_nfc_NativeNfcSecureElement.cpp +++ b/jni/com_android_nfc_NativeNfcSecureElement.cpp @@ -138,10 +138,7 @@ static void com_android_nfc_jni_open_secure_element_notification_callback(void * /* Set type name */ jintArray techList; - jintArray handleList; - jintArray typeList; - nfc_jni_get_technology_tree(e, psRemoteDevList,uNofRemoteDev, &techList, - &handleList, &typeList); + nfc_jni_get_technology_tree(e, psRemoteDevList,uNofRemoteDev, &techList, NULL, NULL); // TODO: Should use the "connected" technology, for now use the first if ((techList != NULL) && e->GetArrayLength(techList) > 0) { @@ -157,6 +154,10 @@ static void com_android_nfc_jni_open_secure_element_notification_callback(void * LOGE("Discovered secure element, but could not resolve tech"); status = NFCSTATUS_FAILED; } + + // This thread may not return to the virtual machine for a long time + // so make sure to delete the local refernce to the tech list. + if (techList != NULL) e->DeleteLocalRef(techList); } pContextData->status = status; |