Fixed Presence Resource Filter crash
authorErich Keane <erich.keane@intel.com>
Thu, 26 Mar 2015 21:11:54 +0000 (14:11 -0700)
committerSudarshan Prasad <sudarshan.prasad@intel.com>
Sun, 29 Mar 2015 01:55:51 +0000 (01:55 +0000)
The AddClientCB method would delete the resourceTypeName
before it got a chance to insert it due to the logic designed
to make the free'ing consistent.  This fix moves the free until
afterwards.  Note that the insert method does NOT makes a copy,
so it is the responsibility of this method to free in the event
that the pointer is not captured.

Change-Id: I9c0c66cfbfb9e8d1ace5df9de372476fbf262659
Signed-off-by: Erich Keane <erich.keane@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/582
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Joseph Morrow <joseph.l.morrow@intel.com>
Reviewed-by: Sudarshan Prasad <sudarshan.prasad@intel.com>
resource/csdk/stack/src/occlientcb.c
resource/unittests/OCPlatformTest.cpp

index 6aa83ac..cf3f164 100644 (file)
@@ -90,15 +90,21 @@ AddClientCB (ClientCB** clientCB, OCCallbackData* cbData,
         OCFree(*token);
         OCFree(*handle);
         OCFree(requestUri);
-        OCFree(resourceTypeName);
         *handle = cbNode->handle;
     }
 
     #ifdef WITH_PRESENCE
     if(method == OC_REST_PRESENCE && resourceTypeName)
-    {   // Amend the found or created node by adding a new resourceType to it.
+    {
+        // Amend the found or created node by adding a new resourceType to it.
         return InsertResourceTypeFilter(cbNode, resourceTypeName);
     }
+    else
+    {
+        OCFree(resourceTypeName);
+    }
+    #else
+    OCFree(resourceTypeName);
     #endif
 
     return OC_STACK_OK;
index 4d50427..233c025 100644 (file)
@@ -698,9 +698,7 @@ namespace OCPlatformTest
                 OC_MULTICAST_IP, nullptr, OC_WIFI, &presenceHandler));
     }
 
-    //UnsubscribePresence Test
-    //We will enable it after fixing double free or corruption
-    TEST(SubscribePresenceTest, DISABLED_UnsubscribePresenceWithValidHandleAndRT)
+    TEST(SubscribePresenceTest, UnsubscribePresenceWithValidHandleAndRT)
     {
         OCPlatform::OCPresenceHandle presenceHandle = nullptr;