From d5fbca9987b595c3f277a39cc04aca810bde02bc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@redhat.com>
Date: Mon, 10 Dec 2018 15:46:17 +0100
Subject: [PATCH] tree: cleanup non-fatal errors in load_key_info()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

There are errors which are not fatal and just ignored in load_keyinfo.
However, as those have not been cleaned up, we could see messages like:
(lt-osinfo-detect:20658): GLib-WARNING **: GError set over the top of a
previous GError or uninitialized memory.
This indicates a bug in someone's code. You must ensure an error is NULL
before it's set.
The overwriting error message was: Key file does not have key “boot.iso”
in group “images-x86_64”

In order to avoid this, let's just call g_clear_error() after situations
where an error may have been set but it can just be ignored.

Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Christophe Fergeau <cfergeau@redhat.com>
(cherry picked from commit 1c4deff7dc94da6157f64c398a58375a2c97e35b)
---
 osinfo/osinfo_tree.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/osinfo/osinfo_tree.c b/osinfo/osinfo_tree.c
index f256f8a..ef82807 100644
--- a/osinfo/osinfo_tree.c
+++ b/osinfo/osinfo_tree.c
@@ -503,21 +503,25 @@ static OsinfoTree *load_keyinfo(const gchar *location,
     if (!(family = g_key_file_get_string(file, "general", "family", error))) {
         if (!is_unknown_group_or_key_error(*error))
             goto cleanup;
+        g_clear_error(error);
     }
 
     if (!(variant = g_key_file_get_string(file, "general", "variant", error))) {
         if (!is_unknown_group_or_key_error(*error))
             goto cleanup;
+        g_clear_error(error);
     }
 
     if (!(version = g_key_file_get_string(file, "general", "version", error))) {
         if (!is_unknown_group_or_key_error(*error))
             goto cleanup;
+        g_clear_error(error);
     }
 
     if (!(arch = g_key_file_get_string(file, "general", "arch", error))) {
         if (!is_unknown_group_or_key_error(*error))
             goto cleanup;
+        g_clear_error(error);
     }
 
 
@@ -527,16 +531,19 @@ static OsinfoTree *load_keyinfo(const gchar *location,
         if (!(kernel = g_key_file_get_string(file, group, "kernel", error))) {
             if (!is_unknown_group_or_key_error(*error))
                 goto cleanup;
+            g_clear_error(error);
         }
 
         if (!(initrd = g_key_file_get_string(file, group, "initrd", error))) {
             if (!is_unknown_group_or_key_error(*error))
                 goto cleanup;
+            g_clear_error(error);
         }
 
         if (!(bootiso = g_key_file_get_string(file, group, "boot.iso", error))) {
             if (!is_unknown_group_or_key_error(*error))
                 goto cleanup;
+            g_clear_error(error);
         }
     }
 
-- 
2.21.0

