aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-11-16 10:19:08 +0100
committerFelix Morgner <felix.morgner@ost.ch>2026-11-22 14:20:36 +0100
commita15cd3183c35534561644bb1f615beb824ca6817 (patch)
tree0cd05daa66da8aaedfdf52548e7bb37ab25c2aa0
parent9d14461a5fbc4493bf6c28456490194febdecb6b (diff)
downloadkernel-a15cd3183c35534561644bb1f615beb824ca6817.tar.xz
kernel-a15cd3183c35534561644bb1f615beb824ca6817.zip
kapi/memory: add a destructor to mmio_allocator
In testing, the mmio_allocator gets replaced for every scenario requiring all heap allocations to be properly cleaned up before the replacement.
-rw-r--r--kernel/kernel/memory/mmio_allocator.cpp11
-rw-r--r--kernel/kernel/memory/mmio_allocator.hpp2
2 files changed, 13 insertions, 0 deletions
diff --git a/kernel/kernel/memory/mmio_allocator.cpp b/kernel/kernel/memory/mmio_allocator.cpp
index 49cb31e9..05cf35e4 100644
--- a/kernel/kernel/memory/mmio_allocator.cpp
+++ b/kernel/kernel/memory/mmio_allocator.cpp
@@ -17,6 +17,17 @@ namespace kernel::memory
: m_head{make_node(base, pages, nullptr, nullptr, true)}
{}
+ mmio_allocator::~mmio_allocator()
+ {
+ auto current = m_head;
+ while (current)
+ {
+ auto next = current->next;
+ destroy_node(current);
+ current = next;
+ }
+ }
+
auto mmio_allocator::allocate(std::size_t count) -> kstd::result<kapi::memory::linear_address>
{
if (count == 0)
diff --git a/kernel/kernel/memory/mmio_allocator.hpp b/kernel/kernel/memory/mmio_allocator.hpp
index 268ca40b..4cb9d407 100644
--- a/kernel/kernel/memory/mmio_allocator.hpp
+++ b/kernel/kernel/memory/mmio_allocator.hpp
@@ -15,6 +15,8 @@ namespace kernel::memory
{
mmio_allocator(kapi::memory::linear_address base, std::size_t pages);
+ ~mmio_allocator();
+
[[nodiscard]] auto allocate(std::size_t page_count) -> kstd::result<kapi::memory::linear_address>;
auto release(kapi::memory::linear_address base) -> void;