Fix issue of release of an object on empty an pool

This commit is contained in:
John Wellbelove 2023-08-25 10:32:25 +01:00
parent 7e266687a2
commit 7e31561363
4 changed files with 43 additions and 10 deletions

2
.gitignore vendored
View File

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

View File

@ -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;
}
//*************************************************************************

View File

@ -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(&not_in_pool), etl::pool_object_not_in_pool);

View File

@ -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(&not_in_pool), etl::pool_object_not_in_pool);