From 79279b93fbef309ca9725ce001e3975d594c222f Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Thu, 7 Apr 2022 14:53:05 +0200 Subject: [PATCH] vfs server: fix dangling alloc on watch failure This patch reverts the vfs-watch-handle creation whenever the subsequent allocation of the VFS server's 'Watch' object fails. This can happen when the session RAM or cap quota is depleted. Fixes #4472 --- repos/os/src/server/vfs/main.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/repos/os/src/server/vfs/main.cc b/repos/os/src/server/vfs/main.cc index 4823ffdde5..665a2a520f 100644 --- a/repos/os/src/server/vfs/main.cc +++ b/repos/os/src/server/vfs/main.cc @@ -590,10 +590,16 @@ class Vfs_server::Session_component : private Session_resources, throw Out_of_caps(); } - Node &node = *new (_alloc) - Watch_node(_node_space, path_str, *vfs_handle, *this); + try { + Node &node = *new (_alloc) + Watch_node(_node_space, path_str, *vfs_handle, *this); - return Watch_handle { node.id().value }; + return Watch_handle { node.id().value }; + } + catch (...) { + vfs_handle->close(); + throw; + } } void close(Node_handle handle) override