Browse Source

Use g_list_free_full().

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Andrew Borodin 11 years ago
parent
commit
29f6dd2a84

+ 20 - 0
lib/glibcompat.c

@@ -114,6 +114,26 @@ g_slist_free_full (GSList * list, GDestroyNotify free_func)
     g_slist_foreach (list, (GFunc) free_func, NULL);
     g_slist_free (list);
 }
+
+/* --------------------------------------------------------------------------------------------- */
+
+/**
+ * g_list_free_full:
+ * @list: a pointer to a #GList
+ * @free_func: the function to be called to free each element's data
+ *
+ * Convenience method, which frees all the memory used by a #GList, and
+ * calls the specified destroy function on every element's data.
+ *
+ * Since: 2.28
+ */
+void
+g_list_free_full (GList * list, GDestroyNotify free_func)
+{
+    g_list_foreach (list, (GFunc) free_func, NULL);
+    g_list_free (list);
+}
+
 #endif /* ! GLIB_CHECK_VERSION (2, 28, 0) */
 
 /* --------------------------------------------------------------------------------------------- */

+ 1 - 0
lib/glibcompat.h

@@ -21,6 +21,7 @@ int g_strcmp0 (const char *str1, const char *str2);
 
 #if ! GLIB_CHECK_VERSION (2, 28, 0)
 void g_slist_free_full (GSList * list, GDestroyNotify free_func);
+void g_list_free_full (GList * list, GDestroyNotify free_func);
 #endif /* ! GLIB_CHECK_VERSION (2, 28, 0) */
 
 /*** inline functions ****************************************************************************/

+ 1 - 2
lib/widget/dialog.c

@@ -1266,8 +1266,7 @@ dlg_destroy (WDialog * h)
     /* if some widgets have history, save all history at one moment here */
     dlg_save_history (h);
     dlg_broadcast_msg (h, MSG_DESTROY);
-    g_list_foreach (h->widgets, (GFunc) g_free, NULL);
-    g_list_free (h->widgets);
+    g_list_free_full (h->widgets, g_free);
     mc_event_group_del (h->event_group);
     g_free (h->event_group);
     g_free (h->title);

+ 1 - 2
lib/widget/history.c

@@ -383,8 +383,7 @@ history_show (GList ** history, Widget * widget, int current)
 
     dlg_destroy (query_dlg);
 
-    g_list_foreach (*history, (GFunc) g_free, NULL);
-    g_list_free (*history);
+    g_list_free_full (*history, g_free);
     *history = g_list_last (z);
 
     return r;

+ 1 - 2
lib/widget/input.c

@@ -900,8 +900,7 @@ input_destroy (WInput * in)
     {
         /* history is already saved before this moment */
         in->history.list = g_list_first (in->history.list);
-        g_list_foreach (in->history.list, (GFunc) g_free, NULL);
-        g_list_free (in->history.list);
+        g_list_free_full (in->history.list, g_free);
     }
     g_free (in->history.name);
     g_free (in->buffer);

+ 1 - 2
lib/widget/listbox.c

@@ -688,8 +688,7 @@ listbox_remove_list (WListbox * l)
 {
     if ((l != NULL) && (l->count != 0))
     {
-        g_list_foreach (l->list, (GFunc) listbox_entry_free, NULL);
-        g_list_free (l->list);
+        g_list_free_full (l->list, listbox_entry_free);
         l->list = NULL;
         l->count = l->pos = l->top = 0;
     }

+ 3 - 6
lib/widget/menu.c

@@ -828,8 +828,7 @@ void
 destroy_menu (menu_t * menu)
 {
     release_hotkey (menu->text);
-    g_list_foreach (menu->entries, (GFunc) menu_entry_free, NULL);
-    g_list_free (menu->entries);
+    g_list_free_full (menu->entries, (GDestroyNotify) menu_entry_free);
     g_free (menu->help_node);
     g_free (menu);
 }
@@ -860,10 +859,8 @@ menubar_set_menu (WMenuBar * menubar, GList * menu)
 {
     /* delete previous menu */
     if (menubar->menu != NULL)
-    {
-        g_list_foreach (menubar->menu, (GFunc) destroy_menu, NULL);
-        g_list_free (menubar->menu);
-    }
+        g_list_free_full (menubar->menu, (GDestroyNotify) destroy_menu);
+
     /* add new menu */
     menubar->is_active = FALSE;
     menubar->is_dropped = FALSE;

+ 1 - 2
src/editor/editcmd.c

@@ -2708,8 +2708,7 @@ edit_search_cmd (WEdit * edit, gboolean again)
             edit->last_search_string = (char *) history->data;
             history->data = NULL;
             history = g_list_first (history);
-            g_list_foreach (history, (GFunc) g_free, NULL);
-            g_list_free (history);
+            g_list_free_full (history, g_free);
 
 #ifdef HAVE_CHARSET
             edit->search = mc_search_new (edit->last_search_string, -1, cp_source);

+ 1 - 2
src/filemanager/panel.c

@@ -1473,8 +1473,7 @@ panel_destroy (WPanel * p)
     {
         /* directory history is already saved before this moment */
         p->dir_history = g_list_first (p->dir_history);
-        g_list_foreach (p->dir_history, (GFunc) g_free, NULL);
-        g_list_free (p->dir_history);
+        g_list_free_full (p->dir_history, g_free);
     }
     g_free (p->hist_name);
 

+ 1 - 2
src/filemanager/treestore.c

@@ -900,8 +900,7 @@ tree_store_end_check (void)
     vfs_path_free (ts.check_name);
     ts.check_name = NULL;
 
-    g_list_foreach (the_queue, (GFunc) vfs_path_free, NULL);
-    g_list_free (the_queue);
+    g_list_free_full (the_queue, (GDestroyNotify) vfs_path_free);
 }
 
 /* --------------------------------------------------------------------------------------------- */

Some files were not shown because too many files changed in this diff