From: Jianpeng Ma Date: Thu, 22 Nov 2018 07:36:40 +0000 (+0800) Subject: test_shared_cache: fix memory leak. X-Git-Tag: v14.1.0~807^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=4c86b6c34e1c88f67acb72fefb36b89a19264f15;p=ceph-ci.git test_shared_cache: fix memory leak. Based on SharedLRU::add, If the key already existed, you are responsible for deleting the new value you tried to insert. Signed-off-by: Jianpeng Ma --- diff --git a/src/test/common/test_shared_cache.cc b/src/test/common/test_shared_cache.cc index 8db5d9ce37c..eeb526236c9 100644 --- a/src/test/common/test_shared_cache.cc +++ b/src/test/common/test_shared_cache.cc @@ -109,9 +109,11 @@ TEST_F(SharedLRU_all, add) { } { int value2 = 3; - std::shared_ptr ptr = cache.add(key, new int(value2), &existed); + auto p = new int(value2); + std::shared_ptr ptr = cache.add(key, p, &existed); ASSERT_EQ(value1, *ptr); ASSERT_TRUE(existed); + delete p; } } TEST_F(SharedLRU_all, empty) {