Commit e9e8adda authored by Adrien Plazas's avatar Adrien Plazas Committed by Guido Gunther
Browse files

leaflet: Allow editing the children list when looping through it

This avoids potential crashes when destroying a leaflet and this avoids
leaks as not all children where looped through as the children list was
edited while being looped through when destroying the leaflet.

This fixes Librem5/libhandy#42.
parent b6213b5c
Pipeline #2591 passed with stage
in 3 minutes and 35 seconds
......@@ -2265,10 +2265,15 @@ hdy_leaflet_forall (GtkContainer *container,
{
HdyLeaflet *self = HDY_LEAFLET (container);
HdyLeafletPrivate *priv = hdy_leaflet_get_instance_private (self);
/* This shallow copy is needed when the callback changes the list while we are
* looping through it, for example by calling hdy_leaflet_remove() on all
* children when destroying the HdyLeaflet_private_offset.
*/
g_autoptr (GList) children_copy = g_list_copy (priv->children);
GList *children;
HdyLeafletChildInfo *child_info;
for (children = priv->children; children; children = children->next) {
for (children = children_copy; children; children = children->next) {
child_info = children->data;
(* callback) (child_info->widget, callback_data);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment