Browse Source

Use g_queue_clear_full().

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Andrew Borodin 6 years ago
parent
commit
7fb06b3105
3 changed files with 30 additions and 2 deletions
  1. 25 0
      lib/glibcompat.c
  2. 4 0
      lib/glibcompat.h
  3. 1 2
      src/filemanager/find.c

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

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

+ 1 - 2
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);
 }
 
 /* --------------------------------------------------------------------------------------------- */