From 7fb06b310574202ccae984e34488fb4a39808ebb Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Sun, 13 Jan 2019 13:20:04 +0300 Subject: [PATCH] Use g_queue_clear_full(). Signed-off-by: Andrew Borodin --- lib/glibcompat.c | 25 +++++++++++++++++++++++++ lib/glibcompat.h | 4 ++++ src/filemanager/find.c | 3 +-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/lib/glibcompat.c b/lib/glibcompat.c index 856b3f67b..d2ca0b6eb 100644 --- a/lib/glibcompat.c +++ b/lib/glibcompat.c @@ -111,3 +111,28 @@ g_queue_free_full (GQueue * queue, GDestroyNotify free_func) #endif /* ! GLIB_CHECK_VERSION (2, 32, 0) */ /* --------------------------------------------------------------------------------------------- */ + +#if ! GLIB_CHECK_VERSION (2, 60, 0) +/** + * g_queue_clear_full: + * @queue: a pointer to a #GQueue + * @free_func: (nullable): the function to be called to free memory allocated + * + * Convenience method, which frees all the memory used by a #GQueue, + * and calls the provided @free_func on each item in the #GQueue. + * + * Since: 2.60 + */ +void +g_queue_clear_full (GQueue * queue, GDestroyNotify free_func) +{ + g_return_if_fail (queue != NULL); + + if (free_func != NULL) + g_queue_foreach (queue, (GFunc) free_func, NULL); + + g_queue_clear (queue); +} +#endif /* ! GLIB_CHECK_VERSION (2, 60, 0) */ + +/* --------------------------------------------------------------------------------------------- */ diff --git a/lib/glibcompat.h b/lib/glibcompat.h index 0b62dd204..d61b76aef 100644 --- a/lib/glibcompat.h +++ b/lib/glibcompat.h @@ -20,6 +20,10 @@ void g_list_free_full (GList * list, GDestroyNotify free_func); void g_queue_free_full (GQueue * queue, GDestroyNotify free_func); #endif /* ! GLIB_CHECK_VERSION (2, 32, 0) */ +#if ! GLIB_CHECK_VERSION (2, 60, 0) +void g_queue_clear_full (GQueue * queue, GDestroyNotify free_func); +#endif /* ! GLIB_CHECK_VERSION (2, 60, 0) */ + /*** inline functions ****************************************************************************/ #endif /* MC_GLIBCOMPAT_H */ diff --git a/src/filemanager/find.c b/src/filemanager/find.c index 377a12691..e173dfcc5 100644 --- a/src/filemanager/find.c +++ b/src/filemanager/find.c @@ -890,8 +890,7 @@ pop_directory (void) static void clear_stack (void) { - g_queue_foreach (&dir_queue, (GFunc) vfs_path_free, NULL); - g_queue_clear (&dir_queue); + g_queue_clear_full (&dir_queue, (GDestroyNotify) vfs_path_free); } /* --------------------------------------------------------------------------------------------- */