[Libosinfo] [osinfo-db-tools PATCH 8/9] validate: Use g_clear_*() functions

Fabiano Fidêncio fidencio at redhat.com
Fri Jun 28 09:41:19 UTC 2019


Let's use g_clear_object() & g_clear_error() as those two functions
avoid us checking whether the object is NULL or not and also sets the
object to NULL after unrefing it.

Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
---
 tools/osinfo-db-validate.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/tools/osinfo-db-validate.c b/tools/osinfo-db-validate.c
index 3a1717f..ea9508e 100644
--- a/tools/osinfo-db-validate.c
+++ b/tools/osinfo-db-validate.c
@@ -137,7 +137,7 @@ static gboolean validate_file_directory(xmlRelaxNGValidCtxtPtr rngValid, GFile *
     ret = TRUE;
 
  cleanup:
-    g_object_unref(children);
+    g_clear_object(&children);
     return ret;
 }
 
@@ -176,8 +176,7 @@ static gboolean validate_file(xmlRelaxNGValidCtxtPtr rngValid, GFile *file, GFil
 
  cleanup:
     g_free(uri);
-    if (thisinfo)
-        g_object_unref(thisinfo);
+    g_clear_object(&thisinfo);
     return ret;
 }
 
@@ -324,10 +323,8 @@ gint main(gint argc, gchar **argv)
     ret = EXIT_SUCCESS;
 
  error:
-    if (schema)
-        g_object_unref(schema);
-    if (dir)
-        g_object_unref(dir);
+    g_clear_object(&schema);
+    g_clear_object(&dir);
     g_free(files);
     g_clear_error(&error);
     g_option_context_free(context);
-- 
2.21.0




More information about the Libosinfo mailing list