[gnome-online-accounts] alarm: Do not clear the wrong objects when setting the time



commit d960d24c4422a01bf0b109228b6f755b498cfc27
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri Nov 8 18:33:49 2013 +0100

    alarm: Do not clear the wrong objects when setting the time
    
    When the time is set using goa_alarm_set_time, we cancel the existing
    self->priv->cancellable and replace it with a new one. Then we take a
    reference to a new context and time. However, since when we cancelled
    the old cancellable, we triggered a chain of events which cause
    clear_scheduled_wakeups to be invoked from a idle callback. By the time
    it gets invoked, self->priv->cancellable, self->priv->context and
    self->priv->time point to the new objects that were set up in
    goa_alarm_set_time, which we don't want to clear.
    
    Actually, there is no point in clearing them in
    clear_scheduled_wakeups, because goa_alarm_set_time already clears up
    the older objects and the only other time we want to clear them is in
    dispose.
    
    Fixes: https://bugzilla.gnome.org/711696

 src/goaidentity/goaalarm.c |   20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)
---
diff --git a/src/goaidentity/goaalarm.c b/src/goaidentity/goaalarm.c
index 920e43f..3fa9523 100644
--- a/src/goaidentity/goaalarm.c
+++ b/src/goaidentity/goaalarm.c
@@ -151,15 +151,9 @@ clear_scheduled_wakeups (GoaAlarm *self)
       break;
     }
 
-  g_clear_object (&self->priv->cancellable);
-
-  g_clear_pointer (&self->priv->context, (GDestroyNotify) g_main_context_unref);
-
   g_clear_pointer (&self->priv->previous_wakeup_time,
                    (GDestroyNotify) g_date_time_unref);
 
-  g_clear_pointer (&self->priv->time, (GDestroyNotify) g_date_time_unref);
-
   g_assert (self->priv->timeout.source == NULL);
 
   self->priv->type = GOA_ALARM_TYPE_UNSCHEDULED;
@@ -167,6 +161,18 @@ clear_scheduled_wakeups (GoaAlarm *self)
 }
 
 static void
+goa_alarm_dispose (GObject *object)
+{
+  GoaAlarm *self = GOA_ALARM (object);
+
+  g_clear_object (&self->priv->cancellable);
+  g_clear_pointer (&self->priv->context, (GDestroyNotify) g_main_context_unref);
+  g_clear_pointer (&self->priv->time, (GDestroyNotify) g_date_time_unref);
+
+  G_OBJECT_CLASS (goa_alarm_parent_class)->dispose (object);
+}
+
+static void
 goa_alarm_finalize (GObject *object)
 {
   GoaAlarm *self = GOA_ALARM (object);
@@ -223,6 +229,7 @@ goa_alarm_class_init (GoaAlarmClass *klass)
 
   object_class = G_OBJECT_CLASS (klass);
 
+  object_class->dispose = goa_alarm_dispose;
   object_class->finalize = goa_alarm_finalize;
   object_class->get_property = goa_alarm_get_property;
   object_class->set_property = goa_alarm_set_property;
@@ -637,6 +644,7 @@ goa_alarm_set_time (GoaAlarm *self, GDateTime *time, GCancellable *cancellable)
 
   self->priv->time = time;
 
+  g_clear_pointer (&self->priv->context, (GDestroyNotify) g_main_context_unref);
   self->priv->context = g_main_context_ref (g_main_context_default ());
 
   schedule_wakeups (self);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]