From 95639a7492f32c6177feca409bf60bd365bca77d Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Mon, 22 Mar 2021 19:04:45 +0100 Subject: [PATCH] vfs/cbe_trust_anchor: close handles correctly The plugin used to close file handles via the 'vfs_env.root_dir.close'. However, this lead to resource leaks and apparently isn't the right way to do it. Other VFS plugins do it by calling 'close' directly on the handle and doing it in the trust anchor plugin also, fixes the leaks. Ref #4032 --- .../gems/src/lib/vfs/cbe_trust_anchor/vfs.cc | 35 ++++++++----------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/repos/gems/src/lib/vfs/cbe_trust_anchor/vfs.cc b/repos/gems/src/lib/vfs/cbe_trust_anchor/vfs.cc index dcac255fe7..bb75d42115 100644 --- a/repos/gems/src/lib/vfs/cbe_trust_anchor/vfs.cc +++ b/repos/gems/src/lib/vfs/cbe_trust_anchor/vfs.cc @@ -428,6 +428,12 @@ class Trust_anchor Io_response_handler _io_response_handler { _io_handler }; + void _close_handle(Vfs::Vfs_handle **handle) + { + (*handle)->close(); + (*handle) = nullptr; + } + /* key */ Vfs::Vfs_handle *_key_handle { nullptr }; @@ -489,8 +495,7 @@ class Trust_anchor Util::Io_job::Partial_result::ALLOW); if (_key_io_job->execute() && _key_io_job->completed()) { _state = State::INITIALIZED; - _vfs_env.root_dir().close(_key_handle); - _key_handle = nullptr; + _close_handle(&_key_handle); return true; } return true; @@ -508,8 +513,7 @@ class Trust_anchor bool const completed = _key_io_job->completed(); if (completed) { _state = State::INITIALIZED; - _vfs_env.root_dir().close(_key_handle); - _key_handle = nullptr; + _close_handle(&_key_handle); _key_io_job.destruct(); } @@ -539,8 +543,7 @@ class Trust_anchor _key_io_job_buffer, 0); if (_key_io_job->execute() && _key_io_job->completed()) { _state = State::INITIALIZED; - _vfs_env.root_dir().close(_key_handle); - _key_handle = nullptr; + _close_handle(&_key_handle); _key_io_job.destruct(); return true; } @@ -559,8 +562,7 @@ class Trust_anchor bool const completed = _key_io_job->completed(); if (completed) { _state = State::INITIALIZED; - _vfs_env.root_dir().close(_key_handle); - _key_handle = nullptr; + _close_handle(&_key_handle); _key_io_job.destruct(); } @@ -608,8 +610,7 @@ class Trust_anchor _hash_io_job_buffer, 0, Util::Io_job::Partial_result::ALLOW); if (_hash_io_job->execute() && _hash_io_job->completed()) { - _vfs_env.root_dir().close(_hash_handle); - _hash_handle = nullptr; + _close_handle(&_hash_handle); _hash_io_job.destruct(); return true; } @@ -624,8 +625,7 @@ class Trust_anchor bool const progress = _hash_io_job->execute(); bool const completed = _hash_io_job->completed(); if (completed) { - _vfs_env.root_dir().close(_hash_handle); - _hash_handle = nullptr; + _close_handle(&_hash_handle); _hash_io_job.destruct(); } @@ -638,14 +638,6 @@ class Trust_anchor _hash_io_job_buffer, 0); } - void _close_hash_handle() - { - _vfs_env.root_dir().close(_hash_handle); - Genode::destroy(_hash_handle->alloc(), _hash_handle); - _hash_handle = nullptr; - _hash_io_job.destruct(); - } - bool _open_hash_file_and_write(Path const &path) { using Result = Vfs::Directory_service::Open_result; @@ -705,7 +697,8 @@ class Trust_anchor bool const progress = _hash_io_job->execute(); bool const completed = _hash_io_job->completed(); if (completed) { - _close_hash_handle(); + _close_handle(&_hash_handle); + _hash_io_job.destruct(); } return progress && completed; }