1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-01 06:22:08 +00:00

Everywhere: Use nothrow new with adopt_{ref,own}_if_nonnull

This commit converts naked `new`s to `AK::try_make` and `AK::try_create`
wherever possible. If the called constructor is private, this can not be
done, so we instead now use the standard-defined and compiler-agnostic
`new (nothrow)`.
This commit is contained in:
Daniel Bertalan 2021-06-20 10:21:16 +02:00 committed by Ali Mohammad Pur
parent 00915e8948
commit f820917a76
45 changed files with 64 additions and 68 deletions

View file

@ -43,11 +43,11 @@ KResultOr<NonnullRefPtr<Thread>> Thread::try_create(NonnullRefPtr<Process> proce
return ENOMEM;
kernel_stack_region->set_stack(true);
auto block_timer = adopt_ref_if_nonnull(new Timer());
auto block_timer = AK::try_create<Timer>();
if (!block_timer)
return ENOMEM;
auto thread = adopt_ref_if_nonnull(new Thread(move(process), kernel_stack_region.release_nonnull(), block_timer.release_nonnull()));
auto thread = adopt_ref_if_nonnull(new (nothrow) Thread(move(process), kernel_stack_region.release_nonnull(), block_timer.release_nonnull()));
if (!thread)
return ENOMEM;