diff --git a/kernel/src/memory/Heap.cpp b/kernel/src/memory/Heap.cpp index e7dba4f2..f47fd530 100644 --- a/kernel/src/memory/Heap.cpp +++ b/kernel/src/memory/Heap.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -36,7 +37,9 @@ static DoublyLinkedList heap; static Result allocate_pages(usize count) { u64 virt = TRY(KernelVM::alloc_several_pages(count)); + auto vm_guard = make_scope_guard([&] { KernelVM::free_several_pages(virt, count).value(); }); void* const ptr = (void*)TRY(MemoryManager::alloc_at(virt, count, MMU::ReadWrite | MMU::NoExecute)); + vm_guard.deactivate(); return (HeapBlock*)ptr; } diff --git a/kernel/src/thread/Scheduler.cpp b/kernel/src/thread/Scheduler.cpp index a6b91f90..2413f37b 100644 --- a/kernel/src/thread/Scheduler.cpp +++ b/kernel/src/thread/Scheduler.cpp @@ -51,7 +51,7 @@ namespace Scheduler auto thread_guard = make_scope_guard([&] { delete thread; }); u64 thread_stack_vm = TRY(KernelVM::alloc_several_pages(4)); - auto vm_guard = make_scope_guard([&] { KernelVM::free_several_pages(thread_stack_vm, 4); }); + auto vm_guard = make_scope_guard([&] { KernelVM::free_several_pages(thread_stack_vm, 4).value(); }); TRY(MemoryManager::alloc_at(thread_stack_vm, 4, MMU::NoExecute | MMU::ReadWrite));