diff --git a/repos/base/include/root/component.h b/repos/base/include/root/component.h index 81ef7d2d4..35698b90e 100644 --- a/repos/base/include/root/component.h +++ b/repos/base/include/root/component.h @@ -122,6 +122,18 @@ class Genode::Root_component : public Rpc_object >, { 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 >, _ep->manage(s); + aquire_guard.ack = true; return *s; }