From 32ae2b4d23aeb063a0e859ebaaddaf64c4e43b4a Mon Sep 17 00:00:00 2001 From: Teon Banek Date: Mon, 2 Sep 2019 14:43:20 +0200 Subject: [PATCH] Correctly release PoolResource memory Reviewers: mferencevic, ipaljak Reviewed By: mferencevic Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D2341 --- src/utils/memory.cpp | 4 ++++ tests/unit/utils_memory.cpp | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/utils/memory.cpp b/src/utils/memory.cpp index b14e58e9e..c5a0de12b 100644 --- a/src/utils/memory.cpp +++ b/src/utils/memory.cpp @@ -256,6 +256,8 @@ void Pool::Release() { GetUpstreamResource()->Deallocate(chunk.data, data_size, alignment); } chunks_.clear(); + last_alloc_chunk_ = nullptr; + last_dealloc_chunk_ = nullptr; } } // namespace impl @@ -363,6 +365,8 @@ void PoolResource::Release() { GetUpstreamResource()->Deallocate(big_block.data, big_block.bytes, big_block.alignment); unpooled_.clear(); + last_alloc_pool_ = nullptr; + last_dealloc_pool_ = nullptr; } // PoolResource END diff --git a/tests/unit/utils_memory.cpp b/tests/unit/utils_memory.cpp index 64fdd5e1a..22e49ad37 100644 --- a/tests/unit/utils_memory.cpp +++ b/tests/unit/utils_memory.cpp @@ -219,6 +219,7 @@ TEST(PoolResource, SingleSmallBlockAllocations) { EXPECT_EQ(test_mem.delete_count_, 0U); mem.Release(); EXPECT_GE(test_mem.delete_count_, 2U); + CheckAllocation(&mem, 64U, 1U); } // NOLINTNEXTLINE(hicpp-special-member-functions) @@ -241,6 +242,7 @@ TEST(PoolResource, MultipleSmallBlockAllocations) { EXPECT_TRUE(test_mem.new_count_ >= 3U && test_mem.new_count_ <= 6U); mem.Release(); EXPECT_GE(test_mem.delete_count_, 6U); + CheckAllocation(&mem, 64U); } // NOLINTNEXTLINE(hicpp-special-member-functions) @@ -260,6 +262,7 @@ TEST(PoolResource, BigBlockAllocations) { EXPECT_GE(test_mem.delete_count_, 1U); mem.Release(); EXPECT_GE(test_mem.delete_count_, 3U); + CheckAllocation(&mem, max_block_size + 1, 1U); } // NOLINTNEXTLINE(hicpp-special-member-functions)