mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:28:12 +00:00
Kernel: Leak a ref() on the new Process ASAP in sys$fork()
This fixes an issue where failing the fork due to OOM or other error, we'd end up destroying the Process too early. By the time we got to WaitBlockerSet::finalize(), it was long gone.
This commit is contained in:
parent
ec4b83326b
commit
ae8f1c7dc8
1 changed files with 4 additions and 3 deletions
|
@ -29,6 +29,10 @@ ErrorOr<FlatPtr> 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<void> {
|
||||
return child->m_unveil_data.with([&](auto& child_unveil_data) -> ErrorOr<void> {
|
||||
child_unveil_data.state = parent_unveil_data.state;
|
||||
|
@ -143,9 +147,6 @@ ErrorOr<FlatPtr> 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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue