From dd29285e356838b2326f1d2261f0a97eeded713e Mon Sep 17 00:00:00 2001 From: Feng Chen Date: Tue, 26 Oct 2021 18:12:13 +0800 Subject: [PATCH] Fix dangling kernel objects when exiting --- src/core/hle/kernel/k_process.cpp | 11 ++++++----- src/core/hle/kernel/kernel.cpp | 13 +++++++------ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/core/hle/kernel/k_process.cpp b/src/core/hle/kernel/k_process.cpp index 211157ccc6..76fd8c285c 100644 --- a/src/core/hle/kernel/k_process.cpp +++ b/src/core/hle/kernel/k_process.cpp @@ -434,11 +434,6 @@ void KProcess::PrepareForTermination() { } void KProcess::Finalize() { - // Release memory to the resource limit. - if (resource_limit != nullptr) { - resource_limit->Close(); - } - // Finalize the handle table and close any open handles. handle_table.Finalize(); @@ -460,6 +455,12 @@ void KProcess::Finalize() { } } + // Release memory to the resource limit. + if (resource_limit != nullptr) { + resource_limit->Close(); + resource_limit = nullptr; + } + // Perform inherited finalization. KAutoObjectWithSlabHeapAndContainer::Finalize(); } diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index db9f558647..4a139c5e73 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp @@ -91,12 +91,6 @@ struct KernelCore::Impl { } void Shutdown() { - // Shutdown all processes. - if (current_process) { - current_process->Finalize(); - current_process->Close(); - current_process = nullptr; - } process_list.clear(); // Close all open server ports. @@ -181,6 +175,13 @@ struct KernelCore::Impl { } } + // Shutdown all processes. + if (current_process) { + current_process->Finalize(); + current_process->Close(); + current_process = nullptr; + } + // Track kernel objects that were not freed on shutdown { std::lock_guard lk(registered_objects_lock);