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