root/component.h: POLICY::release on exception

This patch ensures that the POLICY::release is called whenever the
session creation aborted with an exception. In the original version, an
exception like 'Quota_exceeded' caused a single-session root interface
to deny subsequent session requests.
This commit is contained in:
Norman Feske 2017-02-21 15:17:41 +01:00 committed by Christian Helmuth
parent 8b4afe95c1
commit dfc4c58782

View File

@ -122,6 +122,18 @@ class Genode::Root_component : public Rpc_object<Typed_root<SESSION_TYPE> >,
{
POLICY::aquire(args.string());
/*
* Guard to ensure that 'release' is called whenever the scope
* is left with an exception.
*/
struct Guard
{
bool ack = false;
Root_component &root;
Guard(Root_component &root) : root(root) { }
~Guard() { if (!ack) root.release(); }
} aquire_guard { *this };
/*
* We need to decrease 'ram_quota' by
* the size of the session object.
@ -163,6 +175,7 @@ class Genode::Root_component : public Rpc_object<Typed_root<SESSION_TYPE> >,
_ep->manage(s);
aquire_guard.ack = true;
return *s;
}