diff options
author | Paolo Borelli <pborelli@gnome.org> | 2012-11-04 16:46:35 +0100 |
---|---|---|
committer | Paolo Borelli <pborelli@gnome.org> | 2012-11-04 17:12:14 +0100 |
commit | 1beb9db7b09483cf9b71be733f73d02cb7adc666 (patch) | |
tree | 3723564d9b3ace0a6800fabd66de9f86574ca769 /gtk/gtkmenubutton.c | |
parent | 583036378706ab03822f30ce311c41293d482d6c (diff) | |
download | gtk+-1beb9db7b09483cf9b71be733f73d02cb7adc666.tar.gz |
gtkmenubutton: remove weak pointer when needed
We must make sure to remove the weak pointer when disposing the widget
or when resetting the align widget otherwise glib will try to nullify
invalid memory.
Diffstat (limited to 'gtk/gtkmenubutton.c')
-rw-r--r-- | gtk/gtkmenubutton.c | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/gtk/gtkmenubutton.c b/gtk/gtkmenubutton.c index 5416d3761a..dd4a3bba8e 100644 --- a/gtk/gtkmenubutton.c +++ b/gtk/gtkmenubutton.c @@ -791,6 +791,23 @@ gtk_menu_button_get_menu_model (GtkMenuButton *menu_button) return menu_button->priv->model; } +static void +set_align_widget_pointer (GtkMenuButton *menu_button, + GtkWidget *align_widget) +{ + GtkMenuButtonPrivate *priv; + + priv = menu_button->priv; + + if (priv->align_widget) + g_object_remove_weak_pointer (G_OBJECT (priv->align_widget), (gpointer *) &priv->align_widget); + + priv->align_widget = align_widget; + + if (align_widget) + g_object_add_weak_pointer (G_OBJECT (priv->align_widget), (gpointer *) &priv->align_widget); +} + /** * gtk_menu_button_set_align_widget: * @menu_button: a #GtkMenuButton @@ -817,10 +834,7 @@ gtk_menu_button_set_align_widget (GtkMenuButton *menu_button, if (priv->align_widget == align_widget) return; - priv->align_widget = align_widget; - - if (priv->align_widget) - g_object_add_weak_pointer (G_OBJECT (priv->align_widget), (gpointer *) &priv->align_widget); + set_align_widget_pointer (menu_button, align_widget); g_object_notify (G_OBJECT (menu_button), "align-widget"); } @@ -914,6 +928,8 @@ gtk_menu_button_dispose (GObject *object) priv->popup = NULL; } + set_align_widget_pointer (GTK_MENU_BUTTON (object), NULL); + g_clear_object (&priv->model); G_OBJECT_CLASS (gtk_menu_button_parent_class)->dispose (object); |