Correctly release PoolResource memory

Reviewers: mferencevic, ipaljak

Reviewed By: mferencevic

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D2341
This commit is contained in:
Teon Banek 2019-09-02 14:43:20 +02:00
parent ed802073f6
commit 32ae2b4d23
2 changed files with 7 additions and 0 deletions

View File

@ -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

View File

@ -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)