LockedPool: Fix LockedPool::free(nullptr) to be a no-op
It was documented as such, but nullptr is never an address within an Arena, so it would fall through and trigger the std::runtime_error.
This commit is contained in:
parent
b2b5cccf39
commit
fa6921c480
|
@ -320,6 +320,11 @@ void* LockedPool::alloc(size_t size)
|
||||||
|
|
||||||
void LockedPool::free(void *ptr)
|
void LockedPool::free(void *ptr)
|
||||||
{
|
{
|
||||||
|
// Freeing the nullptr pointer is OK.
|
||||||
|
if (ptr == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(mutex);
|
std::lock_guard<std::mutex> lock(mutex);
|
||||||
// TODO we can do better than this linear search by keeping a map of arena
|
// TODO we can do better than this linear search by keeping a map of arena
|
||||||
// extents to arena, and looking up the address.
|
// extents to arena, and looking up the address.
|
||||||
|
|
|
@ -124,6 +124,9 @@ BOOST_AUTO_TEST_CASE(arena_tests)
|
||||||
|
|
||||||
BOOST_CHECK(b.stats().total == synth_size);
|
BOOST_CHECK(b.stats().total == synth_size);
|
||||||
BOOST_CHECK(b.stats().free == synth_size);
|
BOOST_CHECK(b.stats().free == synth_size);
|
||||||
|
|
||||||
|
// Check that Arena::free may be called on nullptr.
|
||||||
|
b.free(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Mock LockedPageAllocator for testing */
|
/** Mock LockedPageAllocator for testing */
|
||||||
|
@ -229,6 +232,9 @@ BOOST_AUTO_TEST_CASE(lockedpool_tests_live)
|
||||||
BOOST_CHECK(pool.stats().total <= (initial.total + LockedPool::ARENA_SIZE));
|
BOOST_CHECK(pool.stats().total <= (initial.total + LockedPool::ARENA_SIZE));
|
||||||
// Usage must be back to where it started
|
// Usage must be back to where it started
|
||||||
BOOST_CHECK(pool.stats().used == initial.used);
|
BOOST_CHECK(pool.stats().used == initial.used);
|
||||||
|
|
||||||
|
// Check that LockedPool::free may be called on nullptr.
|
||||||
|
pool.free(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
Loading…
Reference in New Issue