Fix crashes in Xen capabilities code

* src/xen_internal.c: Don't free memory now owned by the virCapsPtr
   structure
* tests/testutilsxen.c: Fix up for change in internal API
This commit is contained in:
Daniel P. Berrange 2009-07-27 16:45:01 +01:00
parent f055724b27
commit dd6cd7dd63
2 changed files with 18 additions and 4 deletions

View File

@ -2223,8 +2223,7 @@ xenHypervisorBuildCapabilities(virConnectPtr conn,
virCapabilitiesFreeMachines(machines, 1);
goto no_memory;
}
virCapabilitiesFreeMachines(machines, 1);
machines = NULL;
if (virCapabilitiesAddGuestDomain(guest,
"xen",

View File

@ -9,6 +9,8 @@ virCapsPtr testXenCapsInit(void) {
struct utsname utsname;
virCapsPtr caps;
virCapsGuestPtr guest;
virCapsGuestMachinePtr *machines;
int nmachines;
static const char *const x86_machines[] = {
"xenfv"
};
@ -21,10 +23,16 @@ virCapsPtr testXenCapsInit(void) {
0, 0)) == NULL)
return NULL;
nmachines = ARRAY_CARDINALITY(x86_machines);
if ((machines = virCapabilitiesAllocMachines(x86_machines, nmachines)) == NULL)
goto cleanup;
if ((guest = virCapabilitiesAddGuest(caps, "hvm", "i686", 32,
"/usr/lib/xen/bin/qemu-dm", NULL,
1, x86_machines)) == NULL)
nmachines, machines)) == NULL)
goto cleanup;
machines = NULL;
if (virCapabilitiesAddGuestDomain(guest,
"xen",
NULL,
@ -33,10 +41,16 @@ virCapsPtr testXenCapsInit(void) {
NULL) == NULL)
goto cleanup;
nmachines = ARRAY_CARDINALITY(xen_machines);
if ((machines = virCapabilitiesAllocMachines(xen_machines, nmachines)) == NULL)
goto cleanup;
if ((guest = virCapabilitiesAddGuest(caps, "xen", "i686", 32,
"/usr/lib/xen/bin/qemu-dm", NULL,
1, xen_machines)) == NULL)
nmachines, machines)) == NULL)
goto cleanup;
machines = NULL;
if (virCapabilitiesAddGuestDomain(guest,
"xen",
NULL,
@ -48,6 +62,7 @@ virCapsPtr testXenCapsInit(void) {
return caps;
cleanup:
virCapabilitiesFreeMachines(machines, nmachines);
virCapabilitiesFree(caps);
return NULL;
}