]> xenbits.xensource.com Git - libvirt.git/commitdiff
Fix misc OOM bugs
authorDaniel P. Berrange <berrange@redhat.com>
Wed, 2 Sep 2009 14:09:04 +0000 (15:09 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Thu, 3 Sep 2009 12:14:46 +0000 (13:14 +0100)
* tests/testutils.c: Run test function twice, once to prime it for
  static allocations, once to count the non-static allocations.
* tests/testutilsqemu.c: Initialize variable correctl
* src/capabilities.c: Don't free machines variable upon failure
  since caller must do that
* src/xm_internal.c: Add missing check for OOM in building VIF
  config param

src/capabilities.c
src/xm_internal.c
tests/testutils.c

index 193a9fe97324c0211857361d180651fdedc14a74..289180df077c25c5b600942299cd9424d0d2eb14 100644 (file)
@@ -354,10 +354,6 @@ virCapabilitiesAddGuest(virCapsPtr caps,
     if (loader &&
         (guest->arch.defaultInfo.loader = strdup(loader)) == NULL)
         goto no_memory;
-    if (nmachines) {
-        guest->arch.defaultInfo.nmachines = nmachines;
-        guest->arch.defaultInfo.machines = machines;
-    }
 
     if (VIR_REALLOC_N(caps->guests,
                       caps->nguests + 1) < 0)
@@ -365,6 +361,11 @@ virCapabilitiesAddGuest(virCapsPtr caps,
     caps->guests[caps->nguests] = guest;
     caps->nguests++;
 
+    if (nmachines) {
+        guest->arch.defaultInfo.nmachines = nmachines;
+        guest->arch.defaultInfo.machines = machines;
+    }
+
     return guest;
 
  no_memory:
@@ -407,10 +408,6 @@ virCapabilitiesAddGuestDomain(virCapsGuestPtr guest,
     if (loader &&
         (dom->info.loader = strdup(loader)) == NULL)
         goto no_memory;
-    if (nmachines) {
-        dom->info.nmachines = nmachines;
-        dom->info.machines = machines;
-    }
 
     if (VIR_REALLOC_N(guest->arch.domains,
                       guest->arch.ndomains + 1) < 0)
@@ -418,6 +415,10 @@ virCapabilitiesAddGuestDomain(virCapsGuestPtr guest,
     guest->arch.domains[guest->arch.ndomains] = dom;
     guest->arch.ndomains++;
 
+    if (nmachines) {
+        dom->info.nmachines = nmachines;
+        dom->info.machines = machines;
+    }
 
     return dom;
 
index dd44ce5f7d39efe25e213dd158fe55fa9e120458..2595a5e9a575d1cd1700e8cdeb391bac05fed98b 100644 (file)
@@ -2046,6 +2046,9 @@ static int xenXMDomainConfigFormatNet(virConnectPtr conn,
         virBufferVSprintf(&buf, ",vifname=%s",
                           net->ifname);
 
+    if (virBufferError(&buf))
+        goto cleanup;
+
     if (VIR_ALLOC(val) < 0) {
         virReportOOMError(conn);
         goto cleanup;
index 7a1dbdcdd8edec7d744cddb111a7a799316c2ce6..5072fecb6bfe649ac68a4f7fd8314f1ede5ac926 100644 (file)
@@ -367,10 +367,7 @@ int virtTestMain(int argc,
         }
     }
 
-    if (testOOM)
-        virAllocTestInit();
-
-    /* Run once to count allocs, and ensure it passes :-) */
+    /* Run once to prime any static allocations & ensure it passes */
     ret = (func)(argc, argv);
     if (ret != EXIT_SUCCESS)
         goto cleanup;
@@ -385,6 +382,13 @@ int virtTestMain(int argc,
         testOOM++;
         virSetErrorFunc(NULL, virtTestErrorFuncQuiet);
 
+        virAllocTestInit();
+
+        /* Run again to count allocs, and ensure it passes :-) */
+        ret = (func)(argc, argv);
+        if (ret != EXIT_SUCCESS)
+            goto cleanup;
+
         approxAlloc = virAllocTestCount();
         testCounter++;
         if (testDebug)