From ae0cd155c3e2266ac668b7358f06a8cab0a9fa24 Mon Sep 17 00:00:00 2001 From: apio Date: Sun, 9 Jul 2023 20:43:03 +0200 Subject: [PATCH] kernel: Fix AddressSpace's move assignment operator --- kernel/src/memory/AddressSpace.cpp | 7 +++++-- libluna/include/luna/LinkedList.h | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/kernel/src/memory/AddressSpace.cpp b/kernel/src/memory/AddressSpace.cpp index d750c766..a485c627 100644 --- a/kernel/src/memory/AddressSpace.cpp +++ b/kernel/src/memory/AddressSpace.cpp @@ -70,11 +70,14 @@ AddressSpace& AddressSpace::operator=(AddressSpace&& other) if (&other == this) return *this; m_regions.consume([](VMRegion* region) { delete region; }); - MMU::delete_userspace_page_directory(m_directory); + if (m_directory) MMU::delete_userspace_page_directory(m_directory); m_regions = other.m_regions; m_directory = other.m_directory; + other.m_regions.reset(); + other.m_directory = nullptr; + return *this; } @@ -215,5 +218,5 @@ Result AddressSpace::split_region(VMRegion* parent, u64 boundary) AddressSpace::~AddressSpace() { m_regions.consume([](VMRegion* region) { delete region; }); - MMU::delete_userspace_page_directory(m_directory); + if (m_directory) MMU::delete_userspace_page_directory(m_directory); } diff --git a/libluna/include/luna/LinkedList.h b/libluna/include/luna/LinkedList.h index 2a2ce167..2e6d6a7a 100644 --- a/libluna/include/luna/LinkedList.h +++ b/libluna/include/luna/LinkedList.h @@ -251,6 +251,12 @@ template class LinkedList return { nullptr, *this }; } + void reset() + { + m_start_node = m_end_node = nullptr; + m_count = 0; + } + private: Node* m_start_node = nullptr; Node* m_end_node = nullptr;