a11y: Fix a memory leak
authorMatthias Clasen <mclasen@redhat.com>
Fri, 12 Aug 2022 16:01:42 +0000 (12:01 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 12 Aug 2022 16:01:42 +0000 (12:01 -0400)
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

index bffc632c18b4a2b5f57be86e9949646dcf862033..1335c7fb24c150b113706508d1f2433653c75e5d 100644 (file)
@@ -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);