Browse Source

Use g_slist_free_full().

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Andrew Borodin 11 years ago
parent
commit
90dc6fffac
7 changed files with 31 additions and 11 deletions
  1. 21 0
      lib/glibcompat.c
  2. 4 0
      lib/glibcompat.h
  3. 1 2
      src/editor/syntax.c
  4. 2 3
      src/filemanager/file.c
  5. 1 2
      src/help.c
  6. 1 2
      src/vfs/cpio/cpio.c
  7. 1 2
      src/vfs/ftpfs/ftpfs.c

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

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

+ 1 - 2
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 ();

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

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

+ 1 - 2
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;

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