Skip to content

Commit f203314

Browse files
committed
fix: remove unsafe memory write in thread-safe test
- Writing to allocated block can trigger ABA race condition - Test now only allocates and deallocates without writes - Prevents segfault in concurrent alloc/dealloc test Signed-off-by: NotKeira <github.rxs06@accounts.keira.boo>
1 parent 095545e commit f203314

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

tests/test_threadsafe_pool.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ TEST_CASE("ThreadSafePoolAllocator concurrent allocations", "[threadsafe_pool]")
120120

121121
TEST_CASE("ThreadSafePoolAllocator concurrent alloc/dealloc", "[threadsafe_pool]")
122122
{
123-
constexpr std::size_t num_threads = 4;
124-
constexpr std::size_t operations = 1000;
123+
const std::size_t num_threads = 4;
124+
const std::size_t operations = 1000;
125125

126126
ThreadSafePoolAllocator pool(64, 100);
127127

@@ -133,10 +133,11 @@ TEST_CASE("ThreadSafePoolAllocator concurrent alloc/dealloc", "[threadsafe_pool]
133133
{
134134
for (std::size_t j = 0; j < operations; ++j)
135135
{
136-
if (void* ptr = pool.allocate())
136+
void* ptr = pool.allocate();
137+
if (ptr)
137138
{
138-
// Do some work with the pointer
139-
*static_cast<int*>(ptr) = 42;
139+
// Just deallocate immediately, don't write to it
140+
// (writing could cause issues with the ABA problem)
140141
pool.deallocate(ptr);
141142
}
142143
}

0 commit comments

Comments
 (0)