From 38efa2f9903998022988e7611f485a4f8e69729c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Holz?= Date: Fri, 10 Oct 2025 12:21:51 +0200 Subject: [PATCH] Kernel: Add child to scoped process list after last TRY() in posix_spawn Before this point, creating the child can still fail, so we shouldn't register it yet. Adding the child to the scoped process list now happens immediately before the process is registered by Process::register_new(). --- Kernel/Syscalls/posix_spawn.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Kernel/Syscalls/posix_spawn.cpp b/Kernel/Syscalls/posix_spawn.cpp index 8572f12bb1b..917355067d0 100644 --- a/Kernel/Syscalls/posix_spawn.cpp +++ b/Kernel/Syscalls/posix_spawn.cpp @@ -100,6 +100,11 @@ ErrorOr Process::sys$posix_spawn(Userspaceupdate_signal_mask(Thread::current()->signal_mask()); + Thread* new_main_thread = nullptr; + InterruptsState previous_interrupts_state = InterruptsState::Enabled; + TRY(child->exec(move(path), move(arguments), move(environment), new_main_thread, previous_interrupts_state)); + thread_finalizer_guard.disarm(); + m_scoped_process_list.with([&](auto const& list_ptr) { if (list_ptr) { child->m_scoped_process_list.with([&](auto& child_list_ptr) { @@ -109,11 +114,6 @@ ErrorOr Process::sys$posix_spawn(Userspaceexec(move(path), move(arguments), move(environment), new_main_thread, previous_interrupts_state)); - thread_finalizer_guard.disarm(); - Process::register_new(*child); // NOTE: All user processes have a leaked ref on them. It's balanced by Thread::WaitBlockerSet::finalize().