GNOME Bugzilla – Bug 581879
GFileMonitor crash: emit_cb not handling monitor disposal in signal handlers
Last modified: 2009-05-20 12:25:09 UTC
While emit_cb is iterating through the pending_file_changes it is possible for a signal handler to remove the last reference and dispose the monitor. If there are more pending_file_changes emit_cb will try and emit a signal with the disposed monitor.
Created attachment 134261 [details] [review] patch to ref the monitor before signaling pending changes This patch for gio/gfilemonitor.c:emit_cb fixes the crash I was hitting by just ref'ing the monitor before sending the signals and unref'ing before leaving emit_cb. I saw there were specific comments in gfilemonitor.c:emit_in_idle regarding referencing of monitors: /* We don't ref here - instead dispose will free any * pending idles. */ so I'm not sure, but this patch may break some intended semantics since a monitor may receive some signals after the user believes they have released the last reference.
Created attachment 134262 [details] [review] patch for emit_cb to detect disposal of the monitor using a weak pointer This alternative patch uses a weak pointer to detect if a monitor has been disposed and maintains the invariable that if the user releases their last reference then no more pending changes will be signaled on that monitor.
The first patch is right, the comment is just about not keeping the monitor alive just for the case of running the idle (if its otherwise unreffed before reaching idle), if the idle is actually running we want to ref it. Applied.