Skip to content

Commit

Permalink
fixing mem leak
Browse files Browse the repository at this point in the history
  • Loading branch information
kab163 committed Oct 10, 2024
1 parent 812f2d4 commit d2c58d1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
4 changes: 3 additions & 1 deletion src/umpire/strategy/ResourceAwarePool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ void ResourceAwarePool::do_deallocate(Chunk* chunk, void* ptr) noexcept
UMPIRE_LOG(Debug, "Merging with prev" << prev << " and " << chunk);
UMPIRE_LOG(Debug, "New size: " << prev->size);

chunk->~Chunk(); //manually call destructor
m_chunk_pool.deallocate(chunk);
chunk = prev;
}
Expand All @@ -225,7 +226,6 @@ void ResourceAwarePool::do_deallocate(Chunk* chunk, void* ptr) noexcept
chunk->size += next->size;
chunk->next = next->next;

// TODO: Double check this
chunk->m_event = next->m_event;
chunk->m_resource = next->m_resource;

Expand All @@ -238,6 +238,7 @@ void ResourceAwarePool::do_deallocate(Chunk* chunk, void* ptr) noexcept
UMPIRE_LOG(Debug, "Removing chunk" << next << " from size map");
m_free_map.erase(next->size_map_it);

next->~Chunk(); //manually call destructor
m_chunk_pool.deallocate(next);
}

Expand Down Expand Up @@ -340,6 +341,7 @@ void ResourceAwarePool::release()
}
}

chunk->~Chunk(); //manually call destructor
m_chunk_pool.deallocate(chunk);
pair = m_free_map.erase(pair);
} else {
Expand Down
31 changes: 14 additions & 17 deletions tests/integration/resource_aware_pool_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,29 @@ TEST(ResourceAwarePool_Host_Test, Check_States_Host)
auto& rm = umpire::ResourceManager::getInstance();
auto pool = rm.makeAllocator<umpire::strategy::ResourceAwarePool>("rap-pool-host", rm.getAllocator("HOST"));

Host h1, h2;
Resource r1{h1}, r2{h2};
Resource r1{Host{}}, r2{Host{}};
int* ptr = static_cast<int*>(pool.allocate(r1, 1024));
// int* compare_ptr1 = ptr;
int* compare_ptr1 = ptr;

// EXPECT_EQ(getResource(pool, ptr), r1);
// EXPECT_EQ(getPendingSize(pool), 0);
EXPECT_EQ(getResource(pool, ptr), r1);
EXPECT_EQ(getPendingSize(pool), 0);

// host_sleep(ptr);
host_sleep(ptr);

pool.deallocate(r1, ptr);
// EXPECT_EQ(getPendingSize(pool), 0); // When only using host, there will be no pending chunks
EXPECT_EQ(getPendingSize(pool), 0); // When only using host, there will be no pending chunks

/*
ptr = static_cast<int*>(pool.allocate(r2, 2048));
int* compare_ptr2 = ptr;

ptr = static_cast<int*>(pool.allocate(r2, 2048));
int* compare_ptr2 = ptr;

EXPECT_TRUE(r1 == r2);
EXPECT_EQ(compare_ptr1, compare_ptr2); // only 1 host resource available, no possible data race
EXPECT_TRUE(r1 == r2);
EXPECT_EQ(compare_ptr1, compare_ptr2); // only 1 host resource available, no possible data race

pool.deallocate(r2, ptr);
pool.release();
*/
pool.deallocate(r2, ptr);

}
/*

#if defined(UMPIRE_ENABLE_CUDA) || defined(UMPIRE_ENABLE_HIP)

using clock_value_t = long long;
Expand Down Expand Up @@ -158,4 +156,3 @@ TEST_P(ResourceAwarePoolTest, Check_States)
INSTANTIATE_TEST_SUITE_P(ResourceAwarePoolTests, ResourceAwarePoolTest, ::testing::ValuesIn(get_allocator_strings()));

#endif
*/

0 comments on commit d2c58d1

Please sign in to comment.