[Libosinfo] [libosinfo PATCH] tree: cleanup non-fatal errors
Fabiano Fidêncio
fabiano at fidencio.org
Sat Dec 1 08:54:21 UTC 2018
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 an
situations where an error may have been set but it can just be ignored.
Signed-off-by: Fabiano Fidêncio <fabiano at fidencio.org>
---
osinfo/osinfo_tree.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/osinfo/osinfo_tree.c b/osinfo/osinfo_tree.c
index da01c8b..3082eab 100644
--- a/osinfo/osinfo_tree.c
+++ b/osinfo/osinfo_tree.c
@@ -491,26 +491,31 @@ static OsinfoTree *load_keyinfo(const gchar *location,
if (!g_key_file_load_from_data(file, content, length,
G_KEY_FILE_NONE, error))
goto cleanup;
+ g_clear_error(error);
if (!(family = g_key_file_get_string(file, "general", "family", error)) &&
(*error && (*error)->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND &&
(*error)->code != G_KEY_FILE_ERROR_GROUP_NOT_FOUND))
goto cleanup;
+ g_clear_error(error);
if (!(variant = g_key_file_get_string(file, "general", "variant", error)) &&
(*error && (*error)->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND &&
(*error)->code != G_KEY_FILE_ERROR_GROUP_NOT_FOUND))
goto cleanup;
+ g_clear_error(error);
if (!(version = g_key_file_get_string(file, "general", "version", error)) &&
(*error && (*error)->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND &&
(*error)->code != G_KEY_FILE_ERROR_GROUP_NOT_FOUND))
goto cleanup;
+ g_clear_error(error);
if (!(arch = g_key_file_get_string(file, "general", "arch", error)) &&
(*error && (*error)->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND &&
(*error)->code != G_KEY_FILE_ERROR_GROUP_NOT_FOUND))
goto cleanup;
+ g_clear_error(error);
if (arch) {
@@ -520,16 +525,19 @@ static OsinfoTree *load_keyinfo(const gchar *location,
(*error && (*error)->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND &&
(*error)->code != G_KEY_FILE_ERROR_GROUP_NOT_FOUND))
goto cleanup;
+ g_clear_error(error);
if (!(initrd = g_key_file_get_string(file, group, "initrd", error)) &&
(*error && (*error)->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND &&
(*error)->code != G_KEY_FILE_ERROR_GROUP_NOT_FOUND))
goto cleanup;
+ g_clear_error(error);
if (!(bootiso = g_key_file_get_string(file, group, "boot.iso", error)) &&
(*error && (*error)->code != G_KEY_FILE_ERROR_KEY_NOT_FOUND &&
(*error)->code != G_KEY_FILE_ERROR_GROUP_NOT_FOUND))
goto cleanup;
+ g_clear_error(error);
}
tree = osinfo_tree_new(location, arch ? arch : "i386");
--
1.8.3.1
More information about the Libosinfo
mailing list