Fixed bug in mem_arena_alloc when selecting chunk from which to allocate

This commit is contained in:
martinfouilleul 2023-06-19 17:09:31 +02:00
parent 2fe683b79d
commit d9a9215fa8
1 changed files with 10 additions and 3 deletions

View File

@ -75,11 +75,18 @@ void* mem_arena_alloc(mem_arena* arena, u64 size)
u64 nextOffset = chunk->offset + size; u64 nextOffset = chunk->offset + size;
u64 lastCap = chunk->cap; u64 lastCap = chunk->cap;
while(chunk && nextOffset > chunk->cap) while(nextOffset > chunk->cap)
{ {
chunk = list_next_entry(&arena->chunks, chunk, mem_arena_chunk, listElt); chunk = list_next_entry(&arena->chunks, chunk, mem_arena_chunk, listElt);
nextOffset = chunk->offset + size; if(chunk)
lastCap = chunk->cap; {
nextOffset = chunk->offset + size;
lastCap = chunk->cap;
}
else
{
break;
}
} }
if(!chunk) if(!chunk)
{ {