From 264eff3ad07d6e68d0142fa10914529425e9be6b Mon Sep 17 00:00:00 2001 From: Bananymous Date: Sun, 25 Feb 2024 21:33:30 +0200 Subject: [PATCH] Kernel: Cleanup kmalloc VirtualRange creation --- kernel/kernel/Memory/VirtualRange.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/kernel/kernel/Memory/VirtualRange.cpp b/kernel/kernel/Memory/VirtualRange.cpp index 6c8a7417..80221b97 100644 --- a/kernel/kernel/Memory/VirtualRange.cpp +++ b/kernel/kernel/Memory/VirtualRange.cpp @@ -74,21 +74,18 @@ namespace Kernel BAN::ErrorOr> VirtualRange::create_kmalloc(size_t size) { - VirtualRange* result = new VirtualRange(PageTable::kernel(), false, true); - ASSERT(result); + auto* result_ptr = new VirtualRange(PageTable::kernel(), false, true); + if (!result_ptr) + return BAN::Error::from_errno(ENOMEM); + auto result = BAN::UniqPtr::adopt(result_ptr); result->m_size = size; result->m_flags = PageTable::Flags::ReadWrite | PageTable::Flags::Present; result->m_vaddr = (vaddr_t)kmalloc(size); if (result->m_vaddr == 0) - { - delete result; return BAN::Error::from_errno(ENOMEM); - } - result->set_zero(); - - return BAN::UniqPtr::adopt(result); + return result; } VirtualRange::VirtualRange(PageTable& page_table, bool preallocated, bool kmalloc)