summaryrefslogtreecommitdiff
path: root/Kernel/VM
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-07-11 17:52:07 +0200
committerAndreas Kling <kling@serenityos.org>2021-07-11 17:52:07 +0200
commitaf8c74a328b80b09a6e948ab2e9dc4e54ad91cec (patch)
treed8813fb6bf5a9cfe524f6208f9085b021cf0ec3a /Kernel/VM
parent59049ae4b760ae0f5cdad0d326eeaca9d2192fb9 (diff)
downloadserenity-af8c74a328b80b09a6e948ab2e9dc4e54ad91cec.zip
Kernel: Make SharedInodeVMObject allocation OOM-safe
Diffstat (limited to 'Kernel/VM')
-rw-r--r--Kernel/VM/SharedInodeVMObject.cpp6
-rw-r--r--Kernel/VM/SharedInodeVMObject.h2
2 files changed, 5 insertions, 3 deletions
diff --git a/Kernel/VM/SharedInodeVMObject.cpp b/Kernel/VM/SharedInodeVMObject.cpp
index 91e7873fb7..383e35f254 100644
--- a/Kernel/VM/SharedInodeVMObject.cpp
+++ b/Kernel/VM/SharedInodeVMObject.cpp
@@ -9,12 +9,14 @@
namespace Kernel {
-NonnullRefPtr<SharedInodeVMObject> SharedInodeVMObject::create_with_inode(Inode& inode)
+RefPtr<SharedInodeVMObject> SharedInodeVMObject::try_create_with_inode(Inode& inode)
{
size_t size = inode.size();
if (auto shared_vmobject = inode.shared_vmobject())
return shared_vmobject.release_nonnull();
- auto vmobject = adopt_ref(*new SharedInodeVMObject(inode, size));
+ auto vmobject = adopt_ref_if_nonnull(new (nothrow) SharedInodeVMObject(inode, size));
+ if (!vmobject)
+ return nullptr;
vmobject->inode().set_shared_vmobject(*vmobject);
return vmobject;
}
diff --git a/Kernel/VM/SharedInodeVMObject.h b/Kernel/VM/SharedInodeVMObject.h
index a0e45eb0c9..98e2a30082 100644
--- a/Kernel/VM/SharedInodeVMObject.h
+++ b/Kernel/VM/SharedInodeVMObject.h
@@ -16,7 +16,7 @@ class SharedInodeVMObject final : public InodeVMObject {
AK_MAKE_NONMOVABLE(SharedInodeVMObject);
public:
- static NonnullRefPtr<SharedInodeVMObject> create_with_inode(Inode&);
+ static RefPtr<SharedInodeVMObject> try_create_with_inode(Inode&);
virtual RefPtr<VMObject> clone() override;
private: