Arena reserved size should always add ARENA_HEADER_SIZE #709
+2
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When allocating memory with the arena the reserve size should always incorporate the size of the arena header. Otherwise, it can fail badly in
arena_push().In
arena_push()on line 101 when checking if a existing free block exists the reserved size of the block is checked to see if the allocation will fit into the free block:if(new_block->res >= AlignPow2(new_block->pos, align) + size).Little bit further down the
pos_pstgets adjusted for the new free block:post_prewill always be at leastARENA_HEADER_SIZEbig.This means the allocation will eventually not fit. The condition
assert(pos_pst < current->res);always needs to be true. But currently that is not necessary the case.Note: When allocating new blocks in
arena_push()theARENA_HEADER_SIZEalways gets added to the reserved size as it should be.