From 112393b38a472170708c176e87bc3c075109292a Mon Sep 17 00:00:00 2001 From: Brian Gianforcaro Date: Tue, 11 May 2021 03:53:38 -0700 Subject: [PATCH] Kernel: Make Thread::try_create API OOM safe --- Kernel/Thread.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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)