From 318fbff1717b291c81db8f9c4d5a84019fe2b4b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Sun, 1 Dec 2024 10:21:17 +0000 Subject: Adjust allocate --- arch/x86_64/src/memory/heap/linked_list_allocator.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'arch/x86_64/src/memory') diff --git a/arch/x86_64/src/memory/heap/linked_list_allocator.cpp b/arch/x86_64/src/memory/heap/linked_list_allocator.cpp index f4ba5e2..a2a8c79 100644 --- a/arch/x86_64/src/memory/heap/linked_list_allocator.cpp +++ b/arch/x86_64/src/memory/heap/linked_list_allocator.cpp @@ -22,8 +22,8 @@ namespace teachos::arch::memory::heap auto linked_list_allocator::allocate(std::size_t size) -> void * { - memory_hole * previous = nullptr; - auto current = first; + auto & previous = first; + auto & current = first; while (current != nullptr) { if (current->size > size) @@ -32,10 +32,14 @@ namespace teachos::arch::memory::heap } else if (current->size == size) { - if (previous != nullptr) + if (previous != current) { previous->next = current->next; } + else + { + current = current->next; + } delete current; return static_cast(current); } -- cgit v1.2.3