From 6c3024d4ee8812146b4179f962b4638157b11af5 Mon Sep 17 00:00:00 2001 From: apio Date: Mon, 5 Dec 2022 21:01:06 +0100 Subject: [PATCH] Heap: Count the heap blocks' size in the size required for an allocation --- kernel/src/memory/Heap.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/src/memory/Heap.cpp b/kernel/src/memory/Heap.cpp index 5887e7dc..dc172a83 100644 --- a/kernel/src/memory/Heap.cpp +++ b/kernel/src/memory/Heap.cpp @@ -176,7 +176,7 @@ Result kmalloc(usize size) if (!heap_start) { - const usize pages = get_pages_for_allocation(size); + const usize pages = get_pages_for_allocation(size + sizeof(HeapBlock)); HeapBlock* const block = TRY(allocate_pages(pages)); block->full_size = (pages * ARCH_PAGE_SIZE) - sizeof(HeapBlock); @@ -214,7 +214,7 @@ Result kmalloc(usize size) if (!block) // No free blocks, let's allocate a new one { - usize pages = get_pages_for_allocation(size); + usize pages = get_pages_for_allocation(size + sizeof(HeapBlock)); block = TRY(allocate_pages(pages)); block->full_size = (pages * ARCH_PAGE_SIZE) - sizeof(HeapBlock);