summaryrefslogtreecommitdiff
path: root/Kernel/TTY/PTYMultiplexer.cpp
diff options
context:
space:
mode:
authorBrian Gianforcaro <bgianf@serenityos.org>2021-05-14 04:15:05 -0700
committerAndreas Kling <kling@serenityos.org>2021-05-15 09:01:32 +0200
commit77868abe6a69c16f6ecd9d3aeb3eff158df32a11 (patch)
treeba17d95ffdbed6ac910b1fad310aeb270a604a2f /Kernel/TTY/PTYMultiplexer.cpp
parentf3f5a225b91d7400c87b375d1fca522f2510f205 (diff)
downloadserenity-77868abe6a69c16f6ecd9d3aeb3eff158df32a11.zip
Kernel: Make PTYMultiplexer::open API OOM safe
Diffstat (limited to 'Kernel/TTY/PTYMultiplexer.cpp')
-rw-r--r--Kernel/TTY/PTYMultiplexer.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/Kernel/TTY/PTYMultiplexer.cpp b/Kernel/TTY/PTYMultiplexer.cpp
index ae19e6f8ad..be5dc9fe6c 100644
--- a/Kernel/TTY/PTYMultiplexer.cpp
+++ b/Kernel/TTY/PTYMultiplexer.cpp
@@ -40,9 +40,11 @@ KResultOr<NonnullRefPtr<FileDescription>> PTYMultiplexer::open(int options)
if (m_freelist.is_empty())
return EBUSY;
auto master_index = m_freelist.take_last();
- auto master = adopt_ref(*new MasterPTY(master_index));
+ auto master = adopt_ref_if_nonnull(new MasterPTY(master_index));
+ if (!master)
+ return ENOMEM;
dbgln_if(PTMX_DEBUG, "PTYMultiplexer::open: Vending master {}", master->index());
- auto description = FileDescription::create(move(master));
+ auto description = FileDescription::create(*master);
if (!description.is_error()) {
description.value()->set_rw_mode(options);
description.value()->set_file_flags(options);