Set cell_view to NULL immediately after unparenting

This way we are sure no invalid pointer will be accessed in between.
This commit is contained in:
Kristian Rietveld 2010-12-17 16:30:15 +01:00
parent 81515f7183
commit 21fc66f120

View File

@ -1450,6 +1450,7 @@ static void
gtk_combo_box_add (GtkContainer *container, gtk_combo_box_add (GtkContainer *container,
GtkWidget *widget) GtkWidget *widget)
{ {
gboolean cell_view_removed = FALSE;
GtkComboBox *combo_box = GTK_COMBO_BOX (container); GtkComboBox *combo_box = GTK_COMBO_BOX (container);
GtkComboBoxPrivate *priv = combo_box->priv; GtkComboBoxPrivate *priv = combo_box->priv;
@ -1461,23 +1462,26 @@ gtk_combo_box_add (GtkContainer *container,
return; return;
} }
if (priv->cell_view != NULL && widget != priv->cell_view)
cell_view_removed = TRUE;
if (priv->cell_view && if (priv->cell_view &&
gtk_widget_get_parent (priv->cell_view)) gtk_widget_get_parent (priv->cell_view))
{ {
gtk_widget_unparent (priv->cell_view); gtk_widget_unparent (priv->cell_view);
_gtk_bin_set_child (GTK_BIN (container), NULL); _gtk_bin_set_child (GTK_BIN (container), NULL);
/* since the cell_view was unparented, it's gone now */
priv->cell_view = NULL;
gtk_widget_queue_resize (GTK_WIDGET (container)); gtk_widget_queue_resize (GTK_WIDGET (container));
} }
gtk_widget_set_parent (widget, GTK_WIDGET (container)); gtk_widget_set_parent (widget, GTK_WIDGET (container));
_gtk_bin_set_child (GTK_BIN (container), widget); _gtk_bin_set_child (GTK_BIN (container), widget);
if (priv->cell_view && if (cell_view_removed)
widget != priv->cell_view)
{ {
/* since the cell_view was unparented, it's gone now */
priv->cell_view = NULL;
if (!priv->tree_view && priv->separator) if (!priv->tree_view && priv->separator)
{ {
gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (priv->separator)), gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (priv->separator)),