diff options
author | Brian Gianforcaro <bgianf@serenityos.org> | 2021-05-28 05:41:05 -0700 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-06-01 23:14:40 +0100 |
commit | 23c021912e3e550400d862de93cc152d5818a653 (patch) | |
tree | 2fc4c21fb56f833825886abb26e2dc30b1c13fd2 /Kernel/FileSystem/TmpFS.cpp | |
parent | 8f9872581b94761fe217b72add803f23dc27f571 (diff) | |
download | serenity-23c021912e3e550400d862de93cc152d5818a653.zip |
Kernel: Move TmpFS towards OOM safety
Diffstat (limited to 'Kernel/FileSystem/TmpFS.cpp')
-rw-r--r-- | Kernel/FileSystem/TmpFS.cpp | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/Kernel/FileSystem/TmpFS.cpp b/Kernel/FileSystem/TmpFS.cpp index e56e310207..08cfb261bc 100644 --- a/Kernel/FileSystem/TmpFS.cpp +++ b/Kernel/FileSystem/TmpFS.cpp @@ -11,9 +11,9 @@ namespace Kernel { -NonnullRefPtr<TmpFS> TmpFS::create() +RefPtr<TmpFS> TmpFS::create() { - return adopt_ref(*new TmpFS); + return adopt_ref_if_nonnull(new TmpFS); } TmpFS::TmpFS() @@ -27,7 +27,7 @@ TmpFS::~TmpFS() bool TmpFS::initialize() { m_root_inode = TmpFSInode::create_root(*this); - return true; + return !m_root_inode.is_null(); } NonnullRefPtr<Inode> TmpFS::root_inode() const @@ -84,14 +84,15 @@ TmpFSInode::~TmpFSInode() { } -NonnullRefPtr<TmpFSInode> TmpFSInode::create(TmpFS& fs, InodeMetadata metadata, InodeIdentifier parent) +RefPtr<TmpFSInode> TmpFSInode::create(TmpFS& fs, InodeMetadata metadata, InodeIdentifier parent) { - auto inode = adopt_ref(*new TmpFSInode(fs, metadata, parent)); - fs.register_inode(inode); + auto inode = adopt_ref_if_nonnull(new TmpFSInode(fs, metadata, parent)); + if (inode) + fs.register_inode(*inode); return inode; } -NonnullRefPtr<TmpFSInode> TmpFSInode::create_root(TmpFS& fs) +RefPtr<TmpFSInode> TmpFSInode::create_root(TmpFS& fs) { InodeMetadata metadata; auto now = kgettimeofday().to_truncated_seconds(); @@ -270,10 +271,12 @@ KResultOr<NonnullRefPtr<Inode>> TmpFSInode::create_child(const String& name, mod metadata.mtime = now; auto child = TmpFSInode::create(fs(), metadata, identifier()); - auto result = add_child(child, name, mode); + if (!child) + return ENOMEM; + auto result = add_child(*child, name, mode); if (result.is_error()) return result; - return child; + return child.release_nonnull(); } KResult TmpFSInode::add_child(Inode& child, const StringView& name, mode_t) |