summaryrefslogtreecommitdiff
path: root/Kernel/Net/LocalSocket.cpp
diff options
context:
space:
mode:
authorBrian Gianforcaro <bgianf@serenityos.org>2021-05-13 00:06:09 -0700
committerAndreas Kling <kling@serenityos.org>2021-05-13 16:21:53 +0200
commit9375f3dc094fda351a7bb5bc6f78438b73beffdb (patch)
treef39122cd8cba5561756b52e88b839297c767f592 /Kernel/Net/LocalSocket.cpp
parent51ceb172b9a87da7b6477e202d47c9c9316dc408 (diff)
downloadserenity-9375f3dc094fda351a7bb5bc6f78438b73beffdb.zip
Kernel: Make LocalSocket factory APIs OOM safe
Diffstat (limited to 'Kernel/Net/LocalSocket.cpp')
-rw-r--r--Kernel/Net/LocalSocket.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/Kernel/Net/LocalSocket.cpp b/Kernel/Net/LocalSocket.cpp
index 5a38760c68..fe06dfe78c 100644
--- a/Kernel/Net/LocalSocket.cpp
+++ b/Kernel/Net/LocalSocket.cpp
@@ -33,12 +33,17 @@ void LocalSocket::for_each(Function<void(const LocalSocket&)> callback)
KResultOr<NonnullRefPtr<Socket>> LocalSocket::create(int type)
{
- return adopt_ref(*new LocalSocket(type));
+ auto socket = adopt_ref_if_nonnull(new LocalSocket(type));
+ if (socket)
+ return socket.release_nonnull();
+ return ENOMEM;
}
KResultOr<SocketPair> LocalSocket::create_connected_pair(int type)
{
- auto socket = adopt_ref(*new LocalSocket(type));
+ auto socket = adopt_ref_if_nonnull(new LocalSocket(type));
+ if (!socket)
+ return ENOMEM;
auto description1_result = FileDescription::create(*socket);
if (description1_result.is_error())