[anjuta] file-loader: Fix leak of GtkRecentInfos in the RecentChooserMenu.



commit 2e5d8a7121cd146d89acff820cfeb19261de67ea
Author: Carl-Anton Ingmarsson <ca ingmarsson gmail com>
Date:   Wed Jan 9 15:45:10 2013 +0100

    file-loader: Fix leak of GtkRecentInfos in the RecentChooserMenu.
    
    The list of GtkRecentInfos in MenuPopulateData would leak if the idle source was removed
    using g_source_remove(). Fix this by consolidating all the cleanup code into the
    idle_populate_clean_up() function. Also fix so that the cleanup is always run and not
    only when populate_id has already been set to 0.

 plugins/file-loader/anjuta-recent-chooser-menu.c |   23 +++++++++------------
 1 files changed, 10 insertions(+), 13 deletions(-)
---
diff --git a/plugins/file-loader/anjuta-recent-chooser-menu.c b/plugins/file-loader/anjuta-recent-chooser-menu.c
index ab61fc3..8858ed9 100644
--- a/plugins/file-loader/anjuta-recent-chooser-menu.c
+++ b/plugins/file-loader/anjuta-recent-chooser-menu.c
@@ -391,9 +391,8 @@ _gtk_recent_chooser_get_items (GtkRecentChooser  *chooser,
       
       l = clamp->next;
       clamp->next = NULL;
-    
-      g_list_foreach (l, (GFunc) gtk_recent_info_unref, NULL);
-      g_list_free (l);
+
+      g_list_free_full (l, (GDestroyNotify)gtk_recent_info_unref);
     }
 
   return items;
@@ -1197,9 +1196,6 @@ check_and_return:
 
   if (pdata->loaded_items == pdata->n_items)
     {
-      g_list_foreach (pdata->items, (GFunc) gtk_recent_info_unref, NULL);
-      g_list_free (pdata->items);
-
       priv->populate_id = 0;
 
       retval = FALSE;
@@ -1215,17 +1211,18 @@ idle_populate_clean_up (gpointer data)
 {
   MenuPopulateData *pdata = data;
 
-  if (pdata->menu->priv->populate_id == 0)
-    {
+    if (!pdata->displayed_items)
       /* show the placeholder in case no item survived
        * the filtering process in the idle loop
        */
-      if (!pdata->displayed_items)
         gtk_widget_show (pdata->placeholder);
-      g_object_unref (pdata->placeholder);
 
-      g_slice_free (MenuPopulateData, data);
-    }
+    g_object_unref (pdata->placeholder);
+
+    if (pdata->items)
+        g_list_free_full(pdata->items, (GDestroyNotify)gtk_recent_info_unref);
+
+    g_slice_free (MenuPopulateData, data);
 }
 
 static void
@@ -1256,7 +1253,7 @@ anjuta_recent_chooser_menu_populate (AnjutaRecentChooserMenu *menu)
   priv->populate_id = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 30,
   					         idle_populate_func,
 					         pdata,
-                                                 idle_populate_clean_up);
+					         idle_populate_clean_up);
 }
 
 /* bounce activate signal from the recent menu item widget 



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