Browse Source

Use g_queue_free_full().

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Andrew Borodin 8 years ago
parent
commit
1ff4005228
3 changed files with 27 additions and 3 deletions
  1. 21 0
      lib/glibcompat.c
  2. 4 0
      lib/glibcompat.h
  3. 2 3
      lib/widget/listbox.c

+ 21 - 0
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) */
+
 /* --------------------------------------------------------------------------------------------- */

+ 4 - 0
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 */

+ 2 - 3
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;
     }
 }