From 1ff4005228ad2c0a9c7fa53f6143c682ae65dac9 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Sat, 3 Dec 2016 20:17:21 +0300 Subject: [PATCH] Use g_queue_free_full(). Signed-off-by: Andrew Borodin --- lib/glibcompat.c | 21 +++++++++++++++++++++ lib/glibcompat.h | 4 ++++ lib/widget/listbox.c | 5 ++--- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/glibcompat.c b/lib/glibcompat.c index bdcb82174..1d48f034c 100644 --- a/lib/glibcompat.c +++ b/lib/glibcompat.c @@ -87,6 +87,27 @@ g_list_free_full (GList * list, GDestroyNotify free_func) g_list_free (list); } +/* --------------------------------------------------------------------------------------------- */ + #endif /* ! GLIB_CHECK_VERSION (2, 28, 0) */ +#if ! GLIB_CHECK_VERSION (2, 32, 0) +/** + * g_queue_free_full: + * @queue: a pointer to a #GQueue + * @free_func: the function to be called to free each element's data + * + * Convenience method, which frees all the memory used by a #GQueue, + * and calls the specified destroy function on every element's data. + * + * Since: 2.32 + */ +void +g_queue_free_full (GQueue * queue, GDestroyNotify free_func) +{ + g_queue_foreach (queue, (GFunc) free_func, NULL); + g_queue_free (queue); +} +#endif /* ! GLIB_CHECK_VERSION (2, 32, 0) */ + /* --------------------------------------------------------------------------------------------- */ diff --git a/lib/glibcompat.h b/lib/glibcompat.h index 3f2063758..0b62dd204 100644 --- a/lib/glibcompat.h +++ b/lib/glibcompat.h @@ -16,6 +16,10 @@ 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, 32, 0) +void g_queue_free_full (GQueue * queue, GDestroyNotify free_func); +#endif /* ! GLIB_CHECK_VERSION (2, 32, 0) */ + /*** inline functions ****************************************************************************/ #endif /* MC_GLIBCOMPAT_H */ diff --git a/lib/widget/listbox.c b/lib/widget/listbox.c index ab43b6c52..118ce3438 100644 --- a/lib/widget/listbox.c +++ b/lib/widget/listbox.c @@ -759,11 +759,10 @@ listbox_remove_list (WListbox * l) { if (l->list != NULL) { - g_queue_foreach (l->list, (GFunc) listbox_entry_free, NULL); - g_queue_free (l->list); + g_queue_free_full (l->list, (GDestroyNotify) listbox_entry_free); + l->list = NULL; } - l->list = NULL; l->pos = l->top = 0; } }