diff options
author | Brian Gianforcaro <bgianf@serenityos.org> | 2021-05-13 01:24:44 -0700 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-13 16:21:53 +0200 |
commit | 858fff979a2836d1b92e57ea8a0a5b21d8336245 (patch) | |
tree | 8eb3aefa4bed7f3c2bcc3edbe22bea835411e102 /Kernel/Net | |
parent | 46ce7adf7b9e0101e1f8e4cb63757cf522d1ec62 (diff) | |
download | serenity-858fff979a2836d1b92e57ea8a0a5b21d8336245.zip |
Kernel: Make IPv4Socket::create API for SOCK_RAW OOM safe
Diffstat (limited to 'Kernel/Net')
-rw-r--r-- | Kernel/Net/IPv4Socket.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Kernel/Net/IPv4Socket.cpp b/Kernel/Net/IPv4Socket.cpp index 728b4b1c37..c8ebed1ae7 100644 --- a/Kernel/Net/IPv4Socket.cpp +++ b/Kernel/Net/IPv4Socket.cpp @@ -44,8 +44,12 @@ KResultOr<NonnullRefPtr<Socket>> IPv4Socket::create(int type, int protocol) } if (type == SOCK_DGRAM) return UDPSocket::create(protocol); - if (type == SOCK_RAW) - return adopt_ref(*new IPv4Socket(type, protocol)); + if (type == SOCK_RAW) { + auto raw_socket = adopt_ref_if_nonnull(new IPv4Socket(type, protocol)); + if (raw_socket) + return raw_socket.release_nonnull(); + return ENOMEM; + } return EINVAL; } |