From e81db46578590d8130f4d1f63a239baf0f32a9e2 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 12 Aug 2022 12:01:42 -0400 Subject: [PATCH] a11y: Fix a memory leak We need to free the queued context list in dispose if we didn't get to register the contexts, and we also need to free the list properly when we do get to register them. This showed up in valgrind as leaked GList structs. --- gtk/a11y/gtkatspiroot.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gtk/a11y/gtkatspiroot.c b/gtk/a11y/gtkatspiroot.c index bffc632c18..1335c7fb24 100644 --- a/gtk/a11y/gtkatspiroot.c +++ b/gtk/a11y/gtkatspiroot.c @@ -106,6 +106,7 @@ gtk_at_spi_root_dispose (GObject *gobject) g_clear_object (&self->cache); g_clear_object (&self->connection); + g_clear_pointer (&self->queued_contexts, g_list_free); G_OBJECT_CLASS (gtk_at_spi_root_parent_class)->dispose (gobject); } @@ -517,7 +518,8 @@ on_registration_reply (GObject *gobject, /* Drain the list of queued GtkAtSpiContexts, and add them to the cache */ if (self->queued_contexts != NULL) { - for (GList *l = g_list_reverse (self->queued_contexts); l != NULL; l = l->next) + self->queued_contexts = g_list_reverse (self->queued_contexts); + for (GList *l = self->queued_contexts; l != NULL; l = l->next) { if (data->register_func != NULL) data->register_func (self, l->data); -- 2.30.2