Explorar el Código

Kernel: Make Thread::try_create API OOM safe

Brian Gianforcaro hace 4 años
padre
commit
112393b38a
Se han modificado 1 ficheros con 6 adiciones y 1 borrados
  1. 6 1
      Kernel/Thread.cpp

+ 6 - 1
Kernel/Thread.cpp

@@ -41,7 +41,12 @@ KResultOr<NonnullRefPtr<Thread>> Thread::try_create(NonnullRefPtr<Process> proce
     if (!kernel_stack_region)
     if (!kernel_stack_region)
         return ENOMEM;
         return ENOMEM;
     kernel_stack_region->set_stack(true);
     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> process, NonnullOwnPtr<Region> kernel_stack_region)
 Thread::Thread(NonnullRefPtr<Process> process, NonnullOwnPtr<Region> kernel_stack_region)