]> xenbits.xensource.com Git - libvirt.git/commitdiff
fix error when parsing ppc64 models on x86 host
authorStefan Berger <stefanb@linux.vnet.ibm.com>
Fri, 9 Dec 2011 17:18:58 +0000 (12:18 -0500)
committerStefan Berger <stefanb@us.ibm.com>
Fri, 9 Dec 2011 17:18:58 +0000 (12:18 -0500)
When parsing ppc64 models on an x86 host an out-of-memory error message is displayed due
to it checking for retcpus being NULL. Fix this by removing the check whether retcpus is NULL
since we will realloc into this variable.
Also in the X86 model parser display the OOM error at the location where it happens.

src/qemu/qemu_capabilities.c

index 04ad10477705841fdb225588a332398139d98f68..e69d60129a0672be2731d7320d3896f322136fee 100644 (file)
@@ -443,8 +443,10 @@ qemuCapsParseX86Models(const char *output,
         if (retcpus) {
             unsigned int len;
 
-            if (VIR_REALLOC_N(cpus, count + 1) < 0)
+            if (VIR_REALLOC_N(cpus, count + 1) < 0) {
+                virReportOOMError();
                 goto error;
+            }
 
             if (next)
                 len = next - p - 1;
@@ -456,8 +458,10 @@ qemuCapsParseX86Models(const char *output,
                 len -= 2;
             }
 
-            if (!(cpus[count] = strndup(p, len)))
+            if (!(cpus[count] = strndup(p, len))) {
+                virReportOOMError();
                 goto error;
+            }
         }
         count++;
     } while ((p = next));
@@ -491,12 +495,7 @@ qemuCapsParsePPCModels(const char *output,
     const char *next;
     unsigned int count = 0;
     const char **cpus = NULL;
-    int i;
-
-    if (!retcpus) {
-        VIR_DEBUG("No retcpus specified");
-        return -1;
-    }
+    int i, ret = -1;
 
     do {
         const char *t;
@@ -523,32 +522,36 @@ qemuCapsParsePPCModels(const char *output,
         if (retcpus) {
             unsigned int len;
 
-            if (VIR_REALLOC_N(cpus, count + 1) < 0)
+            if (VIR_REALLOC_N(cpus, count + 1) < 0) {
                 virReportOOMError();
-                goto error;
+                goto cleanup;
+            }
 
             len = t - p - 1;
 
-            if (!(cpus[count] = strndup(p, len)))
+            if (!(cpus[count] = strndup(p, len))) {
                 virReportOOMError();
-                goto error;
+                goto cleanup;
+            }
         }
         count++;
     } while ((p = next));
 
     if (retcount)
         *retcount = count;
-    if (retcpus)
+    if (retcpus) {
         *retcpus = cpus;
-    return 0;
+        cpus = NULL;
+    }
+    ret = 0;
 
-error:
+cleanup:
     if (cpus) {
         for (i = 0; i < count; i++)
             VIR_FREE(cpus[i]);
+        VIR_FREE(cpus);
     }
-    VIR_FREE(cpus);
-    return -1;
+    return ret;
 }
 
 int
@@ -587,10 +590,8 @@ qemuCapsProbeCPUModels(const char *qemu,
     if (virCommandRun(cmd, NULL) < 0)
         goto cleanup;
 
-    if (parse(output, count, cpus) < 0) {
-        virReportOOMError();
+    if (parse(output, count, cpus) < 0)
         goto cleanup;
-    }
 
     ret = 0;