Skip to content
  • Ryan Lortie's avatar
    Fix GtkApplicationWindow action group implementation · 2fd307fd
    Ryan Lortie authored
    GtkApplicationWindow frees its internal action group on dispose for the
    usual reasons: to avoid the possibility of reference cycles caused by
    actions referring back to the window again.
    
    Unfortunately, if it happens to be inside of a GtkActionMuxer at the
    time that it is disposed, it will (eventually) be removed from the muxer
    after it has been disposed.  Removing an action group from a muxer
    involves a call to g_action_group_list_actions() which will crash
    because the internal action group to which we normally delegate the call
    has been freed.
    
    A future patch that reworks the quartz menu code will introduce a use of
    GtkActionMuxer in a way that causes exactly this problem.
    
    We can guard against the problem in a number of ways.
    
    First, we can avoid the entire situation by ensuring that we are removed
    from the muxer before we destroy the action group.  To this end, we
    delay destruction of the action group until after the chain-up to the
    dispose of GtkWindow (which is where the window is removed from the
    GtkApplication).
    
    Secondly, we can add checks to each of our GActionGroup and GActionMap
    implementation functions to check that the internal action group is
    still alive before we attempt to delegate to it.
    
    We have to be careful, though: because our _list_actions() call will
    suddenly be returning an empty list, people watching the group from
    outside will have expected to see "action-removed" calls for the
    now-missing items.  Make sure we send those. but only if someone is
    watching.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=710351
    2fd307fd