[gnome-shell] [StButton] Hold ref to self until animation completes



commit d7e0051bc6c33283c664f3018490f56c13e48ff0
Author: Colin Walters <walters verbum org>
Date:   Fri Jan 22 18:50:48 2010 -0500

    [StButton] Hold ref to self until animation completes
    
    StButton has an internal animation for the border-image actor, then
    it connects to the "completed" signal passing itself as data.  However,
    if the button is destroyed, nothing prevents the animation's completed
    signal from then causing a reference to freed memory.
    
    Holding a reference to the button is the most straightforward fix here.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=607825

 src/st/st-button.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
---
diff --git a/src/st/st-button.c b/src/st/st-button.c
index 52032f0..1f6113e 100644
--- a/src/st/st-button.c
+++ b/src/st/st-button.c
@@ -75,6 +75,7 @@ struct _StButtonPrivate
 
   ClutterActor     *old_bg;
   gboolean          old_bg_parented; /* TRUE if we have adopted old_bg */
+  gboolean          old_bg_animating; /* TRUE if the opacity animation is running and we hold a self-ref */
 
   guint8            old_opacity;
 
@@ -122,6 +123,11 @@ st_button_dispose_old_bg (StButton *button)
         }
       g_object_unref (priv->old_bg);
       priv->old_bg = NULL;
+      if (priv->old_bg_animating)
+        {
+          g_object_unref (button);
+          priv->old_bg_animating = FALSE;
+        }
     }
 }
 
@@ -180,6 +186,13 @@ st_button_style_changed (StWidget *widget)
                                                  priv->transition_duration,
                                                  "opacity", 0,
                                                  NULL);
+              /* The reference counting here is looped; through the button, old_bg,
+               * and the animation.  However, that's not a problem because we will
+               * break the cycle when either the animation completes, or when
+               * we dispose.
+               */
+              priv->old_bg_animating = TRUE;
+              g_object_ref (button);
               g_signal_connect (animation, "completed",
                                 G_CALLBACK (st_animation_completed), button);
             }



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