diff --git a/Kernel/FileSystem/Inode.cpp b/Kernel/FileSystem/Inode.cpp index a8822a1e234..bfe2e4210db 100644 --- a/Kernel/FileSystem/Inode.cpp +++ b/Kernel/FileSystem/Inode.cpp @@ -130,10 +130,11 @@ ErrorOr Inode::decrement_link_count() return ENOTIMPL; } -void Inode::set_shared_vmobject(Memory::SharedInodeVMObject& vmobject) +ErrorOr Inode::set_shared_vmobject(Memory::SharedInodeVMObject& vmobject) { MutexLocker locker(m_inode_lock); - m_shared_vmobject = vmobject; + m_shared_vmobject = TRY(vmobject.try_make_weak_ptr()); + return {}; } RefPtr Inode::bound_socket() const diff --git a/Kernel/FileSystem/Inode.h b/Kernel/FileSystem/Inode.h index 7351e892e28..2056da0bf43 100644 --- a/Kernel/FileSystem/Inode.h +++ b/Kernel/FileSystem/Inode.h @@ -82,7 +82,7 @@ public: void will_be_destroyed(); - void set_shared_vmobject(Memory::SharedInodeVMObject&); + ErrorOr set_shared_vmobject(Memory::SharedInodeVMObject&); RefPtr shared_vmobject() const; static void sync_all(); diff --git a/Kernel/Memory/SharedInodeVMObject.cpp b/Kernel/Memory/SharedInodeVMObject.cpp index fdda7d78608..3c20012718b 100644 --- a/Kernel/Memory/SharedInodeVMObject.cpp +++ b/Kernel/Memory/SharedInodeVMObject.cpp @@ -18,7 +18,7 @@ ErrorOr> SharedInodeVMObject::try_create_with auto new_physical_pages = TRY(VMObject::try_create_physical_pages(size)); auto dirty_pages = TRY(Bitmap::try_create(new_physical_pages.size(), false)); auto vmobject = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) SharedInodeVMObject(inode, move(new_physical_pages), move(dirty_pages)))); - vmobject->inode().set_shared_vmobject(*vmobject); + TRY(vmobject->inode().set_shared_vmobject(*vmobject)); return vmobject; }