diff --git a/Kernel/Thread.cpp b/Kernel/Thread.cpp index c1cc4711abf..8696ec8e3c6 100644 --- a/Kernel/Thread.cpp +++ b/Kernel/Thread.cpp @@ -41,7 +41,12 @@ KResultOr> Thread::try_create(NonnullRefPtr proce if (!kernel_stack_region) return ENOMEM; kernel_stack_region->set_stack(true); - return adopt_ref(*new Thread(move(process), kernel_stack_region.release_nonnull())); + + auto thread = adopt_ref_if_nonnull(new Thread(move(process), kernel_stack_region.release_nonnull())); + if (!thread) + return ENOMEM; + + return thread.release_nonnull(); } Thread::Thread(NonnullRefPtr process, NonnullOwnPtr kernel_stack_region)