Use g_clear_slist() and g_clear_list().

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2019-12-01 14:59:35 +03:00
parent f85c1c898e
commit 57c303eeaf
8 changed files with 78 additions and 17 deletions

View File

@ -91,6 +91,71 @@ g_list_free_full (GList * list, GDestroyNotify free_func)
#endif /* ! GLIB_CHECK_VERSION (2, 28, 0) */
#if ! GLIB_CHECK_VERSION (2, 64, 0)
/**
* g_clear_slist: (skip)
* @slist_ptr: (not nullable): a #GSList return location
* @destroy: (nullable): the function to pass to g_slist_free_full() or NULL to not free elements
*
* Clears a pointer to a #GSList, freeing it and, optionally, freeing its elements using @destroy.
*
* @slist_ptr must be a valid pointer. If @slist_ptr points to a null #GSList, this does nothing.
*
* Since: 2.64
*/
void
g_clear_slist (GSList ** slist_ptr, GDestroyNotify destroy)
{
GSList *slist;
slist = *slist_ptr;
if (slist != NULL)
{
*slist_ptr = NULL;
if (destroy != NULL)
g_slist_free_full (slist, destroy);
else
g_slist_free (slist);
}
}
/* --------------------------------------------------------------------------------------------- */
/**
* g_clear_list:
* @list_ptr: (not nullable): a #GList return location
* @destroy: (nullable): the function to pass to g_list_free_full() or NULL to not free elements
*
* Clears a pointer to a #GList, freeing it and, optionally, freeing its elements using @destroy.
*
* @list_ptr must be a valid pointer. If @list_ptr points to a null #GList, this does nothing.
*
* Since: 2.64
*/
void
g_clear_list (GList ** list_ptr, GDestroyNotify destroy)
{
GList *list;
list = *list_ptr;
if (list != NULL)
{
*list_ptr = NULL;
if (destroy != NULL)
g_list_free_full (list, destroy);
else
g_list_free (list);
}
}
/* --------------------------------------------------------------------------------------------- */
#endif /* ! GLIB_CHECK_VERSION (2, 64, 0) */
#if ! GLIB_CHECK_VERSION (2, 32, 0)
/**
* g_queue_free_full:

View File

@ -16,6 +16,11 @@ 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) */
#if ! GLIB_CHECK_VERSION (2, 64, 0)
void g_clear_slist (GSList ** slist_ptr, GDestroyNotify destroy);
void g_clear_list (GList ** list_ptr, GDestroyNotify destroy);
#endif /* ! GLIB_CHECK_VERSION (2, 64, 0) */
#if ! GLIB_CHECK_VERSION (2, 32, 0)
void g_queue_free_full (GQueue * queue, GDestroyNotify free_func);
#endif /* ! GLIB_CHECK_VERSION (2, 32, 0) */

View File

@ -622,11 +622,10 @@ menubar_refresh (WMenuBar * menubar)
/* --------------------------------------------------------------------------------------------- */
static void
static inline void
menubar_free_menu (WMenuBar * menubar)
{
if (menubar->menu != NULL)
g_list_free_full (menubar->menu, (GDestroyNotify) destroy_menu);
g_clear_list (&menubar->menu, (GDestroyNotify) destroy_menu);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -1448,8 +1448,7 @@ edit_free_syntax_rules (WEdit * edit)
g_ptr_array_foreach (edit->rules, (GFunc) context_rule_free, NULL);
g_ptr_array_free (edit->rules, TRUE);
edit->rules = NULL;
g_slist_free_full (edit->syntax_marker, g_free);
edit->syntax_marker = NULL;
g_clear_slist (&edit->syntax_marker, g_free);
tty_color_free_all_tmp ();
}

View File

@ -1461,8 +1461,7 @@ void
free_my_statfs (void)
{
#ifdef HAVE_INFOMOUNT_LIST
g_slist_free_full (mc_mount_list, (GDestroyNotify) free_mount_entry);
mc_mount_list = NULL;
g_clear_slist (&mc_mount_list, (GDestroyNotify) free_mount_entry);
#endif /* HAVE_INFOMOUNT_LIST */
}

View File

@ -393,8 +393,7 @@ end_link_area (int x, int y)
static void
clear_link_areas (void)
{
g_slist_free_full (link_area, g_free);
link_area = NULL;
g_clear_slist (&link_area, g_free);
inside_link_area = FALSE;
}

View File

@ -217,8 +217,8 @@ cpio_free_archive (struct vfs_class *me, struct vfs_s_super *super)
mc_close (arch->fd);
arch->fd = -1;
}
g_slist_free_full (arch->deferred, g_free);
arch->deferred = NULL;
g_clear_slist (&arch->deferred, g_free);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -224,12 +224,7 @@ smbfs_auth_free (struct smb_authinfo const *a)
static void
smbfs_auth_free_all (void)
{
if (auth_list)
{
g_slist_foreach (auth_list, (GFunc) smbfs_auth_free, 0);
g_slist_free (auth_list);
auth_list = 0;
}
g_clear_slist (&auth_list, (GDestroyNotify) smbfs_auth_free);
}
/* --------------------------------------------------------------------------------------------- */