[libosinfo PATCH] Use g_list_free_full where easily possible

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Use g_list_free_full instead of g_list_foreach + g_list_free, so the
lists are cleared with a single call.

test-isodetect gets a void* wrapper, so there is no need to add casts
everywhere.
---
 osinfo/osinfo_deployment.c |  8 +-------
 osinfo/osinfo_loader.c     |  3 +--
 tests/test-isodetect.c     | 17 +++++++++++------
 3 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/osinfo/osinfo_deployment.c b/osinfo/osinfo_deployment.c
index 7191ac3..a79b32f 100644
--- a/osinfo/osinfo_deployment.c
+++ b/osinfo/osinfo_deployment.c
@@ -114,18 +114,12 @@ osinfo_deployment_get_property(GObject *object,
 
 
 
-static void osinfo_device_link_free(gpointer data, gpointer opaque G_GNUC_UNUSED)
-{
-    g_object_unref(OSINFO_DEVICELINK(data));
-}
-
 static void
 osinfo_deployment_finalize(GObject *object)
 {
     OsinfoDeployment *deployment = OSINFO_DEPLOYMENT(object);
 
-    g_list_foreach(deployment->priv->deviceLinks, osinfo_device_link_free, NULL);
-    g_list_free(deployment->priv->deviceLinks);
+    g_list_free_full(deployment->priv->deviceLinks, g_object_unref);
 
     g_object_unref(deployment->priv->os);
     g_object_unref(deployment->priv->platform);
diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
index dbff95b..77ca5ea 100644
--- a/osinfo/osinfo_loader.c
+++ b/osinfo/osinfo_loader.c
@@ -2002,8 +2002,7 @@ static void osinfo_loader_entity_files_free(OsinfoLoaderEntityFiles *files)
 {
     if (!files)
         return;
-    g_list_foreach(files->extensions, (GFunc)g_object_unref, NULL);
-    g_list_free(files->extensions);
+    g_list_free_full(files->extensions, g_object_unref);
     if (files->master)
         g_object_unref(files->master);
     g_free(files);
diff --git a/tests/test-isodetect.c b/tests/test-isodetect.c
index 717b822..db7b108 100644
--- a/tests/test-isodetect.c
+++ b/tests/test-isodetect.c
@@ -45,6 +45,14 @@ static void free_iso(struct ISOInfo *info)
     g_free(info);
 }
 
+/* void* wrapper for free_iso, so it can be used where a void* parameter
+ * is required (e.g. g_list_free_full), with no need for casts.
+ */
+static void free_iso_void(void *info)
+{
+    free_iso((struct ISOInfo *)info);
+}
+
 static gboolean load_langs(GFile *file, struct ISOInfo *info, GError **error)
 {
     char *path;
@@ -243,8 +251,7 @@ static GList *load_distro(GFile *dir, const gchar *shortid, GError **error) {
     return ret;
 
  error:
-    g_list_foreach(ret, (GFunc)free_iso, NULL);
-    g_list_free(ret);
+    g_list_free_full(ret, free_iso_void);
     ret = NULL;
     goto cleanup;
 }
@@ -289,8 +296,7 @@ static GList *load_distros(GFile *dir, GError **error)
     return ret;
 
  error:
-    g_list_foreach(ret, (GFunc)free_iso, NULL);
-    g_list_free(ret);
+    g_list_free_full(ret, free_iso_void);
     ret = NULL;
     goto cleanup;
 }
@@ -410,8 +416,7 @@ static void test_one(const gchar *vendor)
         test_langs(info);
     }
 
-    g_list_foreach(isos, (GFunc)free_iso, NULL);
-    g_list_free(isos);
+    g_list_free_full(isos, free_iso_void);
 
     g_object_unref(loader);
 }
-- 
2.17.2

_______________________________________________
Libosinfo mailing list
Libosinfo@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libosinfo



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Fedora Users]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux