After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 737781 - Segfault in libgio: extend_menu("preferences-section") cannot be called after extend_menu("tools-section")
Segfault in libgio: extend_menu("preferences-section") cannot be called after...
Status: RESOLVED FIXED
Product: gedit-plugins
Classification: Other
Component: General
3.22.x
Other Linux
: Normal critical
: ---
Assigned To: Gedit maintainers
Gedit maintainers
Depends on:
Blocks:
 
 
Reported: 2014-10-02 13:51 UTC by Aleksei Lissitsin
Modified: 2019-03-23 20:34 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Backtrace in gedit 3.18.3-1 (4.12 KB, text/plain)
2016-04-29 10:58 UTC, Pietro Battiston
  Details
Patch for bugzilla #737781 - do not look into submenu if NULL (420 bytes, patch)
2016-11-06 16:23 UTC, Pietro Battiston
reviewed Details | Review

Description Aleksei Lissitsin 2014-10-02 13:51:29 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]
Comment 1 Aleksei Lissitsin 2014-10-02 13:54:45 UTC
This makes it impossible to use a plugin extending tools (e.g., Latex) with Snippets or External Tools, since the latter ones extend preferences.
Comment 2 Pietro Battiston 2016-04-29 10:58:41 UTC
Created attachment 327003 [details]
Backtrace in gedit 3.18.3-1
Comment 3 Pietro Battiston 2016-10-30 22:52:25 UTC
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.
Comment 4 Pietro Battiston 2016-10-30 23:00:31 UTC
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
Comment 5 Christian Hergert 2016-10-30 23:16:26 UTC
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
Comment 6 Pietro Battiston 2016-11-06 16:23:18 UTC
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.
Comment 7 Pietro Battiston 2016-11-25 23:53:12 UTC
I plan to push the patch in the next few days if there are no objections.
Comment 9 Ignacio Casal Quinteiro (nacho) 2016-11-30 09:07:29 UTC
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)
Comment 10 Pietro Battiston 2016-11-30 09:17:52 UTC
Done, thanks for the pointer:
https://git.gnome.org/browse/gedit/commit/?id=f4ecdcb8807fec2594f62bf7a7f179063f31e41b