d9c875
From d4f62b44d47e3dddfb57add4f1f76cab0297584d Mon Sep 17 00:00:00 2001
d9c875
From: Matthias Clasen <mclasen@redhat.com>
d9c875
Date: Fri, 11 Jun 2021 08:53:46 -0400
d9c875
Subject: [PATCH 1/2] a11y: Fix ref counting in tree views
d9c875
d9c875
GtkContainerCellAccessible wasn't unsetting accessible
d9c875
parents. Fix that.
d9c875
d9c875
By itself, this doesn't help for freeing a memory leak,
d9c875
since AtkObject keeps a ref on its parent, so we never
d9c875
free the GtkContainerCellAccessible as long as it has children.
d9c875
---
d9c875
 gtk/a11y/gtkcontainercellaccessible.c | 10 +++++++++-
d9c875
 1 file changed, 9 insertions(+), 1 deletion(-)
d9c875
d9c875
diff --git a/gtk/a11y/gtkcontainercellaccessible.c b/gtk/a11y/gtkcontainercellaccessible.c
d9c875
index a756e3cadf..a40446fb47 100644
d9c875
--- a/gtk/a11y/gtkcontainercellaccessible.c
d9c875
+++ b/gtk/a11y/gtkcontainercellaccessible.c
d9c875
@@ -30,12 +30,19 @@ struct _GtkContainerCellAccessiblePrivate
d9c875
 G_DEFINE_TYPE_WITH_PRIVATE (GtkContainerCellAccessible, gtk_container_cell_accessible, GTK_TYPE_CELL_ACCESSIBLE)
d9c875
 
d9c875
 
d9c875
+static void
d9c875
+unset_child (gpointer child)
d9c875
+{
d9c875
+  atk_object_set_parent (ATK_OBJECT (child), NULL);
d9c875
+  g_object_unref (child);
d9c875
+}
d9c875
+
d9c875
 static void
d9c875
 gtk_container_cell_accessible_finalize (GObject *obj)
d9c875
 {
d9c875
   GtkContainerCellAccessible *container = GTK_CONTAINER_CELL_ACCESSIBLE (obj);
d9c875
 
d9c875
-  g_list_free_full (container->priv->children, g_object_unref);
d9c875
+  g_list_free_full (container->priv->children, unset_child);
d9c875
 
d9c875
   G_OBJECT_CLASS (gtk_container_cell_accessible_parent_class)->finalize (obj);
d9c875
 }
d9c875
@@ -157,6 +164,7 @@ gtk_container_cell_accessible_remove_child (GtkContainerCellAccessible *containe
d9c875
   g_return_if_fail (GTK_IS_CELL_ACCESSIBLE (child));
d9c875
   g_return_if_fail (container->priv->n_children > 0);
d9c875
 
d9c875
+  atk_object_set_parent (ATK_OBJECT (child), NULL);
d9c875
   container->priv->children = g_list_remove (container->priv->children, child);
d9c875
   container->priv->n_children--;
d9c875
 
d9c875
-- 
d9c875
GitLab
d9c875
d9c875
d9c875
From 21f8098261486417db371b202bc0494c12017468 Mon Sep 17 00:00:00 2001
d9c875
From: Matthias Clasen <mclasen@redhat.com>
d9c875
Date: Fri, 11 Jun 2021 08:55:48 -0400
d9c875
Subject: [PATCH 2/2] a11y: Plug a memory leak with treeviews
d9c875
d9c875
We need to explicitly remove the children from
d9c875
a GtkContainerCellAccessible, since they otherwise
d9c875
keep the parent alive.
d9c875
d9c875
Fixes: #3981
d9c875
---
d9c875
 gtk/a11y/gtktreeviewaccessible.c | 11 +++++++++++
d9c875
 1 file changed, 11 insertions(+)
d9c875
d9c875
diff --git a/gtk/a11y/gtktreeviewaccessible.c b/gtk/a11y/gtktreeviewaccessible.c
d9c875
index adad462064..c1a2097a1e 100644
d9c875
--- a/gtk/a11y/gtktreeviewaccessible.c
d9c875
+++ b/gtk/a11y/gtktreeviewaccessible.c
d9c875
@@ -104,6 +104,17 @@ static void
d9c875
 cell_info_free (GtkTreeViewAccessibleCellInfo *cell_info)
d9c875
 {
d9c875
   gtk_accessible_set_widget (GTK_ACCESSIBLE (cell_info->cell), NULL);
d9c875
+  if (GTK_IS_CONTAINER_CELL_ACCESSIBLE (cell_info->cell))
d9c875
+    {
d9c875
+      GList *children;
d9c875
+
d9c875
+      while ((children = gtk_container_cell_accessible_get_children (GTK_CONTAINER_CELL_ACCESSIBLE (cell_info->cell))) != NULL)
d9c875
+        {
d9c875
+          GtkCellAccessible *child = children->data;
d9c875
+          gtk_container_cell_accessible_remove_child (GTK_CONTAINER_CELL_ACCESSIBLE (cell_info->cell), child);
d9c875
+        }
d9c875
+    }
d9c875
+
d9c875
   g_object_unref (cell_info->cell);
d9c875
 
d9c875
   g_free (cell_info);
d9c875
-- 
d9c875
GitLab
d9c875