diff --git a/repos/os/include/vfs/dir_file_system.h b/repos/os/include/vfs/dir_file_system.h index 67ed604118..2cbb0ed285 100644 --- a/repos/os/include/vfs/dir_file_system.h +++ b/repos/os/include/vfs/dir_file_system.h @@ -659,9 +659,15 @@ class Vfs::Dir_file_system : public File_system continue; } - new (dir_vfs_handle.alloc()) - Dir_vfs_handle::Subdir_handle_element( - dir_vfs_handle.subdir_handle_registry, *sub_dir_handle); + try { + new (dir_vfs_handle.alloc()) + Dir_vfs_handle::Subdir_handle_element( + dir_vfs_handle.subdir_handle_registry, *sub_dir_handle); + } + catch (...) { + sub_dir_handle->close(); + throw; + } /* return OK because at least one directory has been opened */ res = OPENDIR_OK; }