mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Fix issue of release of an object on empty an pool
This commit is contained in:
parent
7e266687a2
commit
7e31561363
2
.gitignore
vendored
2
.gitignore
vendored
@ -384,3 +384,5 @@ test/vs2022/Debug MSVC C++ 20 - No Tests
|
||||
test/vs2022/enc_temp_folder
|
||||
test/vs2022/Debug MSVC C++20 - No virtual messages
|
||||
examples/MutexMessageRouter/.vs
|
||||
support/time remaining test.xlsx
|
||||
test/vs2022/Debug MSVC C++20 - Force C++03
|
||||
|
||||
@ -377,23 +377,48 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void release_item(char* p_value)
|
||||
{
|
||||
//// Does it belong to us?
|
||||
//ETL_ASSERT(is_item_in_pool(p_value), ETL_ERROR(pool_object_not_in_pool));
|
||||
|
||||
//if (p_next != ETL_NULLPTR)
|
||||
//{
|
||||
// // Point it to the current free item.
|
||||
// *(uintptr_t*)p_value = reinterpret_cast<uintptr_t>(p_next);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// // This is the only free item.
|
||||
// *((uintptr_t*)p_value) = 0;
|
||||
//}
|
||||
|
||||
//p_next = p_value;
|
||||
|
||||
//--items_allocated;
|
||||
|
||||
// Does it belong to us?
|
||||
ETL_ASSERT(is_item_in_pool(p_value), ETL_ERROR(pool_object_not_in_pool));
|
||||
|
||||
if (p_next != ETL_NULLPTR)
|
||||
if (items_allocated > 0)
|
||||
{
|
||||
// Point it to the current free item.
|
||||
*(uintptr_t*)p_value = reinterpret_cast<uintptr_t>(p_next);
|
||||
if (p_next != ETL_NULLPTR)
|
||||
{
|
||||
// Point it to the current free item.
|
||||
*(uintptr_t*)p_value = reinterpret_cast<uintptr_t>(p_next);
|
||||
}
|
||||
else
|
||||
{
|
||||
// This is the only free item.
|
||||
*((uintptr_t*)p_value) = 0;
|
||||
}
|
||||
|
||||
p_next = p_value;
|
||||
|
||||
--items_allocated;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
// This is the only free item.
|
||||
*((uintptr_t*)p_value) = 0;
|
||||
ETL_ASSERT_FAIL(ETL_ERROR(pool_no_allocation));
|
||||
}
|
||||
|
||||
p_next = p_value;
|
||||
|
||||
--items_allocated;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
|
||||
@ -199,6 +199,9 @@ namespace
|
||||
|
||||
CHECK_EQUAL(4U, pool.available());
|
||||
|
||||
CHECK_THROW(pool.release(p4), etl::pool_no_allocation);
|
||||
CHECK_EQUAL(4U, pool.available());
|
||||
|
||||
Test_Data not_in_pool;
|
||||
|
||||
CHECK_THROW(pool.release(¬_in_pool), etl::pool_object_not_in_pool);
|
||||
|
||||
@ -205,6 +205,9 @@ namespace
|
||||
|
||||
CHECK_EQUAL(4U, pool.available());
|
||||
|
||||
CHECK_THROW(pool.release(p4), etl::pool_no_allocation);
|
||||
CHECK_EQUAL(4U, pool.available());
|
||||
|
||||
Test_Data not_in_pool;
|
||||
|
||||
CHECK_THROW(pool.release(¬_in_pool), etl::pool_object_not_in_pool);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user