From: Erich Keane Date: Thu, 26 Mar 2015 21:11:54 +0000 (-0700) Subject: Fixed Presence Resource Filter crash X-Git-Tag: 1.2.0+RC1~1855^2~59 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a69f1161f1f32f70b5461d800361e96d87e220a2;p=platform%2Fupstream%2Fiotivity.git Fixed Presence Resource Filter crash 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 Reviewed-on: https://gerrit.iotivity.org/gerrit/582 Tested-by: jenkins-iotivity Reviewed-by: Joseph Morrow Reviewed-by: Sudarshan Prasad --- diff --git a/resource/csdk/stack/src/occlientcb.c b/resource/csdk/stack/src/occlientcb.c index 6aa83ac..cf3f164 100644 --- a/resource/csdk/stack/src/occlientcb.c +++ b/resource/csdk/stack/src/occlientcb.c @@ -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; diff --git a/resource/unittests/OCPlatformTest.cpp b/resource/unittests/OCPlatformTest.cpp index 4d50427..233c025 100644 --- a/resource/unittests/OCPlatformTest.cpp +++ b/resource/unittests/OCPlatformTest.cpp @@ -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;