Skip to content

Fix PoolAllocator crash on first allocation - #36

Merged
mtrebi merged 2 commits into
mtrebi:masterfrom
Tidenflow:fix/pool-empty-pop
Sep 21, 2026
Merged

mtrebi merged 2 commits into
mtrebi:masterfrom
Tidenflow:fix/pool-empty-pop

Conversation

@Tidenflow

Copy link
Copy Markdown
Contributor

Summary

  • Initialize StackLinkedList::head to nullptr.
  • Return nullptr when StackLinkedList::pop() is called on an empty list.
  • Return a successful exit code after all benchmarks complete.

Problem

After the PoolAllocator initialization was changed to use offset-based lazy allocation, its free list can be empty during the first allocation.

PoolAllocator::Allocate() expects pop() to return nullptr in that case, but StackLinkedList::pop() dereferences head unconditionally. This causes an access violation before the allocator can fall back to allocating a new chunk using the offset.

Verification

Built and ran the project with MinGW on Windows:

cmake -S . -B build -G "MinGW Makefiles"
cmake --build build
build\main.exe

Initialize the intrusive free-list head and return nullptr when no recycled pool chunks are available, preserving lazy O(1) pool initialization.
Return zero after every allocator benchmark completes successfully.
@mtrebi
mtrebi merged commit ad599a3 into mtrebi:master Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants