fixed an issue there is no check null for connection manager.
authorjihwan.seo <jihwan.seo@samsung.com>
Mon, 14 Mar 2016 11:41:35 +0000 (20:41 +0900)
committerJon A. Cruz <jon@joncruz.org>
Wed, 16 Mar 2016 07:48:37 +0000 (07:48 +0000)
Change-Id: I1a8d48f5a12489f6c5809cdcdcaa0b2ea1304892
Signed-off-by: jihwan.seo <jihwan.seo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/5881
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jaehong Jo <jaehong.jo@samsung.com>
Reviewed-by: Jon A. Cruz <jon@joncruz.org>
resource/csdk/connectivity/util/src/camanager/android/caleconnectionmanager.c

index 9ef823deacd67afba37a77ed8f1ede06c308a32d..c4e43e3867c5a036e933c8d12bb5f2f007733386 100644 (file)
@@ -504,6 +504,12 @@ Java_org_iotivity_ca_CaLeClientInterface_caManagerLeServicesDiscoveredCallback(J
 
     if (GATT_SUCCESS == status)
     {
+        if (!g_connectedDeviceSet)
+        {
+            OIC_LOG(ERROR, TAG, "g_connectedDeviceSet is null");
+            return;
+        }
+
         jstring jni_address = CAManagerGetAddressFromGatt(env, gatt);
         if (!jni_address)
         {
@@ -515,6 +521,7 @@ Java_org_iotivity_ca_CaLeClientInterface_caManagerLeServicesDiscoveredCallback(J
         if (!address)
         {
             OIC_LOG(ERROR, TAG, "address is null");
+            (*env)->DeleteLocalRef(env, jni_address);
             return;
         }
         OIC_LOG_V(DEBUG, TAG, "ServicesDiscovered device : %s", address);
@@ -525,13 +532,19 @@ Java_org_iotivity_ca_CaLeClientInterface_caManagerLeServicesDiscoveredCallback(J
         if (!jni_cls_set)
         {
             OIC_LOG(ERROR, TAG, "jni_cls_set is null");
+            (*env)->ReleaseStringUTFChars(env, jni_address, address);
+            (*env)->DeleteLocalRef(env, jni_address);
             return;
         }
 
-        jmethodID jni_mid_iterator = (*env)->GetMethodID(env, jni_cls_set, "iterator", "()Ljava/util/Iterator;");
+        jmethodID jni_mid_iterator = (*env)->GetMethodID(env, jni_cls_set, "iterator",
+                                                            "()Ljava/util/Iterator;");
         if (!jni_mid_iterator)
         {
             OIC_LOG(ERROR, TAG, "jni_mid_iterator is null");
+            (*env)->DeleteLocalRef(env, jni_cls_set);
+            (*env)->ReleaseStringUTFChars(env, jni_address, address);
+            (*env)->DeleteLocalRef(env, jni_address);
             return;
         }
 
@@ -539,6 +552,9 @@ Java_org_iotivity_ca_CaLeClientInterface_caManagerLeServicesDiscoveredCallback(J
         if (!jni_obj_iter)
         {
             OIC_LOG(ERROR, TAG, "jni_obj_iter is null");
+            (*env)->DeleteLocalRef(env, jni_cls_set);
+            (*env)->ReleaseStringUTFChars(env, jni_address, address);
+            (*env)->DeleteLocalRef(env, jni_address);
             return;
         }
 
@@ -547,6 +563,10 @@ Java_org_iotivity_ca_CaLeClientInterface_caManagerLeServicesDiscoveredCallback(J
         if (!jni_cls_iterator)
         {
             OIC_LOG(ERROR, TAG, "jni_cls_iterator is null");
+            (*env)->DeleteLocalRef(env, jni_obj_iter);
+            (*env)->DeleteLocalRef(env, jni_cls_set);
+            (*env)->ReleaseStringUTFChars(env, jni_address, address);
+            (*env)->DeleteLocalRef(env, jni_address);
             return;
         }
 
@@ -554,24 +574,52 @@ Java_org_iotivity_ca_CaLeClientInterface_caManagerLeServicesDiscoveredCallback(J
         if (!jni_mid_hasNext)
         {
             OIC_LOG(ERROR, TAG, "jni_mid_hasNext is null");
+            (*env)->DeleteLocalRef(env, jni_cls_iterator);
+            (*env)->DeleteLocalRef(env, jni_obj_iter);
+            (*env)->DeleteLocalRef(env, jni_cls_set);
+            (*env)->ReleaseStringUTFChars(env, jni_address, address);
+            (*env)->DeleteLocalRef(env, jni_address);
             return;
         }
 
-        jmethodID jni_mid_next = (*env)->GetMethodID(env, jni_cls_iterator, "next", "()Ljava/lang/Object;");
+        jmethodID jni_mid_next = (*env)->GetMethodID(env, jni_cls_iterator, "next",
+                                                        "()Ljava/lang/Object;");
         if (!jni_mid_next)
         {
             OIC_LOG(ERROR, TAG, "jni_mid_next is null");
+            (*env)->DeleteLocalRef(env, jni_cls_iterator);
+            (*env)->DeleteLocalRef(env, jni_obj_iter);
+            (*env)->DeleteLocalRef(env, jni_cls_set);
+            (*env)->ReleaseStringUTFChars(env, jni_address, address);
+            (*env)->DeleteLocalRef(env, jni_address);
             return;
         }
 
         // Iterate over the entry Set
         while ((*env)->CallBooleanMethod(env, jni_obj_iter, jni_mid_hasNext))
         {
-            jstring jni_str_entry = (jstring)(*env)->CallObjectMethod(env, jni_obj_iter, jni_mid_next);
+            jstring jni_str_entry = (jstring)(*env)->CallObjectMethod(env, jni_obj_iter,
+                                                                        jni_mid_next);
+            if (!jni_str_entry)
+            {
+                OIC_LOG(ERROR, TAG, "jni_str_entry is null");
+                (*env)->DeleteLocalRef(env, jni_cls_iterator);
+                (*env)->DeleteLocalRef(env, jni_obj_iter);
+                (*env)->DeleteLocalRef(env, jni_cls_set);
+                (*env)->ReleaseStringUTFChars(env, jni_address, address);
+                (*env)->DeleteLocalRef(env, jni_address);
+                return;
+            }
             const char* foundAddress = (*env)->GetStringUTFChars(env, jni_str_entry, NULL);
             if (!foundAddress)
             {
                 OIC_LOG(ERROR, TAG, "addr is null");
+                (*env)->DeleteLocalRef(env, jni_str_entry);
+                (*env)->DeleteLocalRef(env, jni_cls_iterator);
+                (*env)->DeleteLocalRef(env, jni_obj_iter);
+                (*env)->DeleteLocalRef(env, jni_cls_set);
+                (*env)->ReleaseStringUTFChars(env, jni_address, address);
+                (*env)->DeleteLocalRef(env, jni_address);
                 return;
             }
             OIC_LOG_V(INFO, TAG, "found last connected address [%s] from SharedPreferences",
@@ -603,12 +651,12 @@ Java_org_iotivity_ca_CaLeClientInterface_caManagerLeServicesDiscoveredCallback(J
             g_connStateCB(CA_ADAPTER_GATT_BTLE, address, true);
             OIC_LOG(DEBUG, TAG, "LE Connected callback is called");
         }
+
+        (*env)->DeleteLocalRef(env, jni_cls_iterator);
+        (*env)->DeleteLocalRef(env, jni_obj_iter);
+        (*env)->DeleteLocalRef(env, jni_cls_set);
         (*env)->ReleaseStringUTFChars(env, jni_address, address);
         (*env)->DeleteLocalRef(env, jni_address);
-        (*env)->DeleteLocalRef(env, jni_cls_set);
-        (*env)->DeleteLocalRef(env, jni_obj_iter);
-        (*env)->DeleteLocalRef(env, jni_cls_iterator);
-
         OIC_LOG(INFO, TAG, "ServicesDiscovery is successful");
     }
     else