Blame SOURCES/0001-Use-g_list_free_full-where-easily-possible.patch

0a59fa
From f4bae6ba2f20caa6e3bf6fa7a7ea52eaf2180beb Mon Sep 17 00:00:00 2001
0a59fa
From: Pino Toscano <ptoscano@redhat.com>
0a59fa
Date: Thu, 20 Dec 2018 10:56:25 +0100
0a59fa
Subject: [PATCH] Use g_list_free_full where easily possible
0a59fa
MIME-Version: 1.0
0a59fa
Content-Type: text/plain; charset=UTF-8
0a59fa
Content-Transfer-Encoding: 8bit
0a59fa
0a59fa
Use g_list_free_full instead of g_list_foreach + g_list_free, so the
0a59fa
lists are cleared with a single call.
0a59fa
0a59fa
test-isodetect gets a void* wrapper, so there is no need to add casts
0a59fa
everywhere.
0a59fa
0a59fa
Reviewed-by: Fabiano FidĂȘncio <fidencio@redhat.com>
0a59fa
(cherry picked from commit 4fe69c9fe31befe3caa55bbaac0bcfa5e605f028)
0a59fa
---
0a59fa
 osinfo/osinfo_deployment.c    |  8 +-------
0a59fa
 osinfo/osinfo_entity.c        |  7 +------
0a59fa
 osinfo/osinfo_filter.c        |  9 +--------
0a59fa
 osinfo/osinfo_loader.c        |  3 +--
0a59fa
 osinfo/osinfo_os.c            |  8 +-------
0a59fa
 osinfo/osinfo_platform.c      |  8 +-------
0a59fa
 osinfo/osinfo_product.c       |  5 ++---
0a59fa
 osinfo/osinfo_productfilter.c |  9 +--------
0a59fa
 tests/test-isodetect.c        | 17 +++++++++++------
0a59fa
 9 files changed, 20 insertions(+), 54 deletions(-)
0a59fa
0a59fa
diff --git a/osinfo/osinfo_deployment.c b/osinfo/osinfo_deployment.c
0a59fa
index 7191ac3..a79b32f 100644
0a59fa
--- a/osinfo/osinfo_deployment.c
0a59fa
+++ b/osinfo/osinfo_deployment.c
0a59fa
@@ -114,18 +114,12 @@ osinfo_deployment_get_property(GObject *object,
0a59fa
 
0a59fa
 
0a59fa
 
0a59fa
-static void osinfo_device_link_free(gpointer data, gpointer opaque G_GNUC_UNUSED)
0a59fa
-{
0a59fa
-    g_object_unref(OSINFO_DEVICELINK(data));
0a59fa
-}
0a59fa
-
0a59fa
 static void
0a59fa
 osinfo_deployment_finalize(GObject *object)
0a59fa
 {
0a59fa
     OsinfoDeployment *deployment = OSINFO_DEPLOYMENT(object);
0a59fa
 
0a59fa
-    g_list_foreach(deployment->priv->deviceLinks, osinfo_device_link_free, NULL);
0a59fa
-    g_list_free(deployment->priv->deviceLinks);
0a59fa
+    g_list_free_full(deployment->priv->deviceLinks, g_object_unref);
0a59fa
 
0a59fa
     g_object_unref(deployment->priv->os);
0a59fa
     g_object_unref(deployment->priv->platform);
0a59fa
diff --git a/osinfo/osinfo_entity.c b/osinfo/osinfo_entity.c
0a59fa
index 20b9115..a776baa 100644
0a59fa
--- a/osinfo/osinfo_entity.c
0a59fa
+++ b/osinfo/osinfo_entity.c
0a59fa
@@ -146,15 +146,10 @@ osinfo_entity_class_init(OsinfoEntityClass *klass)
0a59fa
     g_type_class_add_private(klass, sizeof(OsinfoEntityPrivate));
0a59fa
 }
0a59fa
 
0a59fa
-static void osinfo_entity_param_value_free(gpointer value, gpointer opaque G_GNUC_UNUSED)
0a59fa
-{
0a59fa
-    g_free(value);
0a59fa
-}
0a59fa
 
0a59fa
 static void osinfo_entity_param_values_free(gpointer values)
0a59fa
 {
0a59fa
-    g_list_foreach(values, osinfo_entity_param_value_free, NULL);
0a59fa
-    g_list_free(values);
0a59fa
+    g_list_free_full(values, g_free);
0a59fa
 }
0a59fa
 
0a59fa
 
0a59fa
diff --git a/osinfo/osinfo_filter.c b/osinfo/osinfo_filter.c
0a59fa
index 7f06d43..1c38735 100644
0a59fa
--- a/osinfo/osinfo_filter.c
0a59fa
+++ b/osinfo/osinfo_filter.c
0a59fa
@@ -88,17 +88,10 @@ OsinfoFilter *osinfo_filter_new(void)
0a59fa
 }
0a59fa
 
0a59fa
 
0a59fa
-static void
0a59fa
-osinfo_filter_prop_constraint_free(gpointer value, gpointer opaque G_GNUC_UNUSED)
0a59fa
-{
0a59fa
-    g_free(value);
0a59fa
-}
0a59fa
-
0a59fa
 static void
0a59fa
 osinfo_filter_prop_constraints_free(gpointer props)
0a59fa
 {
0a59fa
-    g_list_foreach(props, osinfo_filter_prop_constraint_free, NULL);
0a59fa
-    g_list_free(props);
0a59fa
+    g_list_free_full(props, g_free);
0a59fa
 }
0a59fa
 
0a59fa
 
0a59fa
diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
0a59fa
index dca23f1..d580b66 100644
0a59fa
--- a/osinfo/osinfo_loader.c
0a59fa
+++ b/osinfo/osinfo_loader.c
0a59fa
@@ -1898,8 +1898,7 @@ static void osinfo_loader_entity_files_free(OsinfoLoaderEntityFiles *files)
0a59fa
 {
0a59fa
     if (!files)
0a59fa
         return;
0a59fa
-    g_list_foreach(files->extensions, (GFunc)g_object_unref, NULL);
0a59fa
-    g_list_free(files->extensions);
0a59fa
+    g_list_free_full(files->extensions, g_object_unref);
0a59fa
     if (files->master)
0a59fa
         g_object_unref(files->master);
0a59fa
     g_free(files);
0a59fa
diff --git a/osinfo/osinfo_os.c b/osinfo/osinfo_os.c
0a59fa
index 4f74331..b77c687 100644
0a59fa
--- a/osinfo/osinfo_os.c
0a59fa
+++ b/osinfo/osinfo_os.c
0a59fa
@@ -75,11 +75,6 @@ enum {
0a59fa
 
0a59fa
 static void osinfo_os_finalize(GObject *object);
0a59fa
 
0a59fa
-static void osinfo_device_link_free(gpointer data, gpointer opaque G_GNUC_UNUSED)
0a59fa
-{
0a59fa
-    g_object_unref(OSINFO_DEVICELINK(data));
0a59fa
-}
0a59fa
-
0a59fa
 static void
0a59fa
 osinfo_os_get_property(GObject    *object,
0a59fa
                         guint       property_id,
0a59fa
@@ -112,8 +107,7 @@ osinfo_os_finalize(GObject *object)
0a59fa
 {
0a59fa
     OsinfoOs *os = OSINFO_OS(object);
0a59fa
 
0a59fa
-    g_list_foreach(os->priv->deviceLinks, osinfo_device_link_free, NULL);
0a59fa
-    g_list_free(os->priv->deviceLinks);
0a59fa
+    g_list_free_full(os->priv->deviceLinks, g_object_unref);
0a59fa
     g_object_unref(os->priv->medias);
0a59fa
     g_object_unref(os->priv->trees);
0a59fa
     g_object_unref(os->priv->variants);
0a59fa
diff --git a/osinfo/osinfo_platform.c b/osinfo/osinfo_platform.c
0a59fa
index b17eef6..c949a83 100644
0a59fa
--- a/osinfo/osinfo_platform.c
0a59fa
+++ b/osinfo/osinfo_platform.c
0a59fa
@@ -52,18 +52,12 @@ struct _OsinfoPlatformDeviceLink {
0a59fa
     gchar *driver;
0a59fa
 };
0a59fa
 
0a59fa
-static void osinfo_device_link_free(gpointer data, gpointer opaque G_GNUC_UNUSED)
0a59fa
-{
0a59fa
-    g_object_unref(OSINFO_DEVICELINK(data));
0a59fa
-}
0a59fa
-
0a59fa
 static void
0a59fa
 osinfo_platform_finalize(GObject *object)
0a59fa
 {
0a59fa
     OsinfoPlatform *platform = OSINFO_PLATFORM(object);
0a59fa
 
0a59fa
-    g_list_foreach(platform->priv->deviceLinks, osinfo_device_link_free, NULL);
0a59fa
-    g_list_free(platform->priv->deviceLinks);
0a59fa
+    g_list_free_full(platform->priv->deviceLinks, g_object_unref);
0a59fa
 
0a59fa
     /* Chain up to the parent class */
0a59fa
     G_OBJECT_CLASS(osinfo_platform_parent_class)->finalize(object);
0a59fa
diff --git a/osinfo/osinfo_product.c b/osinfo/osinfo_product.c
0a59fa
index 1bd7017..27cb89c 100644
0a59fa
--- a/osinfo/osinfo_product.c
0a59fa
+++ b/osinfo/osinfo_product.c
0a59fa
@@ -82,7 +82,7 @@ enum {
0a59fa
     PROP_LOGO,
0a59fa
 };
0a59fa
 
0a59fa
-static void osinfo_product_link_free(gpointer data, gpointer opaque G_GNUC_UNUSED)
0a59fa
+static void osinfo_product_link_free(gpointer data)
0a59fa
 {
0a59fa
     struct _OsinfoProductProductLink *prodlink = data;
0a59fa
     g_object_unref(prodlink->otherProduct);
0a59fa
@@ -95,8 +95,7 @@ osinfo_product_finalize(GObject *object)
0a59fa
 {
0a59fa
     OsinfoProduct *product = OSINFO_PRODUCT(object);
0a59fa
 
0a59fa
-    g_list_foreach(product->priv->productLinks, osinfo_product_link_free, NULL);
0a59fa
-    g_list_free(product->priv->productLinks);
0a59fa
+    g_list_free_full(product->priv->productLinks, osinfo_product_link_free);
0a59fa
 
0a59fa
     /* Chain up to the parent class */
0a59fa
     G_OBJECT_CLASS(osinfo_product_parent_class)->finalize(object);
0a59fa
diff --git a/osinfo/osinfo_productfilter.c b/osinfo/osinfo_productfilter.c
0a59fa
index 16976c2..addd3dc 100644
0a59fa
--- a/osinfo/osinfo_productfilter.c
0a59fa
+++ b/osinfo/osinfo_productfilter.c
0a59fa
@@ -97,17 +97,10 @@ OsinfoProductFilter *osinfo_productfilter_new(void)
0a59fa
 }
0a59fa
 
0a59fa
 
0a59fa
-static void
0a59fa
-osinfo_productfilter_product_constraint_free(gpointer value, gpointer opaque G_GNUC_UNUSED)
0a59fa
-{
0a59fa
-    g_object_unref(value);
0a59fa
-}
0a59fa
-
0a59fa
 static void
0a59fa
 osinfo_productfilter_product_constraints_free(gpointer relshps)
0a59fa
 {
0a59fa
-    g_list_foreach(relshps, osinfo_productfilter_product_constraint_free, NULL);
0a59fa
-    g_list_free(relshps);
0a59fa
+    g_list_free_full(relshps, g_object_unref);
0a59fa
 }
0a59fa
 
0a59fa
 static void
0a59fa
diff --git a/tests/test-isodetect.c b/tests/test-isodetect.c
0a59fa
index 7214531..b5591bc 100644
0a59fa
--- a/tests/test-isodetect.c
0a59fa
+++ b/tests/test-isodetect.c
0a59fa
@@ -46,6 +46,14 @@ static void free_iso(struct ISOInfo *info)
0a59fa
     g_free(info);
0a59fa
 }
0a59fa
 
0a59fa
+/* void* wrapper for free_iso, so it can be used where a void* parameter
0a59fa
+ * is required (e.g. g_list_free_full), with no need for casts.
0a59fa
+ */
0a59fa
+static void free_iso_void(void *info)
0a59fa
+{
0a59fa
+    free_iso((struct ISOInfo *)info);
0a59fa
+}
0a59fa
+
0a59fa
 static gboolean load_langs(GFile *file, struct ISOInfo *info, GError **error)
0a59fa
 {
0a59fa
     char *path;
0a59fa
@@ -242,8 +250,7 @@ static GList *load_distro(GFile *dir, const gchar *shortid, GError **error) {
0a59fa
     return ret;
0a59fa
 
0a59fa
  error:
0a59fa
-    g_list_foreach(ret, (GFunc)free_iso, NULL);
0a59fa
-    g_list_free(ret);
0a59fa
+    g_list_free_full(ret, free_iso_void);
0a59fa
     ret = NULL;
0a59fa
     goto cleanup;
0a59fa
 }
0a59fa
@@ -288,8 +295,7 @@ static GList *load_distros(GFile *dir, GError **error)
0a59fa
     return ret;
0a59fa
 
0a59fa
  error:
0a59fa
-    g_list_foreach(ret, (GFunc)free_iso, NULL);
0a59fa
-    g_list_free(ret);
0a59fa
+    g_list_free_full(ret, free_iso_void);
0a59fa
     ret = NULL;
0a59fa
     goto cleanup;
0a59fa
 }
0a59fa
@@ -370,8 +376,7 @@ static void test_one(const gchar *vendor)
0a59fa
         tmp = tmp->next;
0a59fa
     }
0a59fa
 
0a59fa
-    g_list_foreach(isos, (GFunc)free_iso, NULL);
0a59fa
-    g_list_free(isos);
0a59fa
+    g_list_free_full(isos, free_iso_void);
0a59fa
 
0a59fa
     g_object_unref(loader);
0a59fa
 }
0a59fa
-- 
0a59fa
2.21.0
0a59fa