idle-monitor: Fix a warning when a callback removes the user active watch

The user active watch is a one-fire watch, but it is valid in the API
for the callback to explicitly remove the watch itself. In that case,
the watch will be invalid after the user removes it, and the memory
potentially freed. So make sure to not dereference the watch after
the callback is called.

https://bugzilla.gnome.org/show_bug.cgi?id=706825
This commit is contained in:
Jasper St. Pierre 2013-08-26 16:22:08 -04:00
parent e74ed92993
commit 576cd87a5b

View File

@ -104,19 +104,20 @@ static void
fire_watch (MetaIdleMonitorWatch *watch) fire_watch (MetaIdleMonitorWatch *watch)
{ {
MetaIdleMonitor *monitor; MetaIdleMonitor *monitor;
guint id;
gboolean is_user_active_watch;
monitor = watch->monitor; monitor = watch->monitor;
g_object_ref (monitor); g_object_ref (monitor);
if (watch->callback) id = watch->id;
{ is_user_active_watch = (watch->timeout_msec == 0);
watch->callback (watch->monitor,
watch->id,
watch->user_data);
}
if (watch->timeout_msec == 0) if (watch->callback)
meta_idle_monitor_remove_watch (watch->monitor, watch->id); watch->callback (monitor, id, watch->user_data);
if (is_user_active_watch)
meta_idle_monitor_remove_watch (monitor, id);
g_object_unref (monitor); g_object_unref (monitor);
} }