Heap: Avoid accessing a block after it's potentially deleted
All checks were successful
continuous-integration/drone/pr Build is passing

This commit is contained in:
apio 2023-02-14 20:17:31 +01:00
parent 08d5d727ee
commit 4697a16206
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -130,6 +130,8 @@ static Result<void> combine_forward(HeapBlock* block)
heap.remove(next); heap.remove(next);
next->magic = BLOCK_DEAD; next->magic = BLOCK_DEAD;
block->full_size += next->full_size + sizeof(HeapBlock);
if (next->status & BLOCK_END_MEM) if (next->status & BLOCK_END_MEM)
{ {
if (next->status & BLOCK_START_MEM) if (next->status & BLOCK_START_MEM)
@ -142,8 +144,6 @@ static Result<void> combine_forward(HeapBlock* block)
block->status |= BLOCK_END_MEM; block->status |= BLOCK_END_MEM;
} }
block->full_size += next->full_size + sizeof(HeapBlock);
return {}; return {};
} }
@ -159,6 +159,8 @@ static Result<HeapBlock*> combine_backward(HeapBlock* block)
heap.remove(block); heap.remove(block);
block->magic = BLOCK_DEAD; block->magic = BLOCK_DEAD;
last->full_size += block->full_size + sizeof(HeapBlock);
if (block->status & BLOCK_END_MEM) if (block->status & BLOCK_END_MEM)
{ {
if (block->status & BLOCK_START_MEM) if (block->status & BLOCK_START_MEM)
@ -171,8 +173,6 @@ static Result<HeapBlock*> combine_backward(HeapBlock* block)
last->status |= BLOCK_END_MEM; last->status |= BLOCK_END_MEM;
} }
last->full_size += block->full_size + sizeof(HeapBlock);
return last; return last;
} }