Skip to content

Commit 87bd930

Browse files
committed
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.
1 parent bd60300 commit 87bd930

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Kernel/FileSystem/InodeWatcher.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,12 @@ ErrorOr<int> InodeWatcher::register_inode(Inode& inode, unsigned event_mask)
123123

124124
auto description = TRY(WatchDescription::create(wd, inode, event_mask));
125125

126-
m_inode_to_watches.set(inode.identifier(), description.ptr());
127-
m_wd_to_watches.set(wd, move(description));
126+
TRY(m_inode_to_watches.try_set(inode.identifier(), description.ptr()));
127+
auto result = m_wd_to_watches.try_set(wd, move(description));
128+
if (result.is_error()) {
129+
m_inode_to_watches.remove(inode.identifier());
130+
return result.release_error();
131+
}
128132

129133
inode.register_watcher({}, *this);
130134
return wd;

0 commit comments

Comments
 (0)