Skip to content

Commit

Permalink
Everywhere: Use nothrow new with adopt_{ref,own}_if_nonnull
Browse files Browse the repository at this point in the history
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)`.
  • Loading branch information
BertalanD authored and alimpfard committed Jun 24, 2021
1 parent 00915e8 commit f820917
Show file tree
Hide file tree
Showing 45 changed files with 64 additions and 68 deletions.
2 changes: 1 addition & 1 deletion Kernel/ACPI/MultiProcessorParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ UNMAP_AFTER_INIT OwnPtr<MultiProcessorParser> MultiProcessorParser::autodetect()
auto floating_pointer = find_floating_pointer();
if (!floating_pointer.has_value())
return {};
auto parser = adopt_own_if_nonnull(new MultiProcessorParser(floating_pointer.value()));
auto parser = adopt_own_if_nonnull(new (nothrow) MultiProcessorParser(floating_pointer.value()));
VERIFY(parser != nullptr);
return parser;
}
Expand Down
2 changes: 1 addition & 1 deletion Kernel/CoreDump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ OwnPtr<CoreDump> CoreDump::create(NonnullRefPtr<Process> process, const String&
auto fd = create_target_file(process, output_path);
if (!fd)
return {};
return adopt_own_if_nonnull(new CoreDump(move(process), fd.release_nonnull()));
return adopt_own_if_nonnull(new (nothrow) CoreDump(move(process), fd.release_nonnull()));
}

CoreDump::CoreDump(NonnullRefPtr<Process> process, NonnullRefPtr<FileDescription>&& fd)
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Devices/USB/USBDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ KResultOr<NonnullRefPtr<Device>> Device::try_create(PortNumber port, DeviceSpeed
if (pipe_or_error.is_error())
return pipe_or_error.error();

auto device = adopt_ref_if_nonnull(new Device(port, speed, pipe_or_error.release_value()));
auto device = AK::try_create<Device>(port, speed, pipe_or_error.release_value());
if (!device)
return ENOMEM;

Expand Down
2 changes: 1 addition & 1 deletion Kernel/Devices/USB/USBPipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Kernel::USB {

KResultOr<NonnullOwnPtr<Pipe>> Pipe::try_create_pipe(Type type, Direction direction, u8 endpoint_address, u16 max_packet_size, i8 device_address, u8 poll_interval)
{
auto pipe = adopt_own_if_nonnull(new Pipe(type, direction, endpoint_address, max_packet_size, device_address, poll_interval));
auto pipe = adopt_own_if_nonnull(new (nothrow) Pipe(type, direction, endpoint_address, max_packet_size, device_address, poll_interval));
if (!pipe)
return ENOMEM;

Expand Down
2 changes: 1 addition & 1 deletion Kernel/Devices/USB/USBTransfer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ RefPtr<Transfer> Transfer::try_create(Pipe& pipe, u16 len)
if (!vmobject)
return nullptr;

return adopt_ref_if_nonnull(new Transfer(pipe, len, *vmobject));
return AK::try_create<Transfer>(pipe, len, *vmobject);
}

Transfer::Transfer(Pipe& pipe, u16 len, ContiguousVMObject& vmobject)
Expand Down
2 changes: 1 addition & 1 deletion Kernel/FileSystem/AnonymousFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AnonymousFile final : public File {
public:
static RefPtr<AnonymousFile> create(NonnullRefPtr<AnonymousVMObject> vmobject)
{
return adopt_ref_if_nonnull(new AnonymousFile(move(vmobject)));
return adopt_ref_if_nonnull(new (nothrow) AnonymousFile(move(vmobject)));
}

virtual ~AnonymousFile() override;
Expand Down
2 changes: 1 addition & 1 deletion Kernel/FileSystem/Custody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ KResultOr<NonnullRefPtr<Custody>> Custody::try_create(Custody* parent, StringVie
auto name_kstring = KString::try_create(name);
if (!name_kstring)
return ENOMEM;
auto custody = adopt_ref_if_nonnull(new Custody(parent, name_kstring.release_nonnull(), inode, mount_flags));
auto custody = adopt_ref_if_nonnull(new (nothrow) Custody(parent, name_kstring.release_nonnull(), inode, mount_flags));
if (!custody)
return ENOMEM;
return custody.release_nonnull();
Expand Down
4 changes: 2 additions & 2 deletions Kernel/FileSystem/DevFS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ KResultOr<NonnullRefPtr<Inode>> DevFSRootDirectoryInode::create_child(const Stri
}
if (name != "pts")
return EROFS;
auto new_directory_inode = adopt_ref_if_nonnull(new DevFSPtsDirectoryInode(m_parent_fs));
auto new_directory_inode = adopt_ref_if_nonnull(new (nothrow) DevFSPtsDirectoryInode(m_parent_fs));
if (!new_directory_inode)
return ENOMEM;
if (!m_subfolders.try_ensure_capacity(m_subfolders.size() + 1))
Expand All @@ -291,7 +291,7 @@ KResultOr<NonnullRefPtr<Inode>> DevFSRootDirectoryInode::create_child(const Stri
if (link.name() == name)
return EEXIST;
}
auto new_link_inode = adopt_ref_if_nonnull(new DevFSLinkInode(m_parent_fs, name));
auto new_link_inode = adopt_ref_if_nonnull(new (nothrow) DevFSLinkInode(m_parent_fs, name));
if (!new_link_inode)
return ENOMEM;
if (!m_links.try_ensure_capacity(m_links.size() + 1))
Expand Down
2 changes: 1 addition & 1 deletion Kernel/FileSystem/Ext2FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1500,7 +1500,7 @@ KResultOr<Ext2FS::CachedBitmap*> Ext2FS::get_bitmap_block(BlockIndex bitmap_bloc
dbgln("Ext2FS: Failed to load bitmap block {}", bitmap_block_index);
return result;
}
auto new_bitmap = adopt_own_if_nonnull(new CachedBitmap(bitmap_block_index, move(block)));
auto new_bitmap = adopt_own_if_nonnull(new (nothrow) CachedBitmap(bitmap_block_index, move(block)));
if (!new_bitmap)
return ENOMEM;
if (!m_cached_bitmaps.try_append(move(new_bitmap)))
Expand Down
4 changes: 2 additions & 2 deletions Kernel/FileSystem/FileDescription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ KResultOr<NonnullRefPtr<FileDescription>> FileDescription::create(Custody& custo
if (inode_file.is_error())
return inode_file.error();

auto description = adopt_ref_if_nonnull(new FileDescription(*inode_file.release_value()));
auto description = adopt_ref_if_nonnull(new (nothrow) FileDescription(*inode_file.release_value()));
if (!description)
return ENOMEM;

Expand All @@ -45,7 +45,7 @@ KResultOr<NonnullRefPtr<FileDescription>> FileDescription::create(Custody& custo

KResultOr<NonnullRefPtr<FileDescription>> FileDescription::create(File& file)
{
auto description = adopt_ref_if_nonnull(new FileDescription(file));
auto description = adopt_ref_if_nonnull(new (nothrow) FileDescription(file));
if (!description)
return ENOMEM;
auto result = description->attach();
Expand Down
2 changes: 1 addition & 1 deletion Kernel/FileSystem/InodeFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class InodeFile final : public File {
public:
static KResultOr<NonnullRefPtr<InodeFile>> create(NonnullRefPtr<Inode>&& inode)
{
auto file = adopt_ref_if_nonnull(new InodeFile(move(inode)));
auto file = adopt_ref_if_nonnull(new (nothrow) InodeFile(move(inode)));
if (!file)
return ENOMEM;
return file.release_nonnull();
Expand Down
2 changes: 1 addition & 1 deletion Kernel/FileSystem/InodeWatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Kernel {

KResultOr<NonnullRefPtr<InodeWatcher>> InodeWatcher::create()
{
auto watcher = adopt_ref_if_nonnull(new InodeWatcher);
auto watcher = adopt_ref_if_nonnull(new (nothrow) InodeWatcher);
if (watcher)
return watcher.release_nonnull();
return ENOMEM;
Expand Down
2 changes: 1 addition & 1 deletion Kernel/FileSystem/InodeWatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct WatchDescription {

static KResultOr<NonnullOwnPtr<WatchDescription>> create(int wd, Inode& inode, unsigned event_mask)
{
auto description = adopt_own_if_nonnull(new WatchDescription(wd, inode, event_mask));
auto description = adopt_own_if_nonnull(new (nothrow) WatchDescription(wd, inode, event_mask));
if (description)
return description.release_nonnull();
return ENOMEM;
Expand Down
2 changes: 1 addition & 1 deletion Kernel/FileSystem/Plan9FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ KResult Plan9FS::read_and_dispatch_one_message()
auto completion = optional_completion.value();
ScopedSpinLock lock(completion->lock);
completion->result = KSuccess;
completion->message = adopt_own_if_nonnull(new Message { buffer.release_nonnull() });
completion->message = adopt_own_if_nonnull(new (nothrow) Message { buffer.release_nonnull() });
completion->completed = true;

m_completions.remove(header.tag);
Expand Down
6 changes: 3 additions & 3 deletions Kernel/FileSystem/ProcFS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ struct ProcFSInodeData : public FileDescriptionData {

RefPtr<ProcFS> ProcFS::create()
{
return adopt_ref_if_nonnull(new ProcFS);
return adopt_ref_if_nonnull(new (nothrow) ProcFS);
}

ProcFS::~ProcFS()
Expand Down Expand Up @@ -1073,7 +1073,7 @@ RefPtr<Inode> ProcFS::get_inode(InodeIdentifier inode_id) const
return adopt_ref_if_nonnull(it->value);
// We couldn't ref it, so just create a new one and replace the entry
}
auto inode = adopt_ref_if_nonnull(new ProcFSInode(const_cast<ProcFS&>(*this), inode_id.index()));
auto inode = adopt_ref_if_nonnull(new (nothrow) ProcFSInode(const_cast<ProcFS&>(*this), inode_id.index()));
if (!inode)
return {};
auto result = m_inodes.set(inode_id.index().value(), inode.ptr());
Expand Down Expand Up @@ -1163,7 +1163,7 @@ KResult ProcFSInode::refresh_data(FileDescription& description) const
}

if (!cached_data)
cached_data = adopt_own_if_nonnull(new ProcFSInodeData);
cached_data = adopt_own_if_nonnull(new (nothrow) ProcFSInodeData);
auto& buffer = static_cast<ProcFSInodeData&>(*cached_data).buffer;
if (buffer) {
// If we're reusing the buffer, reset the size to 0 first. This
Expand Down
4 changes: 2 additions & 2 deletions Kernel/FileSystem/TmpFS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Kernel {

RefPtr<TmpFS> TmpFS::create()
{
return adopt_ref_if_nonnull(new TmpFS);
return adopt_ref_if_nonnull(new (nothrow) TmpFS);
}

TmpFS::TmpFS()
Expand Down Expand Up @@ -86,7 +86,7 @@ TmpFSInode::~TmpFSInode()

RefPtr<TmpFSInode> TmpFSInode::create(TmpFS& fs, InodeMetadata metadata, InodeIdentifier parent)
{
auto inode = adopt_ref_if_nonnull(new TmpFSInode(fs, metadata, parent));
auto inode = adopt_ref_if_nonnull(new (nothrow) TmpFSInode(fs, metadata, parent));
if (inode)
fs.register_inode(*inode);
return inode;
Expand Down
8 changes: 4 additions & 4 deletions Kernel/KBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class KBufferImpl : public RefCounted<KBufferImpl> {
auto region = MM.allocate_kernel_region(page_round_up(size), name, access, strategy);
if (!region)
return nullptr;
return adopt_ref_if_nonnull(new KBufferImpl(region.release_nonnull(), size, strategy));
return adopt_ref_if_nonnull(new (nothrow) KBufferImpl(region.release_nonnull(), size, strategy));
}

static RefPtr<KBufferImpl> try_create_with_bytes(ReadonlyBytes bytes, Region::Access access, StringView name = "KBuffer", AllocationStrategy strategy = AllocationStrategy::Reserve)
Expand All @@ -42,7 +42,7 @@ class KBufferImpl : public RefCounted<KBufferImpl> {
return nullptr;
memcpy(region->vaddr().as_ptr(), bytes.data(), bytes.size());

return adopt_ref_if_nonnull(new KBufferImpl(region.release_nonnull(), bytes.size(), strategy));
return adopt_ref_if_nonnull(new (nothrow) KBufferImpl(region.release_nonnull(), bytes.size(), strategy));
}

static RefPtr<KBufferImpl> create_with_size(size_t size, Region::Access access, StringView name, AllocationStrategy strategy = AllocationStrategy::Reserve)
Expand Down Expand Up @@ -109,15 +109,15 @@ class [[nodiscard]] KBuffer {
auto impl = KBufferImpl::try_create_with_size(size, access, name, strategy);
if (!impl)
return {};
return adopt_own_if_nonnull(new KBuffer(impl.release_nonnull()));
return adopt_own_if_nonnull(new (nothrow) KBuffer(impl.release_nonnull()));
}

[[nodiscard]] static OwnPtr<KBuffer> try_create_with_bytes(ReadonlyBytes bytes, Region::Access access = Region::Access::Read | Region::Access::Write, StringView name = "KBuffer", AllocationStrategy strategy = AllocationStrategy::Reserve)
{
auto impl = KBufferImpl::try_create_with_bytes(bytes, access, name, strategy);
if (!impl)
return {};
return adopt_own_if_nonnull(new KBuffer(impl.release_nonnull()));
return adopt_own_if_nonnull(new (nothrow) KBuffer(impl.release_nonnull()));
}

[[nodiscard]] static KBuffer create_with_size(size_t size, Region::Access access = Region::Access::Read | Region::Access::Write, StringView name = "KBuffer", AllocationStrategy strategy = AllocationStrategy::Reserve)
Expand Down
2 changes: 1 addition & 1 deletion Kernel/KBufferBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ OwnPtr<KBuffer> KBufferBuilder::build()
if (!flush())
return {};

return adopt_own_if_nonnull(new KBuffer(move(m_buffer)));
return try_make<KBuffer>(move(m_buffer));
}

KBufferBuilder::KBufferBuilder(bool can_expand)
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Net/E1000ENetworkAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ UNMAP_AFTER_INIT RefPtr<E1000ENetworkAdapter> E1000ENetworkAdapter::try_to_initi
if (!is_valid_device_id(id.device_id))
return {};
u8 irq = PCI::get_interrupt_line(address);
auto adapter = adopt_ref_if_nonnull(new E1000ENetworkAdapter(address, irq));
auto adapter = adopt_ref_if_nonnull(new (nothrow) E1000ENetworkAdapter(address, irq));
if (!adapter)
return {};
if (adapter->initialize())
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Net/E1000NetworkAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ UNMAP_AFTER_INIT RefPtr<E1000NetworkAdapter> E1000NetworkAdapter::try_to_initial
if (!is_valid_device_id(id.device_id))
return {};
u8 irq = PCI::get_interrupt_line(address);
auto adapter = adopt_ref_if_nonnull(new E1000NetworkAdapter(address, irq));
auto adapter = adopt_ref_if_nonnull(new (nothrow) E1000NetworkAdapter(address, irq));
if (!adapter)
return {};
if (adapter->initialize())
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Net/IPv4Socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ KResultOr<NonnullRefPtr<Socket>> IPv4Socket::create(int type, int protocol)
return udp_socket.release_value();
}
if (type == SOCK_RAW) {
auto raw_socket = adopt_ref_if_nonnull(new IPv4Socket(type, protocol));
auto raw_socket = adopt_ref_if_nonnull(new (nothrow) IPv4Socket(type, protocol));
if (raw_socket)
return raw_socket.release_nonnull();
return ENOMEM;
Expand Down
4 changes: 2 additions & 2 deletions Kernel/Net/LocalSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ void LocalSocket::for_each(Function<void(const LocalSocket&)> callback)

KResultOr<NonnullRefPtr<Socket>> LocalSocket::create(int type)
{
auto socket = adopt_ref_if_nonnull(new LocalSocket(type));
auto socket = adopt_ref_if_nonnull(new (nothrow) LocalSocket(type));
if (socket)
return socket.release_nonnull();
return ENOMEM;
}

KResultOr<SocketPair> LocalSocket::create_connected_pair(int type)
{
auto socket = adopt_ref_if_nonnull(new LocalSocket(type));
auto socket = adopt_ref_if_nonnull(new (nothrow) LocalSocket(type));
if (!socket)
return ENOMEM;

Expand Down
2 changes: 1 addition & 1 deletion Kernel/Net/NE2000NetworkAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ UNMAP_AFTER_INIT RefPtr<NE2000NetworkAdapter> NE2000NetworkAdapter::try_to_initi
if (!ne2k_ids.span().contains_slow(id))
return {};
u8 irq = PCI::get_interrupt_line(address);
return adopt_ref_if_nonnull(new NE2000NetworkAdapter(address, irq));
return adopt_ref_if_nonnull(new (nothrow) NE2000NetworkAdapter(address, irq));
}

UNMAP_AFTER_INIT NE2000NetworkAdapter::NE2000NetworkAdapter(PCI::Address address, u8 irq)
Expand Down
4 changes: 2 additions & 2 deletions Kernel/Net/NetworkAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ RefPtr<PacketWithTimestamp> NetworkAdapter::acquire_packet_buffer(size_t size)
InterruptDisabler disabler;
if (m_unused_packets.is_empty()) {
auto buffer = KBuffer::create_with_size(size, Region::Access::Read | Region::Access::Write, "Packet Buffer", AllocationStrategy::AllocateNow);
auto packet = adopt_ref_if_nonnull(new PacketWithTimestamp { move(buffer), kgettimeofday() });
auto packet = adopt_ref_if_nonnull(new (nothrow) PacketWithTimestamp { move(buffer), kgettimeofday() });
if (!packet)
return nullptr;
packet->buffer.set_size(size);
Expand All @@ -133,7 +133,7 @@ RefPtr<PacketWithTimestamp> NetworkAdapter::acquire_packet_buffer(size_t size)
}

auto buffer = KBuffer::create_with_size(size, Region::Access::Read | Region::Access::Write, "Packet Buffer", AllocationStrategy::AllocateNow);
packet = adopt_ref_if_nonnull(new PacketWithTimestamp { move(buffer), kgettimeofday() });
packet = adopt_ref_if_nonnull(new (nothrow) PacketWithTimestamp { move(buffer), kgettimeofday() });
if (!packet)
return nullptr;
packet->buffer.set_size(size);
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Net/RTL8139NetworkAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ UNMAP_AFTER_INIT RefPtr<RTL8139NetworkAdapter> RTL8139NetworkAdapter::try_to_ini
if (id != rtl8139_id)
return {};
u8 irq = PCI::get_interrupt_line(address);
return adopt_ref_if_nonnull(new RTL8139NetworkAdapter(address, irq));
return adopt_ref_if_nonnull(new (nothrow) RTL8139NetworkAdapter(address, irq));
}

UNMAP_AFTER_INIT RTL8139NetworkAdapter::RTL8139NetworkAdapter(PCI::Address address, u8 irq)
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Net/RTL8168NetworkAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ UNMAP_AFTER_INIT RefPtr<RTL8168NetworkAdapter> RTL8168NetworkAdapter::try_to_ini
if (id.device_id != 0x8168)
return {};
u8 irq = PCI::get_interrupt_line(address);
return adopt_ref_if_nonnull(new RTL8168NetworkAdapter(address, irq));
return adopt_ref_if_nonnull(new (nothrow) RTL8168NetworkAdapter(address, irq));
}

UNMAP_AFTER_INIT RTL8168NetworkAdapter::RTL8168NetworkAdapter(PCI::Address address, u8 irq)
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Net/TCPSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ TCPSocket::~TCPSocket()

KResultOr<NonnullRefPtr<TCPSocket>> TCPSocket::create(int protocol)
{
auto socket = adopt_ref_if_nonnull(new TCPSocket(protocol));
auto socket = adopt_ref_if_nonnull(new (nothrow) TCPSocket(protocol));
if (socket)
return socket.release_nonnull();
return ENOMEM;
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Net/UDPSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ UDPSocket::~UDPSocket()

KResultOr<NonnullRefPtr<UDPSocket>> UDPSocket::create(int protocol)
{
auto socket = adopt_ref_if_nonnull(new UDPSocket(protocol));
auto socket = adopt_ref_if_nonnull(new (nothrow) UDPSocket(protocol));
if (socket)
return socket.release_nonnull();
return ENOMEM;
Expand Down
2 changes: 1 addition & 1 deletion Kernel/PerformanceEventBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ OwnPtr<PerformanceEventBuffer> PerformanceEventBuffer::try_create_with_size(size
auto buffer = KBuffer::try_create_with_size(buffer_size, Region::Access::Read | Region::Access::Write, "Performance events", AllocationStrategy::AllocateNow);
if (!buffer)
return {};
return adopt_own_if_nonnull(new PerformanceEventBuffer(buffer.release_nonnull()));
return adopt_own_if_nonnull(new (nothrow) PerformanceEventBuffer(buffer.release_nonnull()));
}

void PerformanceEventBuffer::add_process(const Process& process, ProcessEventType event_type)
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ void Process::unprotect_data()

RefPtr<Process> Process::create(RefPtr<Thread>& first_thread, const String& name, uid_t uid, gid_t gid, ProcessID ppid, bool is_kernel_process, RefPtr<Custody> cwd, RefPtr<Custody> executable, TTY* tty, Process* fork_parent)
{
auto process = adopt_ref_if_nonnull(new Process(name, uid, gid, ppid, is_kernel_process, move(cwd), move(executable), tty));
auto process = adopt_ref_if_nonnull(new (nothrow) Process(name, uid, gid, ppid, is_kernel_process, move(cwd), move(executable), tty));
if (!process)
return {};
auto result = process->attach_resources(first_thread, fork_parent);
Expand Down
2 changes: 1 addition & 1 deletion Kernel/ProcessGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ProcessGroup::~ProcessGroup()

RefPtr<ProcessGroup> ProcessGroup::create(ProcessGroupID pgid)
{
auto process_group = adopt_ref_if_nonnull(new ProcessGroup(pgid));
auto process_group = adopt_ref_if_nonnull(new (nothrow) ProcessGroup(pgid));
if (process_group) {
ScopedSpinLock lock(g_process_groups_lock);
g_process_groups->prepend(*process_group);
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Syscalls/alarm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ KResultOr<unsigned> Process::sys$alarm(unsigned seconds)
auto deadline = TimeManagement::the().current_time(CLOCK_REALTIME_COARSE);
deadline = deadline + Time::from_seconds(seconds);
if (!m_alarm_timer) {
m_alarm_timer = adopt_ref_if_nonnull(new Timer());
m_alarm_timer = adopt_ref_if_nonnull(new (nothrow) Timer());
if (!m_alarm_timer)
return ENOMEM;
}
Expand Down
4 changes: 2 additions & 2 deletions Kernel/Syscalls/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ KResultOr<int> Process::sys$module_load(Userspace<const char*> user_path, size_t
auto storage = KBuffer::create_with_size(payload.size());
memcpy(storage.data(), payload.data(), payload.size());

auto elf_image = adopt_own_if_nonnull(new ELF::Image(storage.data(), storage.size()));
auto elf_image = try_make<ELF::Image>(storage.data(), storage.size());
if (!elf_image)
return ENOMEM;
if (!elf_image->parse())
return ENOEXEC;

HashMap<String, u8*> section_storage_by_name;

auto module = adopt_own_if_nonnull(new Module());
auto module = try_make<Module>();
if (!module)
return ENOMEM;

Expand Down
Loading

0 comments on commit f820917

Please sign in to comment.