Use g_list_free_full().

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2013-11-04 12:09:13 +04:00
parent 90dc6fffac
commit 29f6dd2a84
12 changed files with 34 additions and 26 deletions

View File

@ -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) */
/* --------------------------------------------------------------------------------------------- */

View File

@ -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 ****************************************************************************/

View File

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

View File

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

View File

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

View File

@ -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;
}

View File

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

View File

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

View File

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

View File

@ -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);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -469,10 +469,8 @@ main (int argc, char *argv[])
if (mc_global.mc_run_mode != MC_RUN_EDITOR)
g_free (mc_run_param0);
else
{
g_list_foreach ((GList *) mc_run_param0, (GFunc) mcedit_arg_free, NULL);
g_list_free ((GList *) mc_run_param0);
}
g_list_free_full ((GList *) mc_run_param0, (GDestroyNotify) mcedit_arg_free);
g_free (mc_run_param1);
g_free (saved_other_dir);

View File

@ -143,8 +143,7 @@ mcview_continue_search_cmd (mcview_t * view)
{
view->last_search_string = (gchar *) g_strdup (history->data);
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
view->search = mc_search_new (view->last_search_string, -1, cp_source);