libluna/Heap: Zero out newly created heap blocks

This commit is contained in:
apio 2023-03-07 20:45:30 +01:00
parent eaed109fe9
commit 7d045e45c1
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -105,7 +105,9 @@ static Option<HeapBlock*> split(HeapBlock* block, usize size)
const usize offset = get_fair_offset_to_split_at(block, size + sizeof(HeapBlock)); const usize offset = get_fair_offset_to_split_at(block, size + sizeof(HeapBlock));
block->full_size = offset; // shrink the old block to fit this offset block->full_size = offset; // shrink the old block to fit this offset
HeapBlock* new_block = offset_ptr(block, offset + sizeof(HeapBlock)); HeapBlock* const new_block = offset_ptr(block, offset + sizeof(HeapBlock));
memset(new_block, 0, sizeof(*new_block));
new_block->magic = BLOCK_MAGIC; new_block->magic = BLOCK_MAGIC;
new_block->status = (block->status & BLOCK_END_MEM) ? BLOCK_END_MEM : 0; new_block->status = (block->status & BLOCK_END_MEM) ? BLOCK_END_MEM : 0;
@ -212,6 +214,8 @@ Result<void*> malloc_impl(usize size, bool should_scrub)
usize pages = get_pages_for_allocation(size + sizeof(HeapBlock)); usize pages = get_pages_for_allocation(size + sizeof(HeapBlock));
HeapBlock* const current = (HeapBlock*)TRY(allocate_pages_impl(pages)); HeapBlock* const current = (HeapBlock*)TRY(allocate_pages_impl(pages));
memset(current, 0, sizeof(*current));
current->full_size = (pages * PAGE_SIZE) - sizeof(HeapBlock); current->full_size = (pages * PAGE_SIZE) - sizeof(HeapBlock);
current->magic = BLOCK_MAGIC; current->magic = BLOCK_MAGIC;
current->status = BLOCK_START_MEM | BLOCK_END_MEM; current->status = BLOCK_START_MEM | BLOCK_END_MEM;