[gtk/leak-fixes-46: 1/5] a11y: Fix a memory leak




commit 412e77d500e435d3887fc9caacdeb53ca66de6ca
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Aug 12 12:01:42 2022 -0400

    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);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]