diff --git a/repos/os/src/server/nitpicker/main.cc b/repos/os/src/server/nitpicker/main.cc index cb2b1c3f4e..bb9fefd3b1 100644 --- a/repos/os/src/server/nitpicker/main.cc +++ b/repos/os/src/server/nitpicker/main.cc @@ -815,12 +815,26 @@ class Nitpicker::Session_component : public Genode::Rpc_object, void destroy_view(View_handle handle) override { - try { - Locked_ptr view(_view_handle_registry.lookup(handle)); - if (view.is_valid()) - _destroy_view(*view); + /* + * Search view object given the handle + * + * We cannot look up the view directly from the + * '_view_handle_registry' because we would obtain a weak + * pointer to the view object. If we called the object's + * destructor from the corresponding locked pointer, the + * call of 'lock_for_destruction' in the view's destructor + * would attempt to take the lock again. + */ + for (Session_view_list_elem *v = _view_list.first(); v; v = v->next()) { + + try { + View &view = *static_cast(v); + if (_view_handle_registry.has_handle(view, handle)) { + _destroy_view(view); + break; + } + } catch (View_handle_registry::Lookup_failed) { } } - catch (View_handle_registry::Lookup_failed) { } _view_handle_registry.free(handle); }