GNOME Bugzilla – Bug 737781
Segfault in libgio: extend_menu("preferences-section") cannot be called after extend_menu("tools-section")
Last modified: 2019-03-23 20:34:37 UTC
The following code in AppActivatable causes a segfault in libgio: menu_ext = self.extend_menu("tools-section") menu = Gio.MenuItem.new("DummyMenu") container = Gio.Menu.new() menu.set_submenu(container) menu_ext.append_menu_item(menu) container.append_item(Gio.MenuItem.new("Dummy", "win.dummy")) self.extend_menu("preferences-section") The segfault log entry is: gedit[6209]: segfault at 0 ip 00007f9b838ef0a0 sp 00007fff6044c868 error 4 in libgio-2.0.so.0.4200.0[7f9b83842000+16f000]
This makes it impossible to use a plugin extending tools (e.g., Latex) with Snippets or External Tools, since the latter ones extend preferences.
Created attachment 327003 [details] Backtrace in gedit 3.18.3-1
This apparently got worse in 3.22.0. Previously, gedit crashed only if the preferences menu was extended after the tools menu: but you could enable first the plugin in the preferences menu, then the one in the tools menu, and everything would work just fine across restarts. Now instead, - extend tools, then preferences -> segfault - extend preferences, then tools -> segfault - ... restart gedit: segfault Please feel free to ask for any additional info.
Sorry, the second bullet is wrong. This is the current state: - extend tools, then preferences -> segfault - extend preferences, then tools -> works until you close gedit - ... restart gedit: segfault
This won't fix the error at hand, but gedit might consider using the MenuManager we built for Builder (based on this gedit menu extension tooling) which allows plugins to simply include a menus.ui resource and extend built-in menus. It has one additional requirement that you have to use id="" on your menu items, but that's a small price to pay to have pain free menu extensions. https://git.gnome.org/browse/gnome-builder/tree/contrib/egg/egg-menu-manager.c https://git.gnome.org/browse/gnome-builder/tree/contrib/egg/egg-menu-manager.h
Created attachment 339200 [details] [review] Patch for bugzilla #737781 - do not look into submenu if NULL This patch solves the bug on gedit 3.22.0 and applies cleanly (but is untested) on git master. I don't have clear at all what is the cause of the bug. But then, it is pretty obvious that the patch can't have any side effect: if "subsection" is not NULL, nothing changes; if it is, then we are avoiding the segfault.
I plan to push the patch in the next few days if there are no objections.
Pushed: https://git.gnome.org/browse/gedit/commit/?id=f4ecdcb8807fec2594f62bf7a7f179063f31e41b
Review of attachment 339200 [details] [review]: Sorry for not being responsive. Can you please push another patch with that style fix? Thanks ::: gedit/gedit-app.c @@ +1713,3 @@ subsection = g_menu_model_get_item_link (model, i, G_MENU_LINK_SECTION); + + if (!subsection) be explicit about NULL, if (subsection == NULL)
Done, thanks for the pointer: https://git.gnome.org/browse/gedit/commit/?id=f4ecdcb8807fec2594f62bf7a7f179063f31e41b