From 37bbc04719442a18562aeffacc03a31f57466788 Mon Sep 17 00:00:00 2001 From: apio Date: Fri, 17 Feb 2023 22:47:15 +0100 Subject: [PATCH] Heap: Fix GPF caused when making many small allocations Apparently space was too tight to split(), but we did it anyways, corrupting the next block. This patch fixes this behavior. --- luna/src/Heap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/luna/src/Heap.cpp b/luna/src/Heap.cpp index 12507913..81c6c45f 100644 --- a/luna/src/Heap.cpp +++ b/luna/src/Heap.cpp @@ -99,7 +99,7 @@ static Option split(HeapBlock* block, usize size) const usize old_size = block->full_size; // Save the old value of this variable since we are going to use it after modifying it - if (available < (size + sizeof(HeapBlock))) + if (available <= (size + sizeof(HeapBlock))) return {}; // This block hasn't got enough free space to hold the requested size. const usize offset = get_fair_offset_to_split_at(block, size + sizeof(HeapBlock));