From 90dc6fffac6ce94047a52a2565d9ad2e2d4b74dd Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Mon, 4 Nov 2013 11:56:14 +0400 Subject: [PATCH] Use g_slist_free_full(). Signed-off-by: Andrew Borodin --- lib/glibcompat.c | 21 +++++++++++++++++++++ lib/glibcompat.h | 4 ++++ src/editor/syntax.c | 3 +-- src/filemanager/file.c | 5 ++--- src/help.c | 3 +-- src/vfs/cpio/cpio.c | 3 +-- src/vfs/ftpfs/ftpfs.c | 3 +-- 7 files changed, 31 insertions(+), 11 deletions(-) diff --git a/lib/glibcompat.c b/lib/glibcompat.c index 9641806bd..290600c32 100644 --- a/lib/glibcompat.c +++ b/lib/glibcompat.c @@ -96,3 +96,24 @@ g_strcmp0 (const char *str1, const char *str2) #endif /* ! GLIB_CHECK_VERSION (2, 16, 0) */ /* --------------------------------------------------------------------------------------------- */ + +#if ! GLIB_CHECK_VERSION (2, 28, 0) +/** + * g_slist_free_full: + * @list: a pointer to a #GSList + * @free_func: the function to be called to free each element's data + * + * Convenience method, which frees all the memory used by a #GSList, and + * calls the specified destroy function on every element's data. + * + * Since: 2.28 + **/ +void +g_slist_free_full (GSList * list, GDestroyNotify free_func) +{ + g_slist_foreach (list, (GFunc) free_func, NULL); + g_slist_free (list); +} +#endif /* ! GLIB_CHECK_VERSION (2, 28, 0) */ + +/* --------------------------------------------------------------------------------------------- */ diff --git a/lib/glibcompat.h b/lib/glibcompat.h index b4768e4be..6c93b03d7 100644 --- a/lib/glibcompat.h +++ b/lib/glibcompat.h @@ -19,6 +19,10 @@ gboolean g_unichar_iszerowidth (gunichar); int g_strcmp0 (const char *str1, const char *str2); #endif /* ! GLIB_CHECK_VERSION (2, 16, 0) */ +#if ! GLIB_CHECK_VERSION (2, 28, 0) +void g_slist_free_full (GSList * list, GDestroyNotify free_func); +#endif /* ! GLIB_CHECK_VERSION (2, 28, 0) */ + /*** inline functions ****************************************************************************/ #endif /* MC_GLIBCOMPAT_H */ diff --git a/src/editor/syntax.c b/src/editor/syntax.c index 84f832942..c5df897ef 100644 --- a/src/editor/syntax.c +++ b/src/editor/syntax.c @@ -1450,8 +1450,7 @@ edit_free_syntax_rules (WEdit * edit) MC_PTR_FREE (edit->rules[i]); } - g_slist_foreach (edit->syntax_marker, (GFunc) g_free, NULL); - g_slist_free (edit->syntax_marker); + g_slist_free_full (edit->syntax_marker, g_free); edit->syntax_marker = NULL; MC_PTR_FREE (edit->rules); tty_color_free_all_tmp (); diff --git a/src/filemanager/file.c b/src/filemanager/file.c index a5dad18da..c61bae5d5 100644 --- a/src/filemanager/file.c +++ b/src/filemanager/file.c @@ -245,11 +245,10 @@ free_link (void *data) /* --------------------------------------------------------------------------------------------- */ -static void * +static inline void * free_linklist (GSList * lp) { - g_slist_foreach (lp, (GFunc) free_link, NULL); - g_slist_free (lp); + g_slist_free_full (lp, free_link); return NULL; } diff --git a/src/help.c b/src/help.c index 326a1465b..d57cf9131 100644 --- a/src/help.c +++ b/src/help.c @@ -394,8 +394,7 @@ end_link_area (int x, int y) static void clear_link_areas (void) { - g_slist_foreach (link_area, (GFunc) g_free, NULL); - g_slist_free (link_area); + g_slist_free_full (link_area, g_free); link_area = NULL; inside_link_area = FALSE; } diff --git a/src/vfs/cpio/cpio.c b/src/vfs/cpio/cpio.c index 1075ea37d..437c887fc 100644 --- a/src/vfs/cpio/cpio.c +++ b/src/vfs/cpio/cpio.c @@ -205,8 +205,7 @@ cpio_free_archive (struct vfs_class *me, struct vfs_s_super *super) if (arch->fd != -1) mc_close (arch->fd); arch->fd = -1; - g_slist_foreach (arch->deferred, (GFunc) g_free, NULL); - g_slist_free (arch->deferred); + g_slist_free_full (arch->deferred, g_free); arch->deferred = NULL; g_free (super->data); super->data = NULL; diff --git a/src/vfs/ftpfs/ftpfs.c b/src/vfs/ftpfs/ftpfs.c index 7ea46acdd..c1963aff6 100644 --- a/src/vfs/ftpfs/ftpfs.c +++ b/src/vfs/ftpfs/ftpfs.c @@ -2236,8 +2236,7 @@ ftpfs_done (struct vfs_class *me) { (void) me; - g_slist_foreach (no_proxy, (GFunc) g_free, NULL); - g_slist_free (no_proxy); + g_slist_free_full (no_proxy, g_free); g_free (ftpfs_anonymous_passwd); g_free (ftpfs_proxy_host);