diff --git a/Kernel/Net/IPv4Socket.cpp b/Kernel/Net/IPv4Socket.cpp index 122ddfa4fc..d2488aab17 100644 --- a/Kernel/Net/IPv4Socket.cpp +++ b/Kernel/Net/IPv4Socket.cpp @@ -53,10 +53,10 @@ KResultOr> IPv4Socket::create(int type, int protocol) return tcp_socket_or_error.release_value(); } if (type == SOCK_DGRAM) { - auto udp_socket = UDPSocket::create(protocol, receive_buffer.release_nonnull()); - if (udp_socket.is_error()) - return udp_socket.error(); - return udp_socket.release_value(); + auto udp_socket_or_error = UDPSocket::try_create(protocol, receive_buffer.release_nonnull()); + if (udp_socket_or_error.is_error()) + return udp_socket_or_error.error(); + return udp_socket_or_error.release_value(); } if (type == SOCK_RAW) { auto raw_socket = adopt_ref_if_nonnull(new (nothrow) IPv4Socket(type, protocol, receive_buffer.release_nonnull(), {})); diff --git a/Kernel/Net/UDPSocket.cpp b/Kernel/Net/UDPSocket.cpp index 372d0f6bfe..ef8878ad0a 100644 --- a/Kernel/Net/UDPSocket.cpp +++ b/Kernel/Net/UDPSocket.cpp @@ -54,12 +54,9 @@ UDPSocket::~UDPSocket() }); } -KResultOr> UDPSocket::create(int protocol, NonnullOwnPtr receive_buffer) +KResultOr> UDPSocket::try_create(int protocol, NonnullOwnPtr receive_buffer) { - auto socket = adopt_ref_if_nonnull(new (nothrow) UDPSocket(protocol, move(receive_buffer))); - if (socket) - return socket.release_nonnull(); - return ENOMEM; + return adopt_nonnull_ref_or_enomem(new (nothrow) UDPSocket(protocol, move(receive_buffer))); } KResultOr UDPSocket::protocol_receive(ReadonlyBytes raw_ipv4_packet, UserOrKernelBuffer& buffer, size_t buffer_size, [[maybe_unused]] int flags) diff --git a/Kernel/Net/UDPSocket.h b/Kernel/Net/UDPSocket.h index 58d011c33c..0720a5a8f1 100644 --- a/Kernel/Net/UDPSocket.h +++ b/Kernel/Net/UDPSocket.h @@ -14,7 +14,7 @@ namespace Kernel { class UDPSocket final : public IPv4Socket { public: - static KResultOr> create(int protocol, NonnullOwnPtr receive_buffer); + static KResultOr> try_create(int protocol, NonnullOwnPtr receive_buffer); virtual ~UDPSocket() override; static SocketHandle from_port(u16);