From 2501cb189ea71609a8998b6010faac4c7fe9c43d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20S=C3=B6ntgen?= Date: Mon, 2 Sep 2013 15:23:26 +0200 Subject: [PATCH] core: explicitly throw Out_of_metadata In case there is not enough quota left to create the trace buffer or trace policy dataspace throw Out_of_metadata explicitly instead of rethrowing the Ram_session::Quota_exceeded exception. Now one can catch Trace::Out_of_metadata exception in a client application. In addition fix Allocator_guard::withdraw() checks because this method does not throw any exceptions and a failed withdrawal goes unoticed. Fixes #871. --- base/src/core/trace_session_component.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/base/src/core/trace_session_component.cc b/base/src/core/trace_session_component.cc index 343a99b9c0..03c7f4befc 100644 --- a/base/src/core/trace_session_component.cc +++ b/base/src/core/trace_session_component.cc @@ -43,17 +43,17 @@ Policy_id Session_component::alloc_policy(size_t size) Policy_id const id(_policy_cnt++); - try { _md_alloc.withdraw(size); } - catch (...) { throw Out_of_metadata(); } + if (!_md_alloc.withdraw(size)) + throw Out_of_metadata(); try { Ram_dataspace_capability ds = _ram.alloc(size); _policies.insert(*this, id, _policies_slab, ds, size); } catch (...) { - /* revert withdrawal or quota and re-throw exception */ + /* revert withdrawal or quota */ _md_alloc.upgrade(size); - throw; + throw Out_of_metadata(); } return id; @@ -82,17 +82,17 @@ void Session_component::trace(Subject_id subject_id, Policy_id policy_id, * Account RAM needed for trace buffer and policy buffer to the trace * session. */ - try { _md_alloc.withdraw(required_ram); } - catch (...) { throw Out_of_metadata(); } + if (!_md_alloc.withdraw(required_ram)) + throw Out_of_metadata(); try { Trace::Subject *subject = _subjects.lookup_by_id(subject_id); subject->trace(policy_id, _policies.dataspace(*this, policy_id), policy_size, _ram, buffer_size); } catch (...) { - /* revert withdrawal or quota and re-throw exception */ + /* revert withdrawal or quota */ _md_alloc.upgrade(required_ram); - throw; + throw Out_of_metadata(); } }