From: KIM JungYong Date: Thu, 13 Apr 2017 07:05:28 +0000 (+0900) Subject: Fix for double free in RE cache unit test. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=adf2b45fbf966a4a87f8ccf2c0157856c41e0493;p=contrib%2Fiotivity.git Fix for double free in RE cache unit test. [Problem] When RE cache unit test is terminated, always will crash af double free. [Reason] double freed valiable is shared pointer of mock object. this pointer will remove twice on release of mock object and shared pointer. [Fix] Deleter as non-operation was added on the creation of shared pointer. Change-Id: I6434795fd011312b1a9bcb5ecf0d092aab19b487 Signed-off-by: KIM JungYong Reviewed-on: https://gerrit.iotivity.org/gerrit/18893 Reviewed-by: Jay Sharma Tested-by: jenkins-iotivity Reviewed-by: Uze Choi --- diff --git a/service/resource-encapsulation/src/resourceCache/unittests/DataCacheTest.cpp b/service/resource-encapsulation/src/resourceCache/unittests/DataCacheTest.cpp index 617596c..ec628bc 100644 --- a/service/resource-encapsulation/src/resourceCache/unittests/DataCacheTest.cpp +++ b/service/resource-encapsulation/src/resourceCache/unittests/DataCacheTest.cpp @@ -57,7 +57,8 @@ class DataCacheTest : public TestWithMock std::call_once(flag, [this]() { isLast = false; - pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >()); + auto deleter = [](PrimitiveResource *) { }; + pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(), deleter); }); } virtual ~DataCacheTest() noexcept(noexcept(std::declval().~Test())) diff --git a/service/resource-encapsulation/src/resourceCache/unittests/ResourceCacheTest.cpp b/service/resource-encapsulation/src/resourceCache/unittests/ResourceCacheTest.cpp index 67d443d..70c7818 100644 --- a/service/resource-encapsulation/src/resourceCache/unittests/ResourceCacheTest.cpp +++ b/service/resource-encapsulation/src/resourceCache/unittests/ResourceCacheTest.cpp @@ -47,7 +47,8 @@ class ResourceCacheManagerTest : public TestWithMock std::call_once(flag, [this]() { isLast = false; - pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >()); + auto deleter = [](PrimitiveResource *) { }; + pResource = PrimitiveResource::Ptr(mocks.Mock< PrimitiveResource >(), deleter); }); mocks.OnCall(pResource.get(), PrimitiveResource::isObservable).Return(false); cb = ([](std::shared_ptr, const RCSResourceAttributes &)->OCStackResult