From b2283a69e0cf70e78f04f071492231408e1c091f Mon Sep 17 00:00:00 2001 From: Michael Mueller Date: Thu, 24 Oct 2024 14:20:57 +0200 Subject: [PATCH] Fixed use after free in ram_file_system. --- repos/os/src/lib/vfs/ram_file_system.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/repos/os/src/lib/vfs/ram_file_system.h b/repos/os/src/lib/vfs/ram_file_system.h index 6b735daaec..feb9db98de 100644 --- a/repos/os/src/lib/vfs/ram_file_system.h +++ b/repos/os/src/lib/vfs/ram_file_system.h @@ -778,13 +778,14 @@ class Vfs::Ram_file_system : public Vfs::File_system bool node_modified = ram_handle->modifying; ram_handle->node.close(*ram_handle); - destroy(vfs_handle->alloc(), ram_handle); - + if (ram_handle->node.unlinked() && !ram_handle->node.opened()) { destroy(_env.alloc(), &ram_handle->node); } else if (node_modified) { node.notify(); } + destroy(vfs_handle->alloc(), ram_handle); + } Stat_result stat(char const *path, Stat &stat) override