diff options
author | Jasper St. Pierre <jstpierre@mecheye.net> | 2013-08-26 16:22:08 -0400 |
---|---|---|
committer | Jasper St. Pierre <jstpierre@mecheye.net> | 2013-08-26 16:30:04 -0400 |
commit | 576cd87a5bc7d5abe22d1d20b00f4ace13dde050 (patch) | |
tree | c0dc75e2df51ec265e03c8c5ef5dded4e8bf3475 | |
parent | e74ed9299321a2036d2fdd15268d38bd8f9f8341 (diff) | |
download | mutter-576cd87a5bc7d5abe22d1d20b00f4ace13dde050.tar.gz |
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
-rw-r--r-- | src/core/meta-idle-monitor.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/core/meta-idle-monitor.c b/src/core/meta-idle-monitor.c index 568e6db72..0d841c4e1 100644 --- a/src/core/meta-idle-monitor.c +++ b/src/core/meta-idle-monitor.c @@ -104,19 +104,20 @@ static void fire_watch (MetaIdleMonitorWatch *watch) { MetaIdleMonitor *monitor; + guint id; + gboolean is_user_active_watch; monitor = watch->monitor; g_object_ref (monitor); + id = watch->id; + is_user_active_watch = (watch->timeout_msec == 0); + if (watch->callback) - { - watch->callback (watch->monitor, - watch->id, - watch->user_data); - } + watch->callback (monitor, id, watch->user_data); - if (watch->timeout_msec == 0) - meta_idle_monitor_remove_watch (watch->monitor, watch->id); + if (is_user_active_watch) + meta_idle_monitor_remove_watch (monitor, id); g_object_unref (monitor); } |