[libvirt] [PATCH 3/3] Fix error reporting when parsing CPU XML strings

Jiri Denemark jdenemar at redhat.com
Wed Feb 24 22:07:34 UTC 2010


Signed-off-by: Jiri Denemark <jdenemar at redhat.com>
---
 src/cpu/cpu.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c
index 501a00c..be0f15e 100644
--- a/src/cpu/cpu.c
+++ b/src/cpu/cpu.c
@@ -73,9 +73,10 @@ cpuCompareXML(virCPUDefPtr host,
     virCPUDefPtr cpu = NULL;
     virCPUCompareResult ret = VIR_CPU_COMPARE_ERROR;
 
-    doc = xmlParseMemory(xml, strlen(xml));
+    if (!(doc = virXMLParseString(xml, "cpu.xml")))
+        goto cleanup;
 
-    if (doc == NULL || (ctxt = xmlXPathNewContext(doc)) == NULL) {
+    if ((ctxt = xmlXPathNewContext(doc)) == NULL) {
         virReportOOMError();
         goto cleanup;
     }
@@ -268,8 +269,10 @@ cpuBaselineXML(const char **xmlCPUs,
         goto no_memory;
 
     for (i = 0; i < ncpus; i++) {
-        doc = xmlParseMemory(xmlCPUs[i], strlen(xmlCPUs[i]));
-        if (doc == NULL || (ctxt = xmlXPathNewContext(doc)) == NULL)
+        if (!(doc = virXMLParseString(xmlCPUs[i], "cpu.xml")))
+            goto error;
+
+        if ((ctxt = xmlXPathNewContext(doc)) == NULL)
             goto no_memory;
 
         ctxt->node = xmlDocGetRootElement(doc);
-- 
1.7.0




More information about the libvir-list mailing list