From d7e0051bc6c33283c664f3018490f56c13e48ff0 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 22 Jan 2010 18:50:48 -0500 Subject: [PATCH] [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 file changed, 13 insertions(+) diff --git a/src/st/st-button.c b/src/st/st-button.c index 52032f0f3..1f6113e20 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); }