提交 8eacfd4c 编写于 作者: D Daniel P. Berrange

Fix misc OOM bugs

* 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
上级 4ff60912
...@@ -354,10 +354,6 @@ virCapabilitiesAddGuest(virCapsPtr caps, ...@@ -354,10 +354,6 @@ virCapabilitiesAddGuest(virCapsPtr caps,
if (loader && if (loader &&
(guest->arch.defaultInfo.loader = strdup(loader)) == NULL) (guest->arch.defaultInfo.loader = strdup(loader)) == NULL)
goto no_memory; goto no_memory;
if (nmachines) {
guest->arch.defaultInfo.nmachines = nmachines;
guest->arch.defaultInfo.machines = machines;
}
if (VIR_REALLOC_N(caps->guests, if (VIR_REALLOC_N(caps->guests,
caps->nguests + 1) < 0) caps->nguests + 1) < 0)
...@@ -365,6 +361,11 @@ virCapabilitiesAddGuest(virCapsPtr caps, ...@@ -365,6 +361,11 @@ virCapabilitiesAddGuest(virCapsPtr caps,
caps->guests[caps->nguests] = guest; caps->guests[caps->nguests] = guest;
caps->nguests++; caps->nguests++;
if (nmachines) {
guest->arch.defaultInfo.nmachines = nmachines;
guest->arch.defaultInfo.machines = machines;
}
return guest; return guest;
no_memory: no_memory:
...@@ -407,10 +408,6 @@ virCapabilitiesAddGuestDomain(virCapsGuestPtr guest, ...@@ -407,10 +408,6 @@ virCapabilitiesAddGuestDomain(virCapsGuestPtr guest,
if (loader && if (loader &&
(dom->info.loader = strdup(loader)) == NULL) (dom->info.loader = strdup(loader)) == NULL)
goto no_memory; goto no_memory;
if (nmachines) {
dom->info.nmachines = nmachines;
dom->info.machines = machines;
}
if (VIR_REALLOC_N(guest->arch.domains, if (VIR_REALLOC_N(guest->arch.domains,
guest->arch.ndomains + 1) < 0) guest->arch.ndomains + 1) < 0)
...@@ -418,6 +415,10 @@ virCapabilitiesAddGuestDomain(virCapsGuestPtr guest, ...@@ -418,6 +415,10 @@ virCapabilitiesAddGuestDomain(virCapsGuestPtr guest,
guest->arch.domains[guest->arch.ndomains] = dom; guest->arch.domains[guest->arch.ndomains] = dom;
guest->arch.ndomains++; guest->arch.ndomains++;
if (nmachines) {
dom->info.nmachines = nmachines;
dom->info.machines = machines;
}
return dom; return dom;
......
...@@ -2046,6 +2046,9 @@ static int xenXMDomainConfigFormatNet(virConnectPtr conn, ...@@ -2046,6 +2046,9 @@ static int xenXMDomainConfigFormatNet(virConnectPtr conn,
virBufferVSprintf(&buf, ",vifname=%s", virBufferVSprintf(&buf, ",vifname=%s",
net->ifname); net->ifname);
if (virBufferError(&buf))
goto cleanup;
if (VIR_ALLOC(val) < 0) { if (VIR_ALLOC(val) < 0) {
virReportOOMError(conn); virReportOOMError(conn);
goto cleanup; goto cleanup;
......
...@@ -367,10 +367,7 @@ int virtTestMain(int argc, ...@@ -367,10 +367,7 @@ int virtTestMain(int argc,
} }
} }
if (testOOM) /* Run once to prime any static allocations & ensure it passes */
virAllocTestInit();
/* Run once to count allocs, and ensure it passes :-) */
ret = (func)(argc, argv); ret = (func)(argc, argv);
if (ret != EXIT_SUCCESS) if (ret != EXIT_SUCCESS)
goto cleanup; goto cleanup;
...@@ -385,6 +382,13 @@ int virtTestMain(int argc, ...@@ -385,6 +382,13 @@ int virtTestMain(int argc,
testOOM++; testOOM++;
virSetErrorFunc(NULL, virtTestErrorFuncQuiet); 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(); approxAlloc = virAllocTestCount();
testCounter++; testCounter++;
if (testDebug) if (testDebug)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册