diff options
author | Brian Gianforcaro <bgianf@serenityos.org> | 2021-05-14 04:15:05 -0700 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-15 09:01:32 +0200 |
commit | 77868abe6a69c16f6ecd9d3aeb3eff158df32a11 (patch) | |
tree | ba17d95ffdbed6ac910b1fad310aeb270a604a2f /Kernel/TTY/PTYMultiplexer.cpp | |
parent | f3f5a225b91d7400c87b375d1fca522f2510f205 (diff) | |
download | serenity-77868abe6a69c16f6ecd9d3aeb3eff158df32a11.zip |
Kernel: Make PTYMultiplexer::open API OOM safe
Diffstat (limited to 'Kernel/TTY/PTYMultiplexer.cpp')
-rw-r--r-- | Kernel/TTY/PTYMultiplexer.cpp | 6 |
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); |