[virt-tools-list] [osinfo PATCH] Make sure we don't set a GError twice in OSInfoLoader

Christophe Fergeau cfergeau at redhat.com
Wed Nov 30 10:07:24 UTC 2011


When parsing OSInfo XML documents, the catchXMLError callback may
be called for non fatal errors. When this happens, we get a pointer
to a parsed document which we can use, but we may have set a GError
during the parsing if a non fatal error was logged. This means we
have to make sure the error is cleared after the parsing, otherwise
we may attempt to set it twice which is forbidden

This can be triggered by running examples/demo.py:

$ python examples/demo.py
/usr/lib/python2.7/dist-packages/gi/types.py:43: 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: Incorrect root element
  return info.invoke(*args, **kwargs)
Traceback (most recent call last):
  File "examples/demo.py", line 6, in <module>
    loader.process_path("./")
  File "/usr/lib/python2.7/dist-packages/gi/types.py", line 43, in function
    return info.invoke(*args, **kwargs)
gi._glib.GError: at line 18: Namespace prefix xi on include is not defined

Bug report and initial fix from Guido Günther <agx at sigxcpu.org>
---
 osinfo/osinfo_loader.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
index ca634f8..cf176a2 100644
--- a/osinfo/osinfo_loader.c
+++ b/osinfo/osinfo_loader.c
@@ -826,6 +826,12 @@ static void osinfo_loader_process_xml(OsinfoLoader *loader,
     if (!xml)
         goto cleanup;
 
+    /* catchXMLError may be called for non-fatal errors. If that happens,
+     * xml will be non-NULL but err may be set. This will cause warnings if
+     * we try to set err later on, so clear it first.
+     */
+    g_clear_error(err);
+
     root = xmlDocGetRootElement(xml);
 
     if (!root) {
-- 
1.7.7.3




More information about the virt-tools-list mailing list