Fixed GtkToolPalette ->forall implementation to be gtk_widget_destroy friendly

The forall() loop was buggy as it was skipping items in the list when
the current item gets removed from the groups array as a result of
calling the callback (causing memory leaks).
This commit is contained in:
Tristan Van Berkom 2011-02-01 04:57:05 +09:00
parent ddb4b3ebe2
commit a37976dae0

View File

@ -831,15 +831,21 @@ gtk_tool_palette_forall (GtkContainer *container,
gpointer callback_data)
{
GtkToolPalette *palette = GTK_TOOL_PALETTE (container);
guint i;
guint i, len;
for (i = 0; i < palette->priv->groups->len; ++i)
{
GtkToolItemGroupInfo *info = g_ptr_array_index (palette->priv->groups, i);
len = palette->priv->groups->len;
if (info->widget)
callback (GTK_WIDGET (info->widget),
callback_data);
/* At destroy time, 'callback' results in removing a widget,
* here we just reset the current index to account for the removed widget. */
i -= (len - palette->priv->groups->len);
}
}