[mutter/wayland] idle-monitor: Fix a warning when a callback removes the user active watch
- From: Giovanni Campagna <gcampagna src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/wayland] idle-monitor: Fix a warning when a callback removes the user active watch
- Date: Tue, 27 Aug 2013 07:57:48 +0000 (UTC)
commit 6526e9882b304ad24218bb5f576a35fd10100bdc
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Mon Aug 26 16:22:08 2013 -0400
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
src/core/meta-idle-monitor.c | 17 +++++++++--------
1 files changed, 9 insertions(+), 8 deletions(-)
---
diff --git a/src/core/meta-idle-monitor.c b/src/core/meta-idle-monitor.c
index cc3e8f7..4301b00 100644
--- a/src/core/meta-idle-monitor.c
+++ b/src/core/meta-idle-monitor.c
@@ -110,19 +110,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);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]