Fix for double free in RE cache unit test.
authorKIM JungYong <jyong2.kim@samsung.com>
Thu, 13 Apr 2017 07:05:28 +0000 (16:05 +0900)
committerUze Choi <uzchoi@samsung.com>
Mon, 17 Apr 2017 04:25:25 +0000 (04:25 +0000)
[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 <jyong2.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/18893
Reviewed-by: Jay Sharma <jay.sharma@samsung.com>
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/resource-encapsulation/src/resourceCache/unittests/DataCacheTest.cpp
service/resource-encapsulation/src/resourceCache/unittests/ResourceCacheTest.cpp

index 617596c..ec628bc 100644 (file)
@@ -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>().~Test()))
index 67d443d..70c7818 100644 (file)
@@ -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<PrimitiveResource >, const RCSResourceAttributes &)->OCStackResult