浏览代码

Kernel: Make InodeWatcher inode registration completely OOM-fallible

InodeWatcher::register_inode was already partially fallible, but the
insertion of the inodes and watch descriptions into their respective
hash maps was not. Note that we cannot simply TRY the insertion into
both, as that could result in an inconsistent state, instead we must
remove the inode from the inode hash map if the insertion into the
watch description hash map failed.
Idan Horowitz 3 年之前
父节点
当前提交
87bd930e7e
共有 1 个文件被更改,包括 6 次插入2 次删除
  1. 6 2
      Kernel/FileSystem/InodeWatcher.cpp

+ 6 - 2
Kernel/FileSystem/InodeWatcher.cpp

@@ -123,8 +123,12 @@ ErrorOr<int> InodeWatcher::register_inode(Inode& inode, unsigned event_mask)
 
 
     auto description = TRY(WatchDescription::create(wd, inode, event_mask));
     auto description = TRY(WatchDescription::create(wd, inode, event_mask));
 
 
-    m_inode_to_watches.set(inode.identifier(), description.ptr());
-    m_wd_to_watches.set(wd, move(description));
+    TRY(m_inode_to_watches.try_set(inode.identifier(), description.ptr()));
+    auto result = m_wd_to_watches.try_set(wd, move(description));
+    if (result.is_error()) {
+        m_inode_to_watches.remove(inode.identifier());
+        return result.release_error();
+    }
 
 
     inode.register_watcher({}, *this);
     inode.register_watcher({}, *this);
     return wd;
     return wd;