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 314369 - gmenu-simple-editor: segfault in queue_fam_event
gmenu-simple-editor: segfault in queue_fam_event
Status: RESOLVED FIXED
Product: gnome-menus
Classification: Core
Component: libgnome-menu
2.11.x
Other Linux
: Normal critical
: ---
Assigned To: gnome-menus dummy account
gnome-menus dummy account
Depends on:
Blocks:
 
 
Reported: 2005-08-24 10:56 UTC by Ed Catmur
Modified: 2005-08-24 14:53 UTC
See Also:
GNOME target: ---
GNOME version: 2.11/2.12


Attachments
fam-segfault.patch (460 bytes, patch)
2005-08-24 11:07 UTC, Ed Catmur
committed Details | Review

Description Ed Catmur 2005-08-24 10:56:47 UTC
This does not happen every time, but maybe 2 out of 3, suggesting a race condition.

Program received signal SIGSEGV, Segmentation fault.
0xb7a12b3f in queue_fam_event (monitor=0x8283a48, fam_event=0xbfe64380)
    at menu-monitor.c:192
192           event = tmp->data;
(gdb) bt
  • #0 queue_fam_event
    at menu-monitor.c line 192
  • #1 process_fam_events
    at menu-monitor.c line 308
  • #2 fam_data_pending
    at menu-monitor.c line 320
  • #3 g_io_unix_dispatch
    from /usr/lib/libglib-2.0.so.0
  • #4 g_main_dispatch
    from /usr/lib/libglib-2.0.so.0
  • #5 g_main_context_iterate
    from /usr/lib/libglib-2.0.so.0
  • #6 g_main_loop_run
    from /usr/lib/libglib-2.0.so.0
  • #7 gtk_main
    from /usr/lib/libgtk-x11-2.0.so.0
  • #8 _wrap_gtk_main
    from /usr/lib/python2.4/site-packages/gtk-2.0/gtk/_gtk.so
  • #9 PyEval_EvalFrame
    from /usr/lib/libpython2.4.so.1.0
  • #10 PyEval_EvalFrame
    from /usr/lib/libpython2.4.so.1.0
  • #11 PyEval_EvalCodeEx
    from /usr/lib/libpython2.4.so.1.0
  • #12 PyEval_EvalCode
    from /usr/lib/libpython2.4.so.1.0
  • #13 PyRun_FileExFlags
    from /usr/lib/libpython2.4.so.1.0
  • #14 PyRun_SimpleFileExFlags
    from /usr/lib/libpython2.4.so.1.0
  • #15 PyRun_AnyFileExFlags
    from /usr/lib/libpython2.4.so.1.0
  • #16 Py_Main
    from /usr/lib/libpython2.4.so.1.0
  • #17 main
$34 = {path = 0x2 <Address 0x2 out of bounds>, refcount = 0,
  notifies = 0x40280000, request = {reqnum = 1}, pending_events = 0x67903212,
  is_directory = 1}

I put a trace on unregister_monitor_with_fam() and discovered that the
MenuMonitor that causes the segfault has already been freed:

(gdb) b unregister_monitor_with_fam
Breakpoint 2 at 0xb79b2239: file menu-monitor.c, line 418.
(gdb) commands
Type commands for when breakpoint 2 is hit, one per line.
End with a line saying just "end".
>continue
>end
(gdb) r
Starting program: /usr/bin/python /usr/bin/gmenu-simple-editor
[Thread debugging using libthread_db enabled]
[New Thread -1208710720 (LWP 18311)]
Breakpoint 1 at 0xb7a130ca: file menu-monitor.c, line 369.
Breakpoint 2 at 0xb7a13239: file menu-monitor.c, line 418.
[Switching to Thread -1208710720 (LWP 18311)]
...
Breakpoint 2, unregister_monitor_with_fam (monitor=0x8283a48)
    at menu-monitor.c:418
418       if (failed_to_connect)
...
Program received signal SIGSEGV, Segmentation fault.
0xb7a12b3f in queue_fam_event (monitor=0x8283a48, fam_event=0xbfe64380)
    at menu-monitor.c:192
192           event = tmp->data;

I think what is happening is that when unregister_monitor_with_fam() calls 
FAMCancelMonitor() there are already unprocessed fam events in the queue that
have a pointer to the monitor, so when unregister_monitor_with_fam() returns and
the monitor is freed, queue_fam_event gets passed a freed monitor.

This is a race condition, so as noted above would not be triggered on every run.

The fix would be to run process_fam_events() immediately after
FAMCancelMonitor() to ensure any events with a pointer to the monitor get
processed before it is freed.

Note: running Gentoo fam-2.7.0-r4.
Comment 1 Ed Catmur 2005-08-24 11:07:15 UTC
Created attachment 51243 [details] [review]
fam-segfault.patch

As suggested above.

This appears to eliminate the crashes, suggesting that it is the correct fix.
Comment 2 Mark McLoughlin 2005-08-24 12:04:31 UTC
Patch looks good, thanks. Please go ahead and commit

(One minor nit - remove the return statement, its not needed)
Comment 3 Ed Catmur 2005-08-24 12:36:39 UTC
Sorry, I don't have commit privileges.
Comment 4 Mark McLoughlin 2005-08-24 14:53:44 UTC
Okay, thanks again

2005-08-24  Mark McLoughlin  <mark@skynet.ie>

        Fix crasher where a FAMConnection may have events for
        a monitor, even after the monitor may be cancelled.
        Patch from Ed Catmur <ed@catmur.co.uk> in bug #314369

        * libmenu/menu-monitor.c: (unregister_monitor_with_fam):
        Process any pending events after cancelling the monitor.