diff --git a/Kernel/Syscalls/fork.cpp b/Kernel/Syscalls/fork.cpp index 1c701728d3..3194db0967 100644 --- a/Kernel/Syscalls/fork.cpp +++ b/Kernel/Syscalls/fork.cpp @@ -29,6 +29,10 @@ ErrorOr Process::sys$fork(RegisterState& regs) auto child_name = TRY(m_name->try_clone()); auto child = TRY(Process::try_create(child_first_thread, move(child_name), uid(), gid(), pid(), m_is_kernel_process, current_directory(), m_executable, m_tty, this)); + + // NOTE: All user processes have a leaked ref on them. It's balanced by Thread::WaitBlockerSet::finalize(). + child->ref(); + TRY(m_unveil_data.with([&](auto& parent_unveil_data) -> ErrorOr { return child->m_unveil_data.with([&](auto& child_unveil_data) -> ErrorOr { child_unveil_data.state = parent_unveil_data.state; @@ -143,9 +147,6 @@ ErrorOr Process::sys$fork(RegisterState& regs) auto child_pid = child->pid().value(); - // NOTE: All user processes have a leaked ref on them. It's balanced by Thread::WaitBlockerSet::finalize(). - (void)child.leak_ref(); - return child_pid; }