Skip to content

fix(memory): PoolAllocator::Allocate returns null silently on exhaustion — should assert #681

Description

@JeanPhilippeKernel

Summary

PoolAllocator::Allocate() returns nullptr silently when the pool is exhausted. No assertion, no log, no diagnostic.

Location

ZEngine/ZEngine/Core/Memory/Allocator.cpp:237-249

void* PoolAllocator::Allocate()
{
    PoolFreeNode* node = head;
    if (node == nullptr)
        return nullptr;   // silent null — no assert, no log
    ...
}

Detail

Every other failure path in the allocator system uses ZENGINE_VALIDATE_ASSERT. A pool returning null on exhaustion is a capacity-planning failure — callers that skip the null check (e.g. ZPushDynamicArray macro users) will dereference null with no diagnostic.

ArenaAllocator::Resize asserts on OOM. PoolAllocator::Allocate should be consistent.

Fix

void* PoolAllocator::Allocate()
{
    ZENGINE_VALIDATE_ASSERT(head != nullptr, "PoolAllocator::Allocate: pool exhausted — increase capacity at init");
    PoolFreeNode* node = head;
    head = head->Next;
    Helpers::secure_memset(node, 0, chunk_size, chunk_size);
    return node;
}

Impact

Medium — any caller that does not check the return value of ZPushDynamicArray / pool.Allocate() dereferences null silently in all build modes today.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions