Convert to use new memory allocation APIs

This commit is contained in:
Daniel P. Berrange 2008-05-29 19:20:22 +00:00
parent e8a0db81ef
commit 895d0fdf5b
11 changed files with 435 additions and 416 deletions

View File

@ -1,3 +1,10 @@
Thu May 29 15:17:00 EST 2008 Daniel P. Berrange <berrange@redhat.com>
* src/conf.c, src/conf.h, src/qemu_conf.c, src/qemu_driver.c,
src/test.c, src/util.c, src/xend_internal.c, src/xm_internal.c,
src/xml.c, tests/virshtest.c: Switch over to using new memory
allocation APIs.
Thu May 29 14:46:00 EST 2008 Daniel P. Berrange <berrange@redhat.com> Thu May 29 14:46:00 EST 2008 Daniel P. Berrange <berrange@redhat.com>
* src/memory.h, src/memory.c, tests/testutils.c: Pass allocation * src/memory.h, src/memory.c, tests/testutils.c: Pass allocation

View File

@ -105,7 +105,6 @@ virConfError(virConfPtr conf ATTRIBUTE_UNUSED,
* Structures allocations and deallocations * * Structures allocations and deallocations *
* * * *
************************************************************************/ ************************************************************************/
static void virConfFreeValue(virConfValuePtr val);
/** /**
* virConfFreeList: * virConfFreeList:
@ -132,8 +131,8 @@ virConfFreeList(virConfValuePtr list)
* *
* Free a value * Free a value
*/ */
static void void
virConfFreeValue(virConfValuePtr val) __virConfFreeValue(virConfValuePtr val)
{ {
if (val == NULL) if (val == NULL)
return; return;

View File

@ -70,6 +70,7 @@ virConfPtr __virConfReadFile (const char *filename);
virConfPtr __virConfReadMem (const char *memory, virConfPtr __virConfReadMem (const char *memory,
int len); int len);
int __virConfFree (virConfPtr conf); int __virConfFree (virConfPtr conf);
void __virConfFreeValue (virConfValuePtr val);
virConfValuePtr __virConfGetValue (virConfPtr conf, virConfValuePtr __virConfGetValue (virConfPtr conf,
const char *setting); const char *setting);
@ -82,14 +83,15 @@ int __virConfWriteMem (char *memory,
int *len, int *len,
virConfPtr conf); virConfPtr conf);
#define virConfNew() (__virConfNew()) #define virConfNew() __virConfNew()
#define virConfReadFile(f) (__virConfReadFile((f))) #define virConfReadFile(f) __virConfReadFile((f))
#define virConfReadMem(m,l) (__virConfReadMem((m),(l))) #define virConfReadMem(m,l) __virConfReadMem((m),(l))
#define virConfFree(c) (__virConfFree((c))) #define virConfFree(c) __virConfFree((c))
#define virConfGetValue(c,s) (__virConfGetValue((c),(s))) #define virConfFreeValue(v) __virConfFreeValue((v))
#define virConfSetValue(c,s,v) (__virConfSetValue((c),(s),(v))) #define virConfGetValue(c,s) __virConfGetValue((c),(s))
#define virConfWriteFile(f,c) (__virConfWriteFile((f),(c))) #define virConfSetValue(c,s,v) __virConfSetValue((c),(s),(v))
#define virConfWriteMem(m,l,c) (__virConfWriteMem((m),(l),(c))) #define virConfWriteFile(f,c) __virConfWriteFile((f),(c))
#define virConfWriteMem(m,l,c) __virConfWriteMem((m),(l),(c))
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -121,7 +121,7 @@ int qemudLoadDriverConfig(struct qemud_driver *driver,
p = virConfGetValue (conf, "vnc_tls_x509_cert_dir"); p = virConfGetValue (conf, "vnc_tls_x509_cert_dir");
CHECK_TYPE ("vnc_tls_x509_cert_dir", VIR_CONF_STRING); CHECK_TYPE ("vnc_tls_x509_cert_dir", VIR_CONF_STRING);
if (p && p->str) { if (p && p->str) {
free(driver->vncTLSx509certdir); VIR_FREE(driver->vncTLSx509certdir);
if (!(driver->vncTLSx509certdir = strdup(p->str))) { if (!(driver->vncTLSx509certdir = strdup(p->str))) {
qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY,
"%s", _("failed to allocate vncTLSx509certdir")); "%s", _("failed to allocate vncTLSx509certdir"));
@ -219,42 +219,42 @@ void qemudFreeVMDef(struct qemud_vm_def *def) {
while (disk) { while (disk) {
struct qemud_vm_disk_def *prev = disk; struct qemud_vm_disk_def *prev = disk;
disk = disk->next; disk = disk->next;
free(prev); VIR_FREE(prev);
} }
while (net) { while (net) {
struct qemud_vm_net_def *prev = net; struct qemud_vm_net_def *prev = net;
net = net->next; net = net->next;
free(prev); VIR_FREE(prev);
} }
while (input) { while (input) {
struct qemud_vm_input_def *prev = input; struct qemud_vm_input_def *prev = input;
input = input->next; input = input->next;
free(prev); VIR_FREE(prev);
} }
while (serial) { while (serial) {
struct qemud_vm_chr_def *prev = serial; struct qemud_vm_chr_def *prev = serial;
serial = serial->next; serial = serial->next;
free(prev); VIR_FREE(prev);
} }
while (parallel) { while (parallel) {
struct qemud_vm_chr_def *prev = parallel; struct qemud_vm_chr_def *prev = parallel;
parallel = parallel->next; parallel = parallel->next;
free(prev); VIR_FREE(prev);
} }
while (sound) { while (sound) {
struct qemud_vm_sound_def *prev = sound; struct qemud_vm_sound_def *prev = sound;
sound = sound->next; sound = sound->next;
free(prev); VIR_FREE(prev);
} }
xmlFree(def->keymap); xmlFree(def->keymap);
free(def); VIR_FREE(def);
} }
void qemudFreeVM(struct qemud_vm *vm) { void qemudFreeVM(struct qemud_vm *vm) {
qemudFreeVMDef(vm->def); qemudFreeVMDef(vm->def);
if (vm->newDef) if (vm->newDef)
qemudFreeVMDef(vm->newDef); qemudFreeVMDef(vm->newDef);
free(vm); VIR_FREE(vm);
} }
@ -1417,8 +1417,8 @@ static int qemudParseCharXMLDevices(virConnectPtr conn,
} }
for (i = 0; i < obj->nodesetval->nodeNr; i++) { for (i = 0; i < obj->nodesetval->nodeNr; i++) {
struct qemud_vm_chr_def *chr = calloc(1, sizeof(*chr)); struct qemud_vm_chr_def *chr;
if (!chr) { if (VIR_ALLOC(chr) < 0) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,
"%s", "%s",
_("failed to allocate space for char device")); _("failed to allocate space for char device"));
@ -1426,7 +1426,7 @@ static int qemudParseCharXMLDevices(virConnectPtr conn,
} }
if (qemudParseCharXML(conn, chr, i, obj->nodesetval->nodeTab[i]) < 0) { if (qemudParseCharXML(conn, chr, i, obj->nodesetval->nodeTab[i]) < 0) {
free(chr); VIR_FREE(chr);
goto cleanup; goto cleanup;
} }
if (ndevs) if (ndevs)
@ -1619,7 +1619,7 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
int i; int i;
struct qemud_vm_def *def; struct qemud_vm_def *def;
if (!(def = calloc(1, sizeof(*def)))) { if (VIR_ALLOC(def) < 0) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,
"%s", _("failed to allocate space for xmlXPathContext")); "%s", _("failed to allocate space for xmlXPathContext"));
return NULL; return NULL;
@ -1659,8 +1659,7 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
"%s", _("invalid domain type attribute")); "%s", _("invalid domain type attribute"));
goto error; goto error;
} }
free(prop); VIR_FREE(prop);
prop = NULL;
/* Extract domain name */ /* Extract domain name */
@ -2032,14 +2031,14 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
if ((obj != NULL) && (obj->type == XPATH_NODESET) && if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) { (obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) {
for (i = 0; i < obj->nodesetval->nodeNr; i++) { for (i = 0; i < obj->nodesetval->nodeNr; i++) {
struct qemud_vm_disk_def *disk = calloc(1, sizeof(*disk)); struct qemud_vm_disk_def *disk;
if (!disk) { if (VIR_ALLOC(disk) < 0) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,
"%s", _("failed to allocate space for disk string")); "%s", _("failed to allocate space for disk string"));
goto error; goto error;
} }
if (qemudParseDiskXML(conn, disk, obj->nodesetval->nodeTab[i]) < 0) { if (qemudParseDiskXML(conn, disk, obj->nodesetval->nodeTab[i]) < 0) {
free(disk); VIR_FREE(disk);
goto error; goto error;
} }
def->ndisks++; def->ndisks++;
@ -2082,8 +2081,8 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
obj = xmlXPathEval(BAD_CAST "/domain/devices/console", ctxt); obj = xmlXPathEval(BAD_CAST "/domain/devices/console", ctxt);
if ((obj != NULL) && (obj->type == XPATH_NODESET) && if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr == 1)) { (obj->nodesetval != NULL) && (obj->nodesetval->nodeNr == 1)) {
struct qemud_vm_chr_def *chr = calloc(1, sizeof(*chr)); struct qemud_vm_chr_def *chr;
if (!chr) { if (VIR_ALLOC(chr) < 0) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,
"%s", "%s",
_("failed to allocate space for char device")); _("failed to allocate space for char device"));
@ -2091,7 +2090,7 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
} }
if (qemudParseCharXML(conn, chr, 0, obj->nodesetval->nodeTab[0]) < 0) { if (qemudParseCharXML(conn, chr, 0, obj->nodesetval->nodeTab[0]) < 0) {
free(chr); VIR_FREE(chr);
goto error; goto error;
} }
def->nserials = 1; def->nserials = 1;
@ -2107,14 +2106,14 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) { (obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) {
struct qemud_vm_net_def *prev = NULL; struct qemud_vm_net_def *prev = NULL;
for (i = 0; i < obj->nodesetval->nodeNr; i++) { for (i = 0; i < obj->nodesetval->nodeNr; i++) {
struct qemud_vm_net_def *net = calloc(1, sizeof(*net)); struct qemud_vm_net_def *net;
if (!net) { if (VIR_ALLOC(net) < 0) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,
"%s", _("failed to allocate space for net string")); "%s", _("failed to allocate space for net string"));
goto error; goto error;
} }
if (qemudParseInterfaceXML(conn, net, obj->nodesetval->nodeTab[i]) < 0) { if (qemudParseInterfaceXML(conn, net, obj->nodesetval->nodeTab[i]) < 0) {
free(net); VIR_FREE(net);
goto error; goto error;
} }
def->nnets++; def->nnets++;
@ -2135,20 +2134,20 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) { (obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) {
struct qemud_vm_input_def *prev = NULL; struct qemud_vm_input_def *prev = NULL;
for (i = 0; i < obj->nodesetval->nodeNr; i++) { for (i = 0; i < obj->nodesetval->nodeNr; i++) {
struct qemud_vm_input_def *input = calloc(1, sizeof(*input)); struct qemud_vm_input_def *input;
if (!input) { if (VIR_ALLOC(input) < 0) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,
"%s", _("failed to allocate space for input string")); "%s", _("failed to allocate space for input string"));
goto error; goto error;
} }
if (qemudParseInputXML(conn, def, input, obj->nodesetval->nodeTab[i]) < 0) { if (qemudParseInputXML(conn, def, input, obj->nodesetval->nodeTab[i]) < 0) {
free(input); VIR_FREE(input);
goto error; goto error;
} }
/* Mouse + PS/2 is implicit with graphics, so don't store it */ /* Mouse + PS/2 is implicit with graphics, so don't store it */
if (input->bus == QEMU_INPUT_BUS_PS2 && if (input->bus == QEMU_INPUT_BUS_PS2 &&
input->type == QEMU_INPUT_TYPE_MOUSE) { input->type == QEMU_INPUT_TYPE_MOUSE) {
free(input); VIR_FREE(input);
continue; continue;
} }
def->ninputs++; def->ninputs++;
@ -2170,17 +2169,17 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
struct qemud_vm_sound_def *prev = NULL; struct qemud_vm_sound_def *prev = NULL;
for (i = 0; i < obj->nodesetval->nodeNr; i++) { for (i = 0; i < obj->nodesetval->nodeNr; i++) {
struct qemud_vm_sound_def *sound = calloc(1, sizeof(*sound)); struct qemud_vm_sound_def *sound;
struct qemud_vm_sound_def *check = def->sounds; struct qemud_vm_sound_def *check = def->sounds;
int collision = 0; int collision = 0;
if (!sound) { if (VIR_ALLOC(sound) < 0) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,
"%s", _("failed to allocate space for sound dev")); "%s", _("failed to allocate space for sound dev"));
goto error; goto error;
} }
if (qemudParseSoundXML(conn, sound, if (qemudParseSoundXML(conn, sound,
obj->nodesetval->nodeTab[i]) < 0) { obj->nodesetval->nodeTab[i]) < 0) {
free(sound); VIR_FREE(sound);
goto error; goto error;
} }
@ -2193,7 +2192,7 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
check = check->next; check = check->next;
} }
if (collision) { if (collision) {
free(sound); VIR_FREE(sound);
continue; continue;
} }
@ -2222,8 +2221,7 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
} }
if (!hasPS2mouse) { if (!hasPS2mouse) {
input = calloc(1, sizeof(*input)); if (VIR_ALLOC(input) < 0) {
if (!input) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,
"%s", _("failed to allocate space for input string")); "%s", _("failed to allocate space for input string"));
goto error; goto error;
@ -2241,7 +2239,7 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
return def; return def;
error: error:
free(prop); VIR_FREE(prop);
xmlXPathFreeObject(obj); xmlXPathFreeObject(obj);
xmlXPathFreeContext(ctxt); xmlXPathFreeContext(ctxt);
qemudFreeVMDef(def); qemudFreeVMDef(def);
@ -2263,7 +2261,6 @@ qemudNetworkIfaceConnect(virConnectPtr conn,
char *retval = NULL; char *retval = NULL;
int err; int err;
int tapfd = -1; int tapfd = -1;
int *tapfds;
if (net->type == QEMUD_NET_NETWORK) { if (net->type == QEMUD_NET_NETWORK) {
if (!(network = qemudFindNetworkByName(driver, net->dst.network.name))) { if (!(network = qemudFindNetworkByName(driver, net->dst.network.name))) {
@ -2320,10 +2317,9 @@ qemudNetworkIfaceConnect(virConnectPtr conn,
if (!(retval = strdup(tapfdstr))) if (!(retval = strdup(tapfdstr)))
goto no_memory; goto no_memory;
if (!(tapfds = realloc(vm->tapfds, sizeof(*tapfds) * (vm->ntapfds+2)))) if (VIR_ALLOC_N(vm->tapfds, vm->ntapfds+2) < 0)
goto no_memory; goto no_memory;
vm->tapfds = tapfds;
vm->tapfds[vm->ntapfds++] = tapfd; vm->tapfds[vm->ntapfds++] = tapfd;
vm->tapfds[vm->ntapfds] = -1; vm->tapfds[vm->ntapfds] = -1;
@ -2333,7 +2329,7 @@ qemudNetworkIfaceConnect(virConnectPtr conn,
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,
"%s", _("failed to allocate space for tapfds string")); "%s", _("failed to allocate space for tapfds string"));
error: error:
free(retval); VIR_FREE(retval);
if (tapfd != -1) if (tapfd != -1)
close(tapfd); close(tapfd);
return NULL; return NULL;
@ -2830,14 +2826,14 @@ int qemudBuildCommandLine(virConnectPtr conn,
/* Add sound hardware */ /* Add sound hardware */
if (sound) { if (sound) {
int size = 100; int size = 100;
char *modstr = calloc(1, size+1); char *modstr;
if (!modstr) if (VIR_ALLOC_N(modstr, size+1) < 0)
goto no_memory; goto no_memory;
while(sound && size > 0) { while(sound && size > 0) {
const char *model = qemudSoundModelToString(sound->model); const char *model = qemudSoundModelToString(sound->model);
if (!model) { if (!model) {
free(modstr); VIR_FREE(modstr);
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
"%s", _("invalid sound model")); "%s", _("invalid sound model"));
goto error; goto error;
@ -2869,14 +2865,14 @@ int qemudBuildCommandLine(virConnectPtr conn,
if (vm->tapfds) { if (vm->tapfds) {
for (i = 0; vm->tapfds[i] != -1; i++) for (i = 0; vm->tapfds[i] != -1; i++)
close(vm->tapfds[i]); close(vm->tapfds[i]);
free(vm->tapfds); VIR_FREE(vm->tapfds);
vm->tapfds = NULL; vm->tapfds = NULL;
vm->ntapfds = 0; vm->ntapfds = 0;
} }
if (qargv) { if (qargv) {
for (i = 0 ; i < qargc ; i++) for (i = 0 ; i < qargc ; i++)
free((qargv)[i]); VIR_FREE((qargv)[i]);
free(qargv); VIR_FREE(qargv);
} }
return -1; return -1;
@ -2928,7 +2924,7 @@ static int qemudSaveConfig(virConnectPtr conn,
if (fd != -1) if (fd != -1)
close(fd); close(fd);
free(xml); VIR_FREE(xml);
return ret; return ret;
} }
@ -2940,13 +2936,18 @@ qemudParseVMDeviceDef(virConnectPtr conn,
{ {
xmlDocPtr xml; xmlDocPtr xml;
xmlNodePtr node; xmlNodePtr node;
struct qemud_vm_device_def *dev = calloc(1, sizeof(*dev)); struct qemud_vm_device_def *dev;
if (VIR_ALLOC(dev) < 0) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
return NULL;
}
if (!(xml = xmlReadDoc(BAD_CAST xmlStr, "device.xml", NULL, if (!(xml = xmlReadDoc(BAD_CAST xmlStr, "device.xml", NULL,
XML_PARSE_NOENT | XML_PARSE_NONET | XML_PARSE_NOENT | XML_PARSE_NONET |
XML_PARSE_NOERROR | XML_PARSE_NOWARNING))) { XML_PARSE_NOERROR | XML_PARSE_NOWARNING))) {
qemudReportError(conn, NULL, NULL, VIR_ERR_XML_ERROR, NULL); qemudReportError(conn, NULL, NULL, VIR_ERR_XML_ERROR, NULL);
return NULL; goto error;
} }
node = xmlDocGetRootElement(xml); node = xmlDocGetRootElement(xml);
@ -2979,7 +2980,7 @@ qemudParseVMDeviceDef(virConnectPtr conn,
error: error:
if (xml) xmlFreeDoc(xml); if (xml) xmlFreeDoc(xml);
free(dev); VIR_FREE(dev);
return NULL; return NULL;
} }
@ -3027,7 +3028,7 @@ qemudAssignVMDef(virConnectPtr conn,
return vm; return vm;
} }
if (!(vm = calloc(1, sizeof(*vm)))) { if (VIR_ALLOC(vm) < 0) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,
"%s", _("failed to allocate space for vm string")); "%s", _("failed to allocate space for vm string"));
return NULL; return NULL;
@ -3155,7 +3156,7 @@ static int qemudSaveNetworkConfig(virConnectPtr conn,
cleanup: cleanup:
free(xml); VIR_FREE(xml);
return ret; return ret;
} }
@ -3164,17 +3165,17 @@ void qemudFreeNetworkDef(struct qemud_network_def *def) {
struct qemud_dhcp_range_def *range = def->ranges; struct qemud_dhcp_range_def *range = def->ranges;
while (range) { while (range) {
struct qemud_dhcp_range_def *next = range->next; struct qemud_dhcp_range_def *next = range->next;
free(range); VIR_FREE(range);
range = next; range = next;
} }
free(def); VIR_FREE(def);
} }
void qemudFreeNetwork(struct qemud_network *network) { void qemudFreeNetwork(struct qemud_network *network) {
qemudFreeNetworkDef(network->def); qemudFreeNetworkDef(network->def);
if (network->newDef) if (network->newDef)
qemudFreeNetworkDef(network->newDef); qemudFreeNetworkDef(network->newDef);
free(network); VIR_FREE(network);
} }
static int qemudParseBridgeXML(struct qemud_driver *driver ATTRIBUTE_UNUSED, static int qemudParseBridgeXML(struct qemud_driver *driver ATTRIBUTE_UNUSED,
@ -3227,7 +3228,7 @@ static int qemudParseDhcpRangesXML(virConnectPtr conn,
continue; continue;
} }
if (!(range = calloc(1, sizeof(*range)))) { if (VIR_ALLOC(range) < 0) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,
"%s", _("failed to allocate space for range string")); "%s", _("failed to allocate space for range string"));
return 0; return 0;
@ -3247,7 +3248,7 @@ static int qemudParseDhcpRangesXML(virConnectPtr conn,
def->ranges = range; def->ranges = range;
def->nranges++; def->nranges++;
} else { } else {
free(range); VIR_FREE(range);
} }
xmlFree(start); xmlFree(start);
@ -3318,7 +3319,7 @@ static struct qemud_network_def *qemudParseNetworkXML(virConnectPtr conn,
xmlXPathObjectPtr obj = NULL, tmp = NULL; xmlXPathObjectPtr obj = NULL, tmp = NULL;
struct qemud_network_def *def; struct qemud_network_def *def;
if (!(def = calloc(1, sizeof(*def)))) { if (VIR_ALLOC(def) < 0) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,
"%s", _("failed to allocate space for network_def string")); "%s", _("failed to allocate space for network_def string"));
return NULL; return NULL;
@ -3492,7 +3493,7 @@ qemudAssignNetworkDef(virConnectPtr conn,
return network; return network;
} }
if (!(network = calloc(1, sizeof(*network)))) { if (VIR_ALLOC(network) < 0) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,
"%s", _("failed to allocate space for network string")); "%s", _("failed to allocate space for network string"));
return NULL; return NULL;
@ -3703,7 +3704,7 @@ int qemudScanConfigDir(struct qemud_driver *driver,
else else
qemudLoadNetworkConfig(driver, entry->d_name, path, xml, autostartLink); qemudLoadNetworkConfig(driver, entry->d_name, path, xml, autostartLink);
free(xml); VIR_FREE(xml);
} }
closedir(dir); closedir(dir);
@ -3839,7 +3840,7 @@ char *qemudGenerateXML(virConnectPtr conn,
const struct qemud_vm_input_def *input; const struct qemud_vm_input_def *input;
const struct qemud_vm_sound_def *sound; const struct qemud_vm_sound_def *sound;
const struct qemud_vm_chr_def *chr; const struct qemud_vm_chr_def *chr;
const char *type = NULL; const char *type = NULL, *tmp;
int n, allones = 1; int n, allones = 1;
if (!(type = qemudVirtTypeToString(def->virtType))) { if (!(type = qemudVirtTypeToString(def->virtType))) {
@ -3876,7 +3877,7 @@ char *qemudGenerateXML(virConnectPtr conn,
goto cleanup; goto cleanup;
} }
virBufferVSprintf(&buf, " <vcpu cpuset='%s'>%d</vcpu>\n", cpumask, def->vcpus); virBufferVSprintf(&buf, " <vcpu cpuset='%s'>%d</vcpu>\n", cpumask, def->vcpus);
free(cpumask); VIR_FREE(cpumask);
} }
if (def->os.bootloader[0]) if (def->os.bootloader[0])
@ -4116,7 +4117,8 @@ char *qemudGenerateXML(virConnectPtr conn,
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,
"%s", _("failed to generate XML: out of memory")); "%s", _("failed to generate XML: out of memory"));
cleanup: cleanup:
free(virBufferContentAndReset(&buf)); tmp = virBufferContentAndReset(&buf);
VIR_FREE(tmp);
return NULL; return NULL;
} }
@ -4127,6 +4129,7 @@ char *qemudGenerateNetworkXML(virConnectPtr conn,
struct qemud_network_def *def) { struct qemud_network_def *def) {
virBuffer buf = VIR_BUFFER_INITIALIZER; virBuffer buf = VIR_BUFFER_INITIALIZER;
unsigned char *uuid; unsigned char *uuid;
char *tmp;
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
virBufferAddLit(&buf, "<network>\n"); virBufferAddLit(&buf, "<network>\n");
@ -4191,7 +4194,8 @@ char *qemudGenerateNetworkXML(virConnectPtr conn,
no_memory: no_memory:
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,
"%s", _("failed to generate XML: out of memory")); "%s", _("failed to generate XML: out of memory"));
free(virBufferContentAndReset(&buf)); tmp = virBufferContentAndReset(&buf);
VIR_FREE(tmp);
return NULL; return NULL;
} }

View File

@ -178,9 +178,8 @@ qemudStartup(void) {
char *base = NULL; char *base = NULL;
char driverConf[PATH_MAX]; char driverConf[PATH_MAX];
if (!(qemu_driver = calloc(1, sizeof(*qemu_driver)))) { if (VIR_ALLOC(qemu_driver) < 0)
return -1; return -1;
}
/* Don't have a dom0 so start from 1 */ /* Don't have a dom0 so start from 1 */
qemu_driver->nextvmid = 1; qemu_driver->nextvmid = 1;
@ -228,8 +227,7 @@ qemudStartup(void) {
base) == -1) base) == -1)
goto out_of_memory; goto out_of_memory;
free(base); VIR_FREE(base);
base = NULL;
if ((qemu_driver->caps = qemudCapsInit()) == NULL) if ((qemu_driver->caps = qemudCapsInit()) == NULL)
goto out_of_memory; goto out_of_memory;
@ -255,9 +253,8 @@ qemudStartup(void) {
out_of_memory: out_of_memory:
qemudLog (QEMUD_ERR, qemudLog (QEMUD_ERR,
"%s", _("qemudStartup: out of memory")); "%s", _("qemudStartup: out of memory"));
free (base); VIR_FREE(base);
free(qemu_driver); VIR_FREE(qemu_driver);
qemu_driver = NULL;
return -1; return -1;
} }
@ -360,19 +357,18 @@ qemudShutdown(void) {
qemu_driver->nactivenetworks = 0; qemu_driver->nactivenetworks = 0;
qemu_driver->ninactivenetworks = 0; qemu_driver->ninactivenetworks = 0;
free(qemu_driver->configDir); VIR_FREE(qemu_driver->configDir);
free(qemu_driver->autostartDir); VIR_FREE(qemu_driver->autostartDir);
free(qemu_driver->networkConfigDir); VIR_FREE(qemu_driver->networkConfigDir);
free(qemu_driver->networkAutostartDir); VIR_FREE(qemu_driver->networkAutostartDir);
free(qemu_driver->vncTLSx509certdir); VIR_FREE(qemu_driver->vncTLSx509certdir);
if (qemu_driver->brctl) if (qemu_driver->brctl)
brShutdown(qemu_driver->brctl); brShutdown(qemu_driver->brctl);
if (qemu_driver->iptables) if (qemu_driver->iptables)
iptablesContextFree(qemu_driver->iptables); iptablesContextFree(qemu_driver->iptables);
free(qemu_driver); VIR_FREE(qemu_driver);
qemu_driver = NULL;
return 0; return 0;
} }
@ -701,13 +697,13 @@ qemudDetectVcpuPIDs(virConnectPtr conn,
if (lastVcpu != (vm->def->vcpus - 1)) if (lastVcpu != (vm->def->vcpus - 1))
goto error; goto error;
free(qemucpus); VIR_FREE(qemucpus);
return 0; return 0;
error: error:
VIR_FREE(vm->vcpupids); VIR_FREE(vm->vcpupids);
vm->vcpupids = 0; vm->nvcpupids = 0;
free(qemucpus); VIR_FREE(qemucpus);
/* Explicitly return success, not error. Older KVM does /* Explicitly return success, not error. Older KVM does
not have vCPU -> Thread mapping info and we don't not have vCPU -> Thread mapping info and we don't
@ -756,7 +752,7 @@ qemudInitCpus(virConnectPtr conn,
"%s", _("resume operation failed")); "%s", _("resume operation failed"));
return -1; return -1;
} }
free(info); VIR_FREE(info);
return 0; return 0;
} }
@ -905,16 +901,15 @@ static int qemudStartVMDaemon(virConnectPtr conn,
} }
for (i = 0 ; argv[i] ; i++) for (i = 0 ; argv[i] ; i++)
free(argv[i]); VIR_FREE(argv[i]);
free(argv); VIR_FREE(argv);
if (vm->tapfds) { if (vm->tapfds) {
for (i = 0; vm->tapfds[i] != -1; i++) { for (i = 0; vm->tapfds[i] != -1; i++) {
close(vm->tapfds[i]); close(vm->tapfds[i]);
vm->tapfds[i] = -1; vm->tapfds[i] = -1;
} }
free(vm->tapfds); VIR_FREE(vm->tapfds);
vm->tapfds = NULL;
vm->ntapfds = 0; vm->ntapfds = 0;
} }
@ -1005,8 +1000,7 @@ static void qemudShutdownVMDaemon(virConnectPtr conn ATTRIBUTE_UNUSED,
vm->pid = -1; vm->pid = -1;
vm->id = -1; vm->id = -1;
vm->state = VIR_DOMAIN_SHUTOFF; vm->state = VIR_DOMAIN_SHUTOFF;
free(vm->vcpupids); VIR_FREE(vm->vcpupids);
vm->vcpupids = NULL;
vm->nvcpupids = 0; vm->nvcpupids = 0;
if (vm->newDef) { if (vm->newDef) {
@ -1058,7 +1052,7 @@ qemudBuildDnsmasqArgv(virConnectPtr conn,
(2 * network->def->nranges) + /* --dhcp-range 10.0.0.2,10.0.0.254 */ (2 * network->def->nranges) + /* --dhcp-range 10.0.0.2,10.0.0.254 */
1; /* NULL */ 1; /* NULL */
if (!(*argv = calloc(len, sizeof(**argv)))) if (VIR_ALLOC_N(*argv, len) < 0)
goto no_memory; goto no_memory;
#define APPEND_ARG(v, n, s) do { \ #define APPEND_ARG(v, n, s) do { \
@ -1126,8 +1120,8 @@ qemudBuildDnsmasqArgv(virConnectPtr conn,
no_memory: no_memory:
if (argv) { if (argv) {
for (i = 0; (*argv)[i]; i++) for (i = 0; (*argv)[i]; i++)
free((*argv)[i]); VIR_FREE((*argv)[i]);
free(*argv); VIR_FREE(*argv);
} }
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,
"%s", _("failed to allocate space for dnsmasq argv")); "%s", _("failed to allocate space for dnsmasq argv"));
@ -1155,8 +1149,8 @@ dhcpStartDhcpDaemon(virConnectPtr conn,
ret = virExecNonBlock(conn, argv, &network->dnsmasqPid, -1, NULL, NULL); ret = virExecNonBlock(conn, argv, &network->dnsmasqPid, -1, NULL, NULL);
for (i = 0; argv[i]; i++) for (i = 0; argv[i]; i++)
free(argv[i]); VIR_FREE(argv[i]);
free(argv); VIR_FREE(argv);
return ret; return ret;
} }
@ -1625,7 +1619,6 @@ qemudMonitorCommand (const struct qemud_driver *driver ATTRIBUTE_UNUSED,
for (;;) { for (;;) {
char data[1024]; char data[1024];
int got = read(vm->monitor, data, sizeof(data)); int got = read(vm->monitor, data, sizeof(data));
char *b;
if (got == 0) if (got == 0)
goto error; goto error;
@ -1636,10 +1629,9 @@ qemudMonitorCommand (const struct qemud_driver *driver ATTRIBUTE_UNUSED,
break; break;
goto error; goto error;
} }
if (!(b = realloc(buf, size+got+1))) if (VIR_REALLOC_N(buf, size+got+1) < 0)
goto error; goto error;
buf = b;
memmove(buf+size, data, got); memmove(buf+size, data, got);
buf[size+got] = '\0'; buf[size+got] = '\0';
size += got; size += got;
@ -1673,7 +1665,7 @@ qemudMonitorCommand (const struct qemud_driver *driver ATTRIBUTE_UNUSED,
if (safewrite(vm->logfile, buf, strlen(buf)) < 0) if (safewrite(vm->logfile, buf, strlen(buf)) < 0)
qemudLog(QEMUD_WARN, _("Unable to log VM console data: %s"), qemudLog(QEMUD_WARN, _("Unable to log VM console data: %s"),
strerror(errno)); strerror(errno));
free(buf); VIR_FREE(buf);
} }
return -1; return -1;
} }
@ -2017,7 +2009,7 @@ static int qemudDomainSuspend(virDomainPtr dom) {
} }
vm->state = VIR_DOMAIN_PAUSED; vm->state = VIR_DOMAIN_PAUSED;
qemudDebug("Reply %s", info); qemudDebug("Reply %s", info);
free(info); VIR_FREE(info);
return 0; return 0;
} }
@ -2045,7 +2037,7 @@ static int qemudDomainResume(virDomainPtr dom) {
} }
vm->state = VIR_DOMAIN_RUNNING; vm->state = VIR_DOMAIN_RUNNING;
qemudDebug("Reply %s", info); qemudDebug("Reply %s", info);
free(info); VIR_FREE(info);
return 0; return 0;
} }
@ -2229,7 +2221,7 @@ static char *qemudEscape(const char *in, int shell)
} }
} }
if ((out = (char *)malloc(len + 1)) == NULL) if (VIR_ALLOC_N(out, len + 1) < 0)
return NULL; return NULL;
for (i = j = 0; in[i] != '\0'; i++) { for (i = j = 0; in[i] != '\0'; i++) {
@ -2338,7 +2330,7 @@ static int qemudDomainSave(virDomainPtr dom,
if ((fd = open(path, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR)) < 0) { if ((fd = open(path, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR)) < 0) {
qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED, qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
_("failed to create '%s'"), path); _("failed to create '%s'"), path);
free(xml); VIR_FREE(xml);
return -1; return -1;
} }
@ -2346,7 +2338,7 @@ static int qemudDomainSave(virDomainPtr dom,
qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED, qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
"%s", _("failed to write save header")); "%s", _("failed to write save header"));
close(fd); close(fd);
free(xml); VIR_FREE(xml);
return -1; return -1;
} }
@ -2354,12 +2346,12 @@ static int qemudDomainSave(virDomainPtr dom,
qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED, qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
"%s", _("failed to write xml")); "%s", _("failed to write xml"));
close(fd); close(fd);
free(xml); VIR_FREE(xml);
return -1; return -1;
} }
close(fd); close(fd);
free(xml); VIR_FREE(xml);
/* Migrate to file */ /* Migrate to file */
safe_path = qemudEscapeShellArg(path); safe_path = qemudEscapeShellArg(path);
@ -2373,7 +2365,7 @@ static int qemudDomainSave(virDomainPtr dom,
"\"", safe_path) == -1) { "\"", safe_path) == -1) {
qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED, qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
"%s", _("out of memory")); "%s", _("out of memory"));
free(safe_path); VIR_FREE(safe_path);
return -1; return -1;
} }
free(safe_path); free(safe_path);
@ -2381,12 +2373,12 @@ static int qemudDomainSave(virDomainPtr dom,
if (qemudMonitorCommand(driver, vm, command, &info) < 0) { if (qemudMonitorCommand(driver, vm, command, &info) < 0) {
qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED, qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
"%s", _("migrate operation failed")); "%s", _("migrate operation failed"));
free(command); VIR_FREE(command);
return -1; return -1;
} }
free(info); VIR_FREE(info);
free(command); VIR_FREE(command);
/* Shut it down */ /* Shut it down */
qemudShutdownVMDaemon(dom->conn, driver, vm); qemudShutdownVMDaemon(dom->conn, driver, vm);
@ -2621,7 +2613,7 @@ static int qemudDomainRestore(virConnectPtr conn,
return -1; return -1;
} }
if ((xml = (char *)malloc(header.xml_len)) == NULL) { if (VIR_ALLOC_N(xml, header.xml_len) < 0) {
qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_FAILED, qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_FAILED,
"%s", _("out of memory")); "%s", _("out of memory"));
close(fd); close(fd);
@ -2632,7 +2624,7 @@ static int qemudDomainRestore(virConnectPtr conn,
qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_FAILED, qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_FAILED,
"%s", _("failed to read XML")); "%s", _("failed to read XML"));
close(fd); close(fd);
free(xml); VIR_FREE(xml);
return -1; return -1;
} }
@ -2641,10 +2633,10 @@ static int qemudDomainRestore(virConnectPtr conn,
qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_FAILED, qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_FAILED,
"%s", _("failed to parse XML")); "%s", _("failed to parse XML"));
close(fd); close(fd);
free(xml); VIR_FREE(xml);
return -1; return -1;
} }
free(xml); VIR_FREE(xml);
/* Ensure the name and UUID don't already exist in an active VM */ /* Ensure the name and UUID don't already exist in an active VM */
vm = qemudFindVMByUUID(driver, def->uuid); vm = qemudFindVMByUUID(driver, def->uuid);
@ -2687,7 +2679,7 @@ static int qemudDomainRestore(virConnectPtr conn,
"%s", _("failed to resume domain")); "%s", _("failed to resume domain"));
return -1; return -1;
} }
free(info); VIR_FREE(info);
vm->state = VIR_DOMAIN_RUNNING; vm->state = VIR_DOMAIN_RUNNING;
} }
@ -2729,7 +2721,7 @@ static int qemudListDefinedDomains(virConnectPtr conn,
cleanup: cleanup:
for (i = 0 ; i < got ; i++) for (i = 0 ; i < got ; i++)
free(names[i]); VIR_FREE(names[i]);
return -1; return -1;
} }
@ -2829,10 +2821,10 @@ static int qemudDomainChangeCDROM(virDomainPtr dom,
safe_path) == -1) { safe_path) == -1) {
qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED, qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
"%s", _("out of memory")); "%s", _("out of memory"));
free(safe_path); VIR_FREE(safe_path);
return -1; return -1;
} }
free(safe_path); VIR_FREE(safe_path);
} else if (asprintf(&cmd, "eject cdrom") == -1) { } else if (asprintf(&cmd, "eject cdrom") == -1) {
qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED, qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
@ -2843,11 +2835,11 @@ static int qemudDomainChangeCDROM(virDomainPtr dom,
if (qemudMonitorCommand(driver, vm, cmd, &reply) < 0) { if (qemudMonitorCommand(driver, vm, cmd, &reply) < 0) {
qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED, qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
"%s", _("cannot change cdrom media")); "%s", _("cannot change cdrom media"));
free(cmd); VIR_FREE(cmd);
return -1; return -1;
} }
free(reply); VIR_FREE(reply);
free(cmd); VIR_FREE(cmd);
strcpy(olddisk->src, newdisk->src); strcpy(olddisk->src, newdisk->src);
olddisk->type = newdisk->type; olddisk->type = newdisk->type;
return 0; return 0;
@ -2880,7 +2872,7 @@ static int qemudDomainAttachDevice(virDomainPtr dom,
if (dev->type != QEMUD_DEVICE_DISK || dev->data.disk.device != QEMUD_DISK_CDROM) { if (dev->type != QEMUD_DEVICE_DISK || dev->data.disk.device != QEMUD_DISK_CDROM) {
qemudReportError(dom->conn, dom, NULL, VIR_ERR_NO_SUPPORT, qemudReportError(dom->conn, dom, NULL, VIR_ERR_NO_SUPPORT,
"%s", _("only CDROM disk devices can be attached")); "%s", _("only CDROM disk devices can be attached"));
free(dev); VIR_FREE(dev);
return -1; return -1;
} }
@ -2895,16 +2887,16 @@ static int qemudDomainAttachDevice(virDomainPtr dom,
if (!disk) { if (!disk) {
qemudReportError(dom->conn, dom, NULL, VIR_ERR_NO_SUPPORT, qemudReportError(dom->conn, dom, NULL, VIR_ERR_NO_SUPPORT,
"%s", _("CDROM not attached, cannot change media")); "%s", _("CDROM not attached, cannot change media"));
free(dev); VIR_FREE(dev);
return -1; return -1;
} }
if (qemudDomainChangeCDROM(dom, vm, disk, &dev->data.disk) < 0) { if (qemudDomainChangeCDROM(dom, vm, disk, &dev->data.disk) < 0) {
free(dev); VIR_FREE(dev);
return -1; return -1;
} }
free(dev); VIR_FREE(dev);
return 0; return 0;
} }
@ -3242,7 +3234,7 @@ static int qemudListNetworks(virConnectPtr conn, char **const names, int nnames)
cleanup: cleanup:
for (i = 0 ; i < got ; i++) for (i = 0 ; i < got ; i++)
free(names[i]); VIR_FREE(names[i]);
return -1; return -1;
} }
@ -3270,7 +3262,7 @@ static int qemudListDefinedNetworks(virConnectPtr conn, char **const names, int
cleanup: cleanup:
for (i = 0 ; i < got ; i++) for (i = 0 ; i < got ; i++)
free(names[i]); VIR_FREE(names[i]);
return -1; return -1;
} }

View File

@ -45,6 +45,7 @@
#include "util.h" #include "util.h"
#include "uuid.h" #include "uuid.h"
#include "capabilities.h" #include "capabilities.h"
#include "memory.h"
/* Flags that determine the action to take on a shutdown or crash of a domain /* Flags that determine the action to take on a shutdown or crash of a domain
*/ */
@ -275,7 +276,7 @@ static int testLoadDomain(virConnectPtr conn,
testError(conn, NULL, NULL, VIR_ERR_XML_ERROR, _("domain uuid")); testError(conn, NULL, NULL, VIR_ERR_XML_ERROR, _("domain uuid"));
goto error; goto error;
} }
free(str); VIR_FREE(str);
ret = virXPathLong("string(/domain/memory[1])", ctxt, &l); ret = virXPathLong("string(/domain/memory[1])", ctxt, &l);
@ -309,30 +310,30 @@ static int testLoadDomain(virConnectPtr conn,
if (str != NULL) { if (str != NULL) {
if (!(onReboot = testRestartStringToFlag(str))) { if (!(onReboot = testRestartStringToFlag(str))) {
testError(conn, NULL, NULL, VIR_ERR_XML_ERROR, _("domain reboot behaviour")); testError(conn, NULL, NULL, VIR_ERR_XML_ERROR, _("domain reboot behaviour"));
free(str); VIR_FREE(str);
goto error; goto error;
} }
free(str); VIR_FREE(str);
} }
str = virXPathString("string(/domain/on_poweroff[1])", ctxt); str = virXPathString("string(/domain/on_poweroff[1])", ctxt);
if (str != NULL) { if (str != NULL) {
if (!(onPoweroff = testRestartStringToFlag(str))) { if (!(onPoweroff = testRestartStringToFlag(str))) {
testError(conn, NULL, NULL, VIR_ERR_XML_ERROR, _("domain poweroff behaviour")); testError(conn, NULL, NULL, VIR_ERR_XML_ERROR, _("domain poweroff behaviour"));
free(str); VIR_FREE(str);
goto error; goto error;
} }
free(str); VIR_FREE(str);
} }
str = virXPathString("string(/domain/on_crash[1])", ctxt); str = virXPathString("string(/domain/on_crash[1])", ctxt);
if (str != NULL) { if (str != NULL) {
if (!(onCrash = testRestartStringToFlag(str))) { if (!(onCrash = testRestartStringToFlag(str))) {
testError(conn, NULL, NULL, VIR_ERR_XML_ERROR, _("domain crash behaviour")); testError(conn, NULL, NULL, VIR_ERR_XML_ERROR, _("domain crash behaviour"));
free(str); VIR_FREE(str);
goto error; goto error;
} }
free(str); VIR_FREE(str);
} }
for (i = 0 ; i < MAX_DOMAINS ; i++) { for (i = 0 ; i < MAX_DOMAINS ; i++) {
@ -348,7 +349,7 @@ static int testLoadDomain(virConnectPtr conn,
privconn->domains[handle].id = domid; privconn->domains[handle].id = domid;
strncpy(privconn->domains[handle].name, name, sizeof(privconn->domains[handle].name)-1); strncpy(privconn->domains[handle].name, name, sizeof(privconn->domains[handle].name)-1);
privconn->domains[handle].name[sizeof(privconn->domains[handle].name)-1] = '\0'; privconn->domains[handle].name[sizeof(privconn->domains[handle].name)-1] = '\0';
free(name); VIR_FREE(name);
name = NULL; name = NULL;
if (memory > maxMem) if (memory > maxMem)
@ -371,7 +372,7 @@ static int testLoadDomain(virConnectPtr conn,
error: error:
xmlXPathFreeContext(ctxt); xmlXPathFreeContext(ctxt);
free(name); VIR_FREE(name);
return (-1); return (-1);
} }
@ -464,7 +465,7 @@ static int testLoadNetwork(virConnectPtr conn,
testError(conn, NULL, NULL, VIR_ERR_XML_ERROR, _("network uuid")); testError(conn, NULL, NULL, VIR_ERR_XML_ERROR, _("network uuid"));
goto error; goto error;
} }
free(str); VIR_FREE(str);
forward = virXPathBoolean("count(/network/forward) != 0", ctxt); forward = virXPathBoolean("count(/network/forward) != 0", ctxt);
@ -512,10 +513,10 @@ static int testLoadNetwork(virConnectPtr conn,
privconn->networks[handle].name[sizeof(privconn->networks[handle].name)-1] = '\0'; privconn->networks[handle].name[sizeof(privconn->networks[handle].name)-1] = '\0';
strncpy(privconn->networks[handle].bridge, bridge ? bridge : name, sizeof(privconn->networks[handle].bridge)-1); strncpy(privconn->networks[handle].bridge, bridge ? bridge : name, sizeof(privconn->networks[handle].bridge)-1);
privconn->networks[handle].bridge[sizeof(privconn->networks[handle].bridge)-1] = '\0'; privconn->networks[handle].bridge[sizeof(privconn->networks[handle].bridge)-1] = '\0';
free(name); VIR_FREE(name);
name = NULL; name = NULL;
if (bridge) { if (bridge) {
free(bridge); VIR_FREE(bridge);
bridge = NULL; bridge = NULL;
} }
@ -524,32 +525,32 @@ static int testLoadNetwork(virConnectPtr conn,
if (forwardDev) { if (forwardDev) {
strncpy(privconn->networks[handle].forwardDev, forwardDev, sizeof(privconn->networks[handle].forwardDev)-1); strncpy(privconn->networks[handle].forwardDev, forwardDev, sizeof(privconn->networks[handle].forwardDev)-1);
privconn->networks[handle].forwardDev[sizeof(privconn->networks[handle].forwardDev)-1] = '\0'; privconn->networks[handle].forwardDev[sizeof(privconn->networks[handle].forwardDev)-1] = '\0';
free(forwardDev); VIR_FREE(forwardDev);
} }
strncpy(privconn->networks[handle].ipAddress, ipaddress, sizeof(privconn->networks[handle].ipAddress)-1); strncpy(privconn->networks[handle].ipAddress, ipaddress, sizeof(privconn->networks[handle].ipAddress)-1);
privconn->networks[handle].ipAddress[sizeof(privconn->networks[handle].ipAddress)-1] = '\0'; privconn->networks[handle].ipAddress[sizeof(privconn->networks[handle].ipAddress)-1] = '\0';
free(ipaddress); VIR_FREE(ipaddress);
strncpy(privconn->networks[handle].ipNetmask, ipnetmask, sizeof(privconn->networks[handle].ipNetmask)-1); strncpy(privconn->networks[handle].ipNetmask, ipnetmask, sizeof(privconn->networks[handle].ipNetmask)-1);
privconn->networks[handle].ipNetmask[sizeof(privconn->networks[handle].ipNetmask)-1] = '\0'; privconn->networks[handle].ipNetmask[sizeof(privconn->networks[handle].ipNetmask)-1] = '\0';
free(ipnetmask); VIR_FREE(ipnetmask);
strncpy(privconn->networks[handle].dhcpStart, dhcpstart, sizeof(privconn->networks[handle].dhcpStart)-1); strncpy(privconn->networks[handle].dhcpStart, dhcpstart, sizeof(privconn->networks[handle].dhcpStart)-1);
privconn->networks[handle].dhcpStart[sizeof(privconn->networks[handle].dhcpStart)-1] = '\0'; privconn->networks[handle].dhcpStart[sizeof(privconn->networks[handle].dhcpStart)-1] = '\0';
free(dhcpstart); VIR_FREE(dhcpstart);
strncpy(privconn->networks[handle].dhcpEnd, dhcpend, sizeof(privconn->networks[handle].dhcpEnd)-1); strncpy(privconn->networks[handle].dhcpEnd, dhcpend, sizeof(privconn->networks[handle].dhcpEnd)-1);
privconn->networks[handle].dhcpEnd[sizeof(privconn->networks[handle].dhcpEnd)-1] = '\0'; privconn->networks[handle].dhcpEnd[sizeof(privconn->networks[handle].dhcpEnd)-1] = '\0';
free(dhcpend); VIR_FREE(dhcpend);
xmlXPathFreeContext(ctxt); xmlXPathFreeContext(ctxt);
return (handle); return (handle);
error: error:
xmlXPathFreeContext(ctxt); xmlXPathFreeContext(ctxt);
free (forwardDev); VIR_FREE (forwardDev);
free(ipaddress); VIR_FREE(ipaddress);
free(ipnetmask); VIR_FREE(ipnetmask);
free(dhcpstart); VIR_FREE(dhcpstart);
free(dhcpend); VIR_FREE(dhcpend);
free(name); VIR_FREE(name);
return (-1); return (-1);
} }
@ -601,8 +602,8 @@ static int testLoadNetworkFromFile(virConnectPtr conn,
static int testOpenDefault(virConnectPtr conn) { static int testOpenDefault(virConnectPtr conn) {
int u; int u;
struct timeval tv; struct timeval tv;
testConnPtr privconn = malloc(sizeof(*privconn)); testConnPtr privconn;
if (!privconn) { if (VIR_ALLOC(privconn) < 0) {
testError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "testConn"); testError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "testConn");
return VIR_DRV_OPEN_ERROR; return VIR_DRV_OPEN_ERROR;
} }
@ -677,7 +678,9 @@ static char *testBuildFilename(const char *relativeTo,
offset = strrchr(relativeTo, '/'); offset = strrchr(relativeTo, '/');
if ((baseLen = (offset-relativeTo+1))) { if ((baseLen = (offset-relativeTo+1))) {
char *absFile = malloc(baseLen + strlen(filename) + 1); char *absFile;
if (VIR_ALLOC_N(absFile, baseLen + strlen(filename) + 1) < 0)
return NULL;
strncpy(absFile, relativeTo, baseLen); strncpy(absFile, relativeTo, baseLen);
absFile[baseLen] = '\0'; absFile[baseLen] = '\0';
strcat(absFile, filename); strcat(absFile, filename);
@ -697,8 +700,8 @@ static int testOpenFromFile(virConnectPtr conn,
xmlNodePtr *domains, *networks = NULL; xmlNodePtr *domains, *networks = NULL;
xmlXPathContextPtr ctxt = NULL; xmlXPathContextPtr ctxt = NULL;
virNodeInfoPtr nodeInfo; virNodeInfoPtr nodeInfo;
testConnPtr privconn = calloc(1, sizeof(*privconn)); testConnPtr privconn;
if (!privconn) { if (VIR_ALLOC(privconn) < 0) {
testError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "testConn"); testError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "testConn");
return VIR_DRV_OPEN_ERROR; return VIR_DRV_OPEN_ERROR;
} }
@ -794,7 +797,7 @@ static int testOpenFromFile(virConnectPtr conn,
if (str != NULL) { if (str != NULL) {
strncpy(nodeInfo->model, str, sizeof(nodeInfo->model)-1); strncpy(nodeInfo->model, str, sizeof(nodeInfo->model)-1);
nodeInfo->model[sizeof(nodeInfo->model)-1] = '\0'; nodeInfo->model[sizeof(nodeInfo->model)-1] = '\0';
free(str); VIR_FREE(str);
} }
ret = virXPathLong("string(/node/memory[1])", ctxt, &l); ret = virXPathLong("string(/node/memory[1])", ctxt, &l);
@ -815,21 +818,21 @@ static int testOpenFromFile(virConnectPtr conn,
xmlChar *domFile = xmlGetProp(domains[i], BAD_CAST "file"); xmlChar *domFile = xmlGetProp(domains[i], BAD_CAST "file");
char *absFile = testBuildFilename(file, (const char *)domFile); char *absFile = testBuildFilename(file, (const char *)domFile);
int domid = privconn->nextDomID++, handle; int domid = privconn->nextDomID++, handle;
free(domFile); VIR_FREE(domFile);
if (!absFile) { if (!absFile) {
testError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, _("resolving domain filename")); testError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, _("resolving domain filename"));
goto error; goto error;
} }
if ((handle = testLoadDomainFromFile(conn, domid, absFile)) < 0) { if ((handle = testLoadDomainFromFile(conn, domid, absFile)) < 0) {
free(absFile); VIR_FREE(absFile);
goto error; goto error;
} }
privconn->domains[handle].config = 1; privconn->domains[handle].config = 1;
free(absFile); VIR_FREE(absFile);
privconn->numDomains++; privconn->numDomains++;
} }
if (domains != NULL) { if (domains != NULL) {
free(domains); VIR_FREE(domains);
domains = NULL; domains = NULL;
} }
@ -840,21 +843,21 @@ static int testOpenFromFile(virConnectPtr conn,
xmlChar *netFile = xmlGetProp(networks[i], BAD_CAST "file"); xmlChar *netFile = xmlGetProp(networks[i], BAD_CAST "file");
char *absFile = testBuildFilename(file, (const char *)netFile); char *absFile = testBuildFilename(file, (const char *)netFile);
int handle; int handle;
free(netFile); VIR_FREE(netFile);
if (!absFile) { if (!absFile) {
testError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, _("resolving network filename")); testError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, _("resolving network filename"));
goto error; goto error;
} }
if ((handle = testLoadNetworkFromFile(conn, absFile)) < 0) { if ((handle = testLoadNetworkFromFile(conn, absFile)) < 0) {
free(absFile); VIR_FREE(absFile);
goto error; goto error;
} }
privconn->networks[handle].config = 1; privconn->networks[handle].config = 1;
free(absFile); VIR_FREE(absFile);
privconn->numNetworks++; privconn->numNetworks++;
} }
if (networks != NULL) { if (networks != NULL) {
free(networks); VIR_FREE(networks);
networks = NULL; networks = NULL;
} }
} }
@ -866,13 +869,13 @@ static int testOpenFromFile(virConnectPtr conn,
error: error:
xmlXPathFreeContext(ctxt); xmlXPathFreeContext(ctxt);
free(domains); VIR_FREE(domains);
free(networks); VIR_FREE(networks);
if (xml) if (xml)
xmlFreeDoc(xml); xmlFreeDoc(xml);
if (fd != -1) if (fd != -1)
close(fd); close(fd);
free(privconn); VIR_FREE(privconn);
conn->privateData = NULL; conn->privateData = NULL;
return VIR_DRV_OPEN_ERROR; return VIR_DRV_OPEN_ERROR;
} }
@ -945,7 +948,7 @@ static int testOpen(virConnectPtr conn,
static int testClose(virConnectPtr conn) static int testClose(virConnectPtr conn)
{ {
GET_CONNECTION(conn, -1); GET_CONNECTION(conn, -1);
free (privconn); VIR_FREE (privconn);
conn->privateData = conn; conn->privateData = conn;
return 0; return 0;
} }
@ -1361,11 +1364,11 @@ static int testDomainSave(virDomainPtr domain,
if (safewrite(fd, xml, len) < 0) { if (safewrite(fd, xml, len) < 0) {
testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR, testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR,
_("cannot write metadata")); _("cannot write metadata"));
free(xml); VIR_FREE(xml);
close(fd); close(fd);
return (-1); return (-1);
} }
free(xml); VIR_FREE(xml);
if (close(fd) < 0) { if (close(fd) < 0) {
testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR, testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR,
_("cannot save domain data")); _("cannot save domain data"));
@ -1419,8 +1422,7 @@ static int testDomainRestore(virConnectPtr conn,
close(fd); close(fd);
return (-1); return (-1);
} }
xml = malloc(len+1); if (VIR_ALLOC_N(xml, len+1) < 0) {
if (!xml) {
testError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "xml"); testError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "xml");
close(fd); close(fd);
return (-1); return (-1);
@ -1435,7 +1437,7 @@ static int testDomainRestore(virConnectPtr conn,
close(fd); close(fd);
domid = privconn->nextDomID++; domid = privconn->nextDomID++;
ret = testLoadDomainFromDoc(conn, domid, xml); ret = testLoadDomainFromDoc(conn, domid, xml);
free(xml); VIR_FREE(xml);
return ret < 0 ? -1 : 0; return ret < 0 ? -1 : 0;
} }

View File

@ -47,7 +47,7 @@
#include "event.h" #include "event.h"
#include "buf.h" #include "buf.h"
#include "util.h" #include "util.h"
#include "memory.h"
#include "util-lib.c" #include "util-lib.c"
#ifndef MIN #ifndef MIN
@ -302,19 +302,14 @@ fread_file_lim (FILE *stream, size_t max_len, size_t *length)
size_t requested; size_t requested;
if (size + BUFSIZ + 1 > alloc) { if (size + BUFSIZ + 1 > alloc) {
char *new_buf;
alloc += alloc / 2; alloc += alloc / 2;
if (alloc < size + BUFSIZ + 1) if (alloc < size + BUFSIZ + 1)
alloc = size + BUFSIZ + 1; alloc = size + BUFSIZ + 1;
new_buf = realloc (buf, alloc); if (VIR_ALLOC_N(buf, alloc) < 0) {
if (!new_buf) {
save_errno = errno; save_errno = errno;
break; break;
} }
buf = new_buf;
} }
/* Ensure that (size + requested <= max_len); */ /* Ensure that (size + requested <= max_len); */
@ -358,7 +353,7 @@ int __virFileReadAll(const char *path, int maxlen, char **buf)
} }
if (len > maxlen || (int)len != len) { if (len > maxlen || (int)len != len) {
free(s); VIR_FREE(s);
virLog("File '%s' is too large %d, max %d", virLog("File '%s' is too large %d, max %d",
path, (int)len, maxlen); path, (int)len, maxlen);
goto error; goto error;

View File

@ -44,6 +44,7 @@
#include "xend_internal.h" #include "xend_internal.h"
#include "xen_internal.h" /* for DOM0_INTERFACE_VERSION */ #include "xen_internal.h" /* for DOM0_INTERFACE_VERSION */
#include "xs_internal.h" /* To extract VNC port & Serial console TTY */ #include "xs_internal.h" /* To extract VNC port & Serial console TTY */
#include "memory.h"
/* required for cpumap_t */ /* required for cpumap_t */
#include <xen/dom0_ops.h> #include <xen/dom0_ops.h>
@ -630,7 +631,7 @@ xend_op_ext2(virConnectPtr xend, const char *path, char *error,
content = virBufferContentAndReset(&buf); content = virBufferContentAndReset(&buf);
ret = http2unix(xend, xend_post(xend, path, content, error, n_error)); ret = http2unix(xend, xend_post(xend, path, content, error, n_error));
free(content); VIR_FREE(content);
return ret; return ret;
} }
@ -825,14 +826,15 @@ static char *
urlencode(const char *string) urlencode(const char *string)
{ {
size_t len = strlen(string); size_t len = strlen(string);
char *buffer = malloc(len * 3 + 1); char *buffer;
char *ptr = buffer; char *ptr;
size_t i; size_t i;
if (buffer == NULL) { if (VIR_ALLOC_N(buffer, len * 3 + 1) < 0) {
virXendError(NULL, VIR_ERR_NO_MEMORY, _("allocate new buffer")); virXendError(NULL, VIR_ERR_NO_MEMORY, _("allocate new buffer"));
return (NULL); return (NULL);
} }
ptr = buffer;
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
switch (string[i]) { switch (string[i]) {
case ' ': case ' ':
@ -909,6 +911,7 @@ int is_sound_model_conflict(const char *model, const char *soundstr) {
char *sound_string_to_xml(const char *sound) { char *sound_string_to_xml(const char *sound) {
virBuffer buf = VIR_BUFFER_INITIALIZER; virBuffer buf = VIR_BUFFER_INITIALIZER;
char *tmp;
while (sound) { while (sound) {
int modelsize, valid, collision = 0; int modelsize, valid, collision = 0;
@ -925,15 +928,16 @@ char *sound_string_to_xml(const char *sound) {
if (STREQ(model, "all")) { if (STREQ(model, "all")) {
int i; int i;
if (virBufferError(&buf)) { if (virBufferError(&buf)) {
free(model); VIR_FREE(model);
goto error; goto error;
} }
free(virBufferContentAndReset(&buf)); tmp = virBufferContentAndReset(&buf);
VIR_FREE(tmp);
for (i=0; i < sizeof(sound_models)/sizeof(*sound_models); ++i) for (i=0; i < sizeof(sound_models)/sizeof(*sound_models); ++i)
virBufferVSprintf(&buf, " <sound model='%s'/>\n", virBufferVSprintf(&buf, " <sound model='%s'/>\n",
sound_models[i]); sound_models[i]);
free(model); VIR_FREE(model);
break; break;
} }
} }
@ -944,7 +948,7 @@ char *sound_string_to_xml(const char *sound) {
virBufferVSprintf(&buf, " <sound model='%s'/>\n", model); virBufferVSprintf(&buf, " <sound model='%s'/>\n", model);
sound = (model_end ? ++model_end : NULL); sound = (model_end ? ++model_end : NULL);
free(model); VIR_FREE(model);
} }
if (virBufferError(&buf)) if (virBufferError(&buf))
@ -952,7 +956,8 @@ char *sound_string_to_xml(const char *sound) {
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
error: error:
free(virBufferContentAndReset(&buf)); tmp = virBufferContentAndReset(&buf);
VIR_FREE(tmp);
return NULL; return NULL;
} }
@ -1092,8 +1097,7 @@ xenDaemonListDomainsOld(virConnectPtr xend)
count++; count++;
} }
ptr = malloc((count + 1) * sizeof(char *) + extra); if (VIR_ALLOC_N(ptr, count + 1 + extra) < 0)
if (ptr == NULL)
goto error; goto error;
ret = (char **) ptr; ret = (char **) ptr;
@ -1149,7 +1153,7 @@ xenDaemonDomainCreateLinux(virConnectPtr xend, const char *sexpr)
ret = xend_op(xend, "", "op", "create", "config", ptr, NULL); ret = xend_op(xend, "", "op", "create", "config", ptr, NULL);
serrno = errno; serrno = errno;
free(ptr); VIR_FREE(ptr);
errno = serrno; errno = serrno;
return ret; return ret;
@ -1250,10 +1254,8 @@ xenDaemonDomainLookupByID(virConnectPtr xend,
error: error:
sexpr_free(root); sexpr_free(root);
if (domname && *domname) { if (domname)
free(*domname); VIR_FREE(*domname);
*domname = NULL;
}
return (-1); return (-1);
} }
@ -1694,11 +1696,11 @@ no_memory:
error: error:
free(path); VIR_FREE(path);
free(bindHost); VIR_FREE(bindHost);
free(bindPort); VIR_FREE(bindPort);
free(connectHost); VIR_FREE(connectHost);
free(connectPort); VIR_FREE(connectPort);
return ret; return ret;
} }
@ -1723,7 +1725,7 @@ xend_parse_sexp_desc(virConnectPtr conn, struct sexpr *root,
{ {
struct sexpr *cur, *node; struct sexpr *cur, *node;
const char *tmp; const char *tmp;
char *tty; char *tty, *val;
virBuffer buf = VIR_BUFFER_INITIALIZER; virBuffer buf = VIR_BUFFER_INITIALIZER;
int hvm = 0, bootloader = 0, vfb = 0; int hvm = 0, bootloader = 0, vfb = 0;
int domid = -1; int domid = -1;
@ -1906,8 +1908,7 @@ xend_parse_sexp_desc(virConnectPtr conn, struct sexpr *root,
goto bad_parse; goto bad_parse;
} }
drvName = malloc((offset-src)+1); if (VIR_ALLOC_N(drvName, (offset-src)+1) < 0) {
if (!drvName) {
virXendError(conn, VIR_ERR_NO_MEMORY, virXendError(conn, VIR_ERR_NO_MEMORY,
_("allocate new buffer")); _("allocate new buffer"));
goto bad_parse; goto bad_parse;
@ -1925,8 +1926,7 @@ xend_parse_sexp_desc(virConnectPtr conn, struct sexpr *root,
goto bad_parse; goto bad_parse;
} }
drvType = malloc((offset-src)+1); if (VIR_ALLOC_N(drvType, (offset-src)+1)< 0) {
if (!drvType) {
virXendError(conn, VIR_ERR_NO_MEMORY, virXendError(conn, VIR_ERR_NO_MEMORY,
_("allocate new buffer")); _("allocate new buffer"));
goto bad_parse; goto bad_parse;
@ -2004,8 +2004,8 @@ xend_parse_sexp_desc(virConnectPtr conn, struct sexpr *root,
virBufferAddLit(&buf, " </disk>\n"); virBufferAddLit(&buf, " </disk>\n");
bad_parse: bad_parse:
free(drvName); VIR_FREE(drvName);
free(drvType); VIR_FREE(drvType);
} else if (sexpr_lookup(node, "device/vif")) { } else if (sexpr_lookup(node, "device/vif")) {
const char *tmp2, *model; const char *tmp2, *model;
tmp2 = sexpr_node(node, "device/vif/script"); tmp2 = sexpr_node(node, "device/vif/script");
@ -2191,7 +2191,7 @@ xend_parse_sexp_desc(virConnectPtr conn, struct sexpr *root,
virBufferAddLit(&buf, " <target port='0'/>\n"); virBufferAddLit(&buf, " <target port='0'/>\n");
virBufferAddLit(&buf, " </console>\n"); virBufferAddLit(&buf, " </console>\n");
} }
free(tty); VIR_FREE(tty);
if (hvm) { if (hvm) {
if (sexpr_node(root, "domain/image/hvm/soundhw")) { if (sexpr_node(root, "domain/image/hvm/soundhw")) {
@ -2200,7 +2200,7 @@ xend_parse_sexp_desc(virConnectPtr conn, struct sexpr *root,
if (tmp && *tmp) { if (tmp && *tmp) {
if ((soundxml = sound_string_to_xml(tmp))) { if ((soundxml = sound_string_to_xml(tmp))) {
virBufferVSprintf(&buf, "%s", soundxml); virBufferVSprintf(&buf, "%s", soundxml);
free(soundxml); VIR_FREE(soundxml);
} else { } else {
virXendError(conn, VIR_ERR_INTERNAL_ERROR, virXendError(conn, VIR_ERR_INTERNAL_ERROR,
_("parsing soundhw string failed.")); _("parsing soundhw string failed."));
@ -2221,7 +2221,8 @@ xend_parse_sexp_desc(virConnectPtr conn, struct sexpr *root,
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
error: error:
free(virBufferContentAndReset(&buf)); val = virBufferContentAndReset(&buf);
VIR_FREE(val);
return (NULL); return (NULL);
} }
@ -2379,11 +2380,9 @@ sexpr_to_xend_topology(virConnectPtr conn,
numCpus = sexpr_int(root, "node/nr_cpus"); numCpus = sexpr_int(root, "node/nr_cpus");
cpuset = malloc(numCpus * sizeof(*cpuset)); if (VIR_ALLOC_N(cpuset, numCpus) < 0)
if (cpuset == NULL)
goto memory_error; goto memory_error;
cpuNums = malloc(numCpus * sizeof(*cpuNums)); if (VIR_ALLOC_N(cpuNums, numCpus) < 0)
if (cpuNums == NULL)
goto memory_error; goto memory_error;
cur = nodeToCpu; cur = nodeToCpu;
@ -2423,21 +2422,21 @@ sexpr_to_xend_topology(virConnectPtr conn,
cpuNums) < 0) cpuNums) < 0)
goto memory_error; goto memory_error;
} }
free(cpuNums); VIR_FREE(cpuNums);
free(cpuset); VIR_FREE(cpuset);
return (0); return (0);
parse_error: parse_error:
virXendError(conn, VIR_ERR_XEN_CALL, _("topology syntax error")); virXendError(conn, VIR_ERR_XEN_CALL, _("topology syntax error"));
error: error:
free(cpuNums); VIR_FREE(cpuNums);
free(cpuset); VIR_FREE(cpuset);
return (-1); return (-1);
memory_error: memory_error:
free(cpuNums); VIR_FREE(cpuNums);
free(cpuset); VIR_FREE(cpuset);
virXendError(conn, VIR_ERR_NO_MEMORY, _("allocate buffer")); virXendError(conn, VIR_ERR_NO_MEMORY, _("allocate buffer"));
return (-1); return (-1);
} }
@ -3331,11 +3330,11 @@ xenDaemonLookupByID(virConnectPtr conn, int id) {
if (ret == NULL) return NULL; if (ret == NULL) return NULL;
ret->id = id; ret->id = id;
free(name); VIR_FREE(name);
return (ret); return (ret);
error: error:
free(name); VIR_FREE(name);
return (NULL); return (NULL);
} }
@ -3543,7 +3542,7 @@ xenDaemonLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
} }
tmp++; tmp++;
} }
free(names); VIR_FREE(names);
} else { /* New approach for xen >= 3.0.4 */ } else { /* New approach for xen >= 3.0.4 */
char *domname = NULL; char *domname = NULL;
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
@ -3569,7 +3568,7 @@ xenDaemonLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
if (ret == NULL) return NULL; if (ret == NULL) return NULL;
ret->id = id; ret->id = id;
free(name); VIR_FREE(name);
return (ret); return (ret);
} }
@ -3610,14 +3609,14 @@ xenDaemonCreateLinux(virConnectPtr conn, const char *xmlDesc,
if ((sexpr == NULL) || (name == NULL)) { if ((sexpr == NULL) || (name == NULL)) {
virXendError(conn, VIR_ERR_XML_ERROR, virXendError(conn, VIR_ERR_XML_ERROR,
_("failed to parse domain description")); _("failed to parse domain description"));
free(sexpr); VIR_FREE(sexpr);
free(name); VIR_FREE(name);
return (NULL); return (NULL);
} }
ret = xenDaemonDomainCreateLinux(conn, sexpr); ret = xenDaemonDomainCreateLinux(conn, sexpr);
free(sexpr); VIR_FREE(sexpr);
if (ret != 0) { if (ret != 0) {
goto error; goto error;
} }
@ -3633,7 +3632,7 @@ xenDaemonCreateLinux(virConnectPtr conn, const char *xmlDesc,
if ((ret = xenDaemonDomainResume(dom)) < 0) if ((ret = xenDaemonDomainResume(dom)) < 0)
goto error; goto error;
free(name); VIR_FREE(name);
return (dom); return (dom);
@ -3643,7 +3642,7 @@ xenDaemonCreateLinux(virConnectPtr conn, const char *xmlDesc,
xenDaemonDomainDestroy(dom); xenDaemonDomainDestroy(dom);
virUnrefDomain(dom); virUnrefDomain(dom);
} }
free(name); VIR_FREE(name);
return (NULL); return (NULL);
} }
@ -3683,7 +3682,7 @@ xenDaemonAttachDevice(virDomainPtr domain, const char *xml)
str = virDomainGetOSType(domain); str = virDomainGetOSType(domain);
if (STREQ(str, "hvm")) if (STREQ(str, "hvm"))
hvm = 1; hvm = 1;
free(str); VIR_FREE(str);
sexpr = virParseXMLDevice(domain->conn, xml, hvm, priv->xendConfigVersion); sexpr = virParseXMLDevice(domain->conn, xml, hvm, priv->xendConfigVersion);
if (sexpr == NULL) if (sexpr == NULL)
return (-1); return (-1);
@ -3702,7 +3701,7 @@ xenDaemonAttachDevice(virDomainPtr domain, const char *xml)
ret = xend_op(domain->conn, domain->name, "op", "device_configure", ret = xend_op(domain->conn, domain->name, "op", "device_configure",
"config", conf, "dev", ref, NULL); "config", conf, "dev", ref, NULL);
} }
free(sexpr); VIR_FREE(sexpr);
return ret; return ret;
} }
@ -3810,7 +3809,7 @@ xenDaemonDomainSetAutostart(virDomainPtr domain,
// Change the autostart value in place, then define the new sexpr // Change the autostart value in place, then define the new sexpr
autonode = sexpr_lookup(root, "domain/on_xend_start"); autonode = sexpr_lookup(root, "domain/on_xend_start");
free(autonode->u.s.car->u.value); VIR_FREE(autonode->u.s.car->u.value);
autonode->u.s.car->u.value = (autostart ? strdup("start") autonode->u.s.car->u.value = (autostart ? strdup("start")
: strdup("ignore")); : strdup("ignore"));
if (!(autonode->u.s.car->u.value)) { if (!(autonode->u.s.car->u.value)) {
@ -3996,7 +3995,7 @@ xenDaemonDomainMigratePerform (virDomainPtr domain,
"port", port, "port", port,
"resource", "0", /* required, xend ignores it */ "resource", "0", /* required, xend ignores it */
NULL); NULL);
free (hostname); VIR_FREE (hostname);
DEBUG0("migration done"); DEBUG0("migration done");
@ -4028,14 +4027,14 @@ virDomainPtr xenDaemonDomainDefineXML(virConnectPtr conn, const char *xmlDesc) {
if ((sexpr == NULL) || (name == NULL)) { if ((sexpr == NULL) || (name == NULL)) {
virXendError(conn, VIR_ERR_XML_ERROR, virXendError(conn, VIR_ERR_XML_ERROR,
_("failed to parse domain description")); _("failed to parse domain description"));
free(sexpr); VIR_FREE(sexpr);
free(name); VIR_FREE(name);
return (NULL); return (NULL);
} }
ret = xend_op(conn, "", "op", "new", "config", sexpr, NULL); ret = xend_op(conn, "", "op", "new", "config", sexpr, NULL);
free(sexpr); VIR_FREE(sexpr);
if (ret != 0) { if (ret != 0) {
fprintf(stderr, _("Failed to create inactive domain %s\n"), name); fprintf(stderr, _("Failed to create inactive domain %s\n"), name);
goto error; goto error;
@ -4048,7 +4047,7 @@ virDomainPtr xenDaemonDomainDefineXML(virConnectPtr conn, const char *xmlDesc) {
return (dom); return (dom);
error: error:
free(name); VIR_FREE(name);
return (NULL); return (NULL);
} }
int xenDaemonDomainCreate(virDomainPtr domain) int xenDaemonDomainCreate(virDomainPtr domain)
@ -4318,7 +4317,7 @@ xenDaemonGetSchedulerParameters(virDomainPtr domain,
error: error:
sexpr_free(root); sexpr_free(root);
free(sched_type); VIR_FREE(sched_type);
return (ret); return (ret);
} }
@ -4430,7 +4429,7 @@ xenDaemonSetSchedulerParameters(virDomainPtr domain,
error: error:
sexpr_free(root); sexpr_free(root);
free(sched_type); VIR_FREE(sched_type);
return (ret); return (ret);
} }

View File

@ -54,6 +54,7 @@
#include "buf.h" #include "buf.h"
#include "uuid.h" #include "uuid.h"
#include "util.h" #include "util.h"
#include "memory.h"
static int xenXMConfigSetString(virConfPtr conf, const char *setting, static int xenXMConfigSetString(virConfPtr conf, const char *setting,
const char *str); const char *str);
@ -241,16 +242,14 @@ static int xenXMConfigEnsureIdentity(virConfPtr conf, const char *filename) {
/* Had better have a name...*/ /* Had better have a name...*/
if (xenXMConfigGetString(conf, "name", &name) < 0) { if (xenXMConfigGetString(conf, "name", &name) < 0) {
virConfValuePtr value; virConfValuePtr value;
value = malloc(sizeof(*value)); if (VIR_ALLOC(value) < 0)
if (!value) {
return (-1); return (-1);
}
/* Set name based on filename */ /* Set name based on filename */
value->type = VIR_CONF_STRING; value->type = VIR_CONF_STRING;
value->str = strdup(filename); value->str = strdup(filename);
if (!value->str) { if (!value->str) {
free(value); VIR_FREE(value);
return (-1); return (-1);
} }
if (virConfSetValue(conf, "name", value) < 0) if (virConfSetValue(conf, "name", value) < 0)
@ -262,10 +261,8 @@ static int xenXMConfigEnsureIdentity(virConfPtr conf, const char *filename) {
virConfValuePtr value; virConfValuePtr value;
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
value = malloc(sizeof(*value)); if (VIR_ALLOC(value) < 0)
if (!value) {
return (-1); return (-1);
}
/* ... then generate one */ /* ... then generate one */
virUUIDGenerate(uuid); virUUIDGenerate(uuid);
@ -274,7 +271,7 @@ static int xenXMConfigEnsureIdentity(virConfPtr conf, const char *filename) {
value->type = VIR_CONF_STRING; value->type = VIR_CONF_STRING;
value->str = strdup(uuidstr); value->str = strdup(uuidstr);
if (!value->str) { if (!value->str) {
free(value); VIR_FREE(value);
return (-1); return (-1);
} }
@ -289,7 +286,7 @@ static int xenXMConfigEnsureIdentity(virConfPtr conf, const char *filename) {
static void xenXMConfigFree(void *payload, const char *key ATTRIBUTE_UNUSED) { static void xenXMConfigFree(void *payload, const char *key ATTRIBUTE_UNUSED) {
xenXMConfCachePtr entry = (xenXMConfCachePtr)payload; xenXMConfCachePtr entry = (xenXMConfCachePtr)payload;
virConfFree(entry->conf); virConfFree(entry->conf);
free(entry); VIR_FREE(entry);
} }
@ -411,7 +408,7 @@ static int xenXMConfigCacheRefresh (virConnectPtr conn) {
entry->conf = NULL; entry->conf = NULL;
} else { /* Completely new entry */ } else { /* Completely new entry */
newborn = 1; newborn = 1;
if (!(entry = malloc(sizeof(*entry)))) { if (VIR_ALLOC(entry) < 0) {
xenXMError (conn, VIR_ERR_NO_MEMORY, strerror (errno)); xenXMError (conn, VIR_ERR_NO_MEMORY, strerror (errno));
goto cleanup; goto cleanup;
} }
@ -424,7 +421,7 @@ static int xenXMConfigCacheRefresh (virConnectPtr conn) {
if (!newborn) { if (!newborn) {
virHashRemoveEntry(configCache, path, NULL); virHashRemoveEntry(configCache, path, NULL);
} }
free(entry); VIR_FREE(entry);
continue; continue;
} }
@ -433,7 +430,7 @@ static int xenXMConfigCacheRefresh (virConnectPtr conn) {
if (!newborn) { if (!newborn) {
virHashRemoveEntry(configCache, path, NULL); virHashRemoveEntry(configCache, path, NULL);
} }
free(entry); VIR_FREE(entry);
xenXMError (conn, VIR_ERR_INTERNAL_ERROR, xenXMError (conn, VIR_ERR_INTERNAL_ERROR,
_("xenXMConfigCacheRefresh: name")); _("xenXMConfigCacheRefresh: name"));
goto cleanup; goto cleanup;
@ -444,7 +441,7 @@ static int xenXMConfigCacheRefresh (virConnectPtr conn) {
if (newborn) { if (newborn) {
if (virHashAddEntry(configCache, entry->filename, entry) < 0) { if (virHashAddEntry(configCache, entry->filename, entry) < 0) {
virConfFree(entry->conf); virConfFree(entry->conf);
free(entry); VIR_FREE(entry);
xenXMError (conn, VIR_ERR_INTERNAL_ERROR, xenXMError (conn, VIR_ERR_INTERNAL_ERROR,
_("xenXMConfigCacheRefresh: virHashAddEntry")); _("xenXMConfigCacheRefresh: virHashAddEntry"));
goto cleanup; goto cleanup;
@ -458,7 +455,7 @@ static int xenXMConfigCacheRefresh (virConnectPtr conn) {
if (virHashAddEntry(nameConfigMap, domname, entry->filename) < 0) { if (virHashAddEntry(nameConfigMap, domname, entry->filename) < 0) {
virHashRemoveEntry(configCache, ent->d_name, NULL); virHashRemoveEntry(configCache, ent->d_name, NULL);
virConfFree(entry->conf); virConfFree(entry->conf);
free(entry); VIR_FREE(entry);
} }
} }
} }
@ -674,7 +671,7 @@ char *xenXMDomainFormatXML(virConnectPtr conn, virConfPtr conf) {
ranges = virConvertCpuSet(conn, str, 0); ranges = virConvertCpuSet(conn, str, 0);
if (ranges != NULL) { if (ranges != NULL) {
virBufferVSprintf(&buf, " cpuset='%s'", ranges); virBufferVSprintf(&buf, " cpuset='%s'", ranges);
free(ranges); VIR_FREE(ranges);
} else } else
virBufferVSprintf(&buf, " cpuset='%s'", str); virBufferVSprintf(&buf, " cpuset='%s'", str);
} }
@ -1064,7 +1061,7 @@ char *xenXMDomainFormatXML(virConnectPtr conn, virConfPtr conf) {
char *soundxml; char *soundxml;
if ((soundxml = sound_string_to_xml(str))) { if ((soundxml = sound_string_to_xml(str))) {
virBufferVSprintf(&buf, "%s", soundxml); virBufferVSprintf(&buf, "%s", soundxml);
free(soundxml); VIR_FREE(soundxml);
} else { } else {
xenXMError(conn, VIR_ERR_INTERNAL_ERROR, xenXMError(conn, VIR_ERR_INTERNAL_ERROR,
_("parsing soundhw string failed.")); _("parsing soundhw string failed."));
@ -1085,7 +1082,8 @@ char *xenXMDomainFormatXML(virConnectPtr conn, virConfPtr conf) {
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
error: error:
free(virBufferContentAndReset(&buf)); str = virBufferContentAndReset(&buf);
VIR_FREE(str);
return NULL; return NULL;
} }
@ -1140,7 +1138,7 @@ int xenXMDomainSetMemory(virDomainPtr domain, unsigned long memory) {
if (!(entry = virHashLookup(configCache, filename))) if (!(entry = virHashLookup(configCache, filename)))
return (-1); return (-1);
if (!(value = malloc(sizeof(*value)))) if (VIR_ALLOC(value) < 0)
return (-1); return (-1);
value->type = VIR_CONF_LONG; value->type = VIR_CONF_LONG;
@ -1182,7 +1180,7 @@ int xenXMDomainSetMaxMemory(virDomainPtr domain, unsigned long memory) {
if (!(entry = virHashLookup(configCache, filename))) if (!(entry = virHashLookup(configCache, filename)))
return (-1); return (-1);
if (!(value = malloc(sizeof(*value)))) if (VIR_ALLOC(value) < 0)
return (-1); return (-1);
value->type = VIR_CONF_LONG; value->type = VIR_CONF_LONG;
@ -1255,7 +1253,7 @@ int xenXMDomainSetVcpus(virDomainPtr domain, unsigned int vcpus) {
if (!(entry = virHashLookup(configCache, filename))) if (!(entry = virHashLookup(configCache, filename)))
return (-1); return (-1);
if (!(value = malloc(sizeof(*value)))) if (VIR_ALLOC(value) < 0)
return (-1); return (-1);
value->type = VIR_CONF_LONG; value->type = VIR_CONF_LONG;
@ -1359,8 +1357,8 @@ int xenXMDomainPinVcpu(virDomainPtr domain,
ret = 0; ret = 0;
cleanup: cleanup:
free(mapstr); VIR_FREE(mapstr);
free(ranges); VIR_FREE(ranges);
return (ret); return (ret);
} }
@ -1494,13 +1492,13 @@ int xenXMDomainCreate(virDomainPtr domain) {
priv = (xenUnifiedPrivatePtr) domain->conn->privateData; priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
if (!(sexpr = virDomainParseXMLDesc(domain->conn, xml, NULL, priv->xendConfigVersion))) { if (!(sexpr = virDomainParseXMLDesc(domain->conn, xml, NULL, priv->xendConfigVersion))) {
free(xml); VIR_FREE(xml);
return (-1); return (-1);
} }
free(xml); VIR_FREE(xml);
ret = xenDaemonDomainCreateLinux(domain->conn, sexpr); ret = xenDaemonDomainCreateLinux(domain->conn, sexpr);
free(sexpr); VIR_FREE(sexpr);
if (ret != 0) { if (ret != 0) {
return (-1); return (-1);
} }
@ -1531,7 +1529,7 @@ static
int xenXMConfigSetInt(virConfPtr conf, const char *setting, long l) { int xenXMConfigSetInt(virConfPtr conf, const char *setting, long l) {
virConfValuePtr value = NULL; virConfValuePtr value = NULL;
if (!(value = malloc(sizeof(*value)))) if (VIR_ALLOC(value) < 0)
return -1; return -1;
value->type = VIR_CONF_LONG; value->type = VIR_CONF_LONG;
@ -1546,13 +1544,13 @@ static
int xenXMConfigSetString(virConfPtr conf, const char *setting, const char *str) { int xenXMConfigSetString(virConfPtr conf, const char *setting, const char *str) {
virConfValuePtr value = NULL; virConfValuePtr value = NULL;
if (!(value = malloc(sizeof(*value)))) if (VIR_ALLOC(value) < 0)
return -1; return -1;
value->type = VIR_CONF_STRING; value->type = VIR_CONF_STRING;
value->next = NULL; value->next = NULL;
if (!(value->str = strdup(str))) { if (!(value->str = strdup(str))) {
free(value); VIR_FREE(value);
return -1; return -1;
} }
@ -1755,7 +1753,7 @@ static int xenXMParseXMLDisk(xmlNodePtr node, int hvm, int xendConfigVersion, ch
buflen += 2; /* mode */ buflen += 2; /* mode */
if (!(buf = malloc(buflen))) if (VIR_ALLOC_N(buf, buflen) < 0)
goto cleanup; goto cleanup;
if(source) { if(source) {
@ -1884,7 +1882,7 @@ static char *xenXMParseXMLVif(virConnectPtr conn, xmlNodePtr node, int hvm) {
if (ip) if (ip)
buflen += 4 + strlen((const char*)ip); buflen += 4 + strlen((const char*)ip);
if (!(buf = malloc(buflen))) if (VIR_ALLOC_N(buf, buflen) < 0)
goto cleanup; goto cleanup;
strcpy(buf, "mac="); strcpy(buf, "mac=");
@ -1918,7 +1916,7 @@ static char *xenXMParseXMLVif(virConnectPtr conn, xmlNodePtr node, int hvm) {
} }
cleanup: cleanup:
free(bridge); VIR_FREE(bridge);
xmlFree(mac); xmlFree(mac);
xmlFree(source); xmlFree(source);
xmlFree(script); xmlFree(script);
@ -2007,18 +2005,18 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char *xml) {
ranges = virConvertCpuSet(conn, cpus, 0); ranges = virConvertCpuSet(conn, cpus, 0);
if (ranges != NULL) { if (ranges != NULL) {
free(cpus); VIR_FREE(cpus);
if (xenXMConfigSetString(conf, "cpus", ranges) < 0) { if (xenXMConfigSetString(conf, "cpus", ranges) < 0) {
free(ranges); VIR_FREE(ranges);
goto error; goto error;
} }
free(ranges); VIR_FREE(ranges);
} else { } else {
if (xenXMConfigSetString(conf, "cpus", cpus) < 0) { if (xenXMConfigSetString(conf, "cpus", cpus) < 0) {
free(cpus); VIR_FREE(cpus);
goto error; goto error;
} }
free(cpus); VIR_FREE(cpus);
} }
} }
@ -2027,6 +2025,7 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char *xml) {
(obj->stringval != NULL) && STREQ((char*)obj->stringval, "hvm")) (obj->stringval != NULL) && STREQ((char*)obj->stringval, "hvm"))
hvm = 1; hvm = 1;
xmlXPathFreeObject(obj); xmlXPathFreeObject(obj);
obj = NULL;
priv = (xenUnifiedPrivatePtr) conn->privateData; priv = (xenUnifiedPrivatePtr) conn->privateData;
@ -2051,6 +2050,7 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char *xml) {
boot = "d"; boot = "d";
} }
xmlXPathFreeObject(obj); xmlXPathFreeObject(obj);
obj = NULL;
if (xenXMConfigSetString(conf, "boot", boot) < 0) if (xenXMConfigSetString(conf, "boot", boot) < 0)
goto error; goto error;
@ -2073,6 +2073,7 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char *xml) {
clockLocal = 1; clockLocal = 1;
} }
xmlXPathFreeObject(obj); xmlXPathFreeObject(obj);
obj = NULL;
if (xenXMConfigSetInt(conf, "localtime", clockLocal) < 0) if (xenXMConfigSetInt(conf, "localtime", clockLocal) < 0)
goto error; goto error;
@ -2160,7 +2161,7 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char *xml) {
obj = xmlXPathEval(BAD_CAST "/domain/devices/graphics", ctxt); obj = xmlXPathEval(BAD_CAST "/domain/devices/graphics", ctxt);
if ((obj != NULL) && (obj->type == XPATH_NODESET) && if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) { (obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) {
if (!(vfb = malloc(sizeof(*vfb)))) { if (VIR_ALLOC(vfb) < 0) {
xenXMError(conn, VIR_ERR_NO_MEMORY, _("config")); xenXMError(conn, VIR_ERR_NO_MEMORY, _("config"));
goto error; goto error;
} }
@ -2192,7 +2193,16 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char *xml) {
len += 11 + strlen((const char*)vncpasswd); len += 11 + strlen((const char*)vncpasswd);
if (keymap) if (keymap)
len += 8 + strlen((const char*)keymap); len += 8 + strlen((const char*)keymap);
if ((val = malloc(len)) != NULL) { if (VIR_ALLOC_N(val, len) < 0) {
xmlFree(type);
xmlFree(vncport);
xmlFree(vnclisten);
xmlFree(vncpasswd);
xmlFree(keymap);
VIR_FREE(vfb);
xenXMError (conn, VIR_ERR_NO_MEMORY, strerror (errno));
goto error;
}
strcpy(val, "type=vnc"); strcpy(val, "type=vnc");
if (vncunused) { if (vncunused) {
strcat(val, ",vncunused=1"); strcat(val, ",vncunused=1");
@ -2220,12 +2230,12 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char *xml) {
xmlFree(keymap); xmlFree(keymap);
} }
} }
}
xmlFree(type); xmlFree(type);
if (val) { if (val) {
virConfValuePtr disp; virConfValuePtr disp;
if (!(disp = malloc(sizeof(*disp)))) { if (VIR_ALLOC(disp) < 0) {
free(val); VIR_FREE(val);
VIR_FREE(vfb);
xenXMError(conn, VIR_ERR_NO_MEMORY, _("config")); xenXMError(conn, VIR_ERR_NO_MEMORY, _("config"));
goto error; goto error;
} }
@ -2246,7 +2256,7 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char *xml) {
if ((obj != NULL) && (obj->type == XPATH_NODESET) && if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) { (obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) {
virConfValuePtr disks; virConfValuePtr disks;
if (!(disks = malloc(sizeof(*disks)))) { if (VIR_ALLOC(disks) < 0) {
xenXMError(conn, VIR_ERR_NO_MEMORY, _("config")); xenXMError(conn, VIR_ERR_NO_MEMORY, _("config"));
goto error; goto error;
} }
@ -2255,11 +2265,14 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char *xml) {
for (i = obj->nodesetval->nodeNr -1 ; i >= 0 ; i--) { for (i = obj->nodesetval->nodeNr -1 ; i >= 0 ; i--) {
virConfValuePtr thisDisk; virConfValuePtr thisDisk;
char *disk = NULL; char *disk = NULL;
if (xenXMParseXMLDisk(obj->nodesetval->nodeTab[i], hvm, priv->xendConfigVersion, &disk) < 0) if (xenXMParseXMLDisk(obj->nodesetval->nodeTab[i], hvm, priv->xendConfigVersion, &disk) < 0) {
virConfFreeValue(disks);
goto error; goto error;
}
if (disk) { if (disk) {
if (!(thisDisk = malloc(sizeof(*thisDisk)))) { if (VIR_ALLOC(thisDisk) < 0) {
free(disk); VIR_FREE(disk);
virConfFreeValue(disks);
xenXMError(conn, VIR_ERR_NO_MEMORY, _("config")); xenXMError(conn, VIR_ERR_NO_MEMORY, _("config"));
goto error; goto error;
} }
@ -2278,7 +2291,7 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char *xml) {
if ((obj != NULL) && (obj->type == XPATH_NODESET) && if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) { (obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) {
virConfValuePtr vifs; virConfValuePtr vifs;
if (!(vifs = malloc(sizeof(*vifs)))) { if (VIR_ALLOC(vifs) < 0) {
xenXMError(conn, VIR_ERR_NO_MEMORY, _("config")); xenXMError(conn, VIR_ERR_NO_MEMORY, _("config"));
goto error; goto error;
} }
@ -2287,10 +2300,13 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char *xml) {
for (i = obj->nodesetval->nodeNr - 1; i >= 0; i--) { for (i = obj->nodesetval->nodeNr - 1; i >= 0; i--) {
virConfValuePtr thisVif; virConfValuePtr thisVif;
char *vif = xenXMParseXMLVif(conn, obj->nodesetval->nodeTab[i], hvm); char *vif = xenXMParseXMLVif(conn, obj->nodesetval->nodeTab[i], hvm);
if (!vif) if (!vif) {
virConfFreeValue(vifs);
goto error; goto error;
if (!(thisVif = malloc(sizeof(*thisVif)))) { }
free(vif); if (VIR_ALLOC(thisVif) < 0) {
VIR_FREE(vif);
virConfFreeValue(vifs);
xenXMError(conn, VIR_ERR_NO_MEMORY, _("config")); xenXMError(conn, VIR_ERR_NO_MEMORY, _("config"));
goto error; goto error;
} }
@ -2344,10 +2360,10 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char *xml) {
if (!(soundstr = virBuildSoundStringFromXML(conn, ctxt))) if (!(soundstr = virBuildSoundStringFromXML(conn, ctxt)))
goto error; goto error;
if (xenXMConfigSetString(conf, "soundhw", soundstr) < 0) { if (xenXMConfigSetString(conf, "soundhw", soundstr) < 0) {
free(soundstr); VIR_FREE(soundstr);
goto error; goto error;
} }
free(soundstr); VIR_FREE(soundstr);
} }
} }
@ -2463,7 +2479,7 @@ virDomainPtr xenXMDomainDefineXML(virConnectPtr conn, const char *xml) {
goto error; goto error;
} }
if (!(entry = calloc(1, sizeof(*entry)))) { if (VIR_ALLOC(entry) < 0) {
xenXMError(conn, VIR_ERR_NO_MEMORY, _("config")); xenXMError(conn, VIR_ERR_NO_MEMORY, _("config"));
goto error; goto error;
} }
@ -2505,7 +2521,7 @@ virDomainPtr xenXMDomainDefineXML(virConnectPtr conn, const char *xml) {
return (ret); return (ret);
error: error:
free(entry); VIR_FREE(entry);
if (conf) if (conf)
virConfFree(conf); virConfFree(conf);
return (NULL); return (NULL);
@ -2712,7 +2728,7 @@ xenXMDomainAttachDevice(virDomainPtr domain, const char *xml) {
ret = 0; ret = 0;
cleanup: cleanup:
free(domxml); VIR_FREE(domxml);
xmlXPathFreeObject(obj); xmlXPathFreeObject(obj);
xmlXPathFreeContext(ctxt); xmlXPathFreeContext(ctxt);
if (doc) if (doc)
@ -2803,11 +2819,11 @@ xenXMAttachDisk(virDomainPtr domain, xmlXPathContextPtr ctxt, int hvm,
list_val = list_val->next; list_val = list_val->next;
} }
} else if (!list_item) { } else if (!list_item) {
if (!(list_item = calloc(1, sizeof(virConfValue)))) if (VIR_ALLOC(list_item) < 0)
goto cleanup; goto cleanup;
list_item->type = VIR_CONF_LIST; list_item->type = VIR_CONF_LIST;
if(virConfSetValue(entry->conf, "disk", list_item)) { if(virConfSetValue(entry->conf, "disk", list_item)) {
free(list_item); VIR_FREE(list_item);
goto cleanup; goto cleanup;
} }
list_val = NULL; list_val = NULL;
@ -2817,7 +2833,7 @@ xenXMAttachDisk(virDomainPtr domain, xmlXPathContextPtr ctxt, int hvm,
if (!list_val) { if (!list_val) {
/* insert */ /* insert */
if (!(list_val = malloc(sizeof(virConfValue)))) if (VIR_ALLOC(list_val) < 0)
goto cleanup; goto cleanup;
list_val->type = VIR_CONF_STRING; list_val->type = VIR_CONF_STRING;
list_val->next = NULL; list_val->next = NULL;
@ -2828,7 +2844,7 @@ xenXMAttachDisk(virDomainPtr domain, xmlXPathContextPtr ctxt, int hvm,
prev->next = list_val; prev->next = list_val;
} else { } else {
/* configure */ /* configure */
free(list_val->str); VIR_FREE(list_val->str);
list_val->str = dev; list_val->str = dev;
} }
@ -2836,9 +2852,9 @@ xenXMAttachDisk(virDomainPtr domain, xmlXPathContextPtr ctxt, int hvm,
goto cleanup; goto cleanup;
cleanup: cleanup:
free(type); VIR_FREE(type);
free(source); VIR_FREE(source);
free(target); VIR_FREE(target);
return (ret); return (ret);
} }
@ -2912,7 +2928,7 @@ xenXMAttachInterface(virDomainPtr domain, xmlXPathContextPtr ctxt, int hvm,
if (virMacAddrCompare (dommac, (const char *) mac) == 0) { if (virMacAddrCompare (dommac, (const char *) mac) == 0) {
if (autoassign) { if (autoassign) {
free(mac); VIR_FREE(mac);
mac = NULL; mac = NULL;
if (!(mac = (xmlChar *)xenXMAutoAssignMac())) if (!(mac = (xmlChar *)xenXMAutoAssignMac()))
goto cleanup; goto cleanup;
@ -2929,11 +2945,11 @@ xenXMAttachInterface(virDomainPtr domain, xmlXPathContextPtr ctxt, int hvm,
list_val = list_val->next; list_val = list_val->next;
} }
} else if (!list_item) { } else if (!list_item) {
if (!(list_item = calloc(1, sizeof(virConfValue)))) if (VIR_ALLOC(list_item) < 0)
goto cleanup; goto cleanup;
list_item->type = VIR_CONF_LIST; list_item->type = VIR_CONF_LIST;
if(virConfSetValue(entry->conf, "vif", list_item)) { if(virConfSetValue(entry->conf, "vif", list_item)) {
free(list_item); VIR_FREE(list_item);
goto cleanup; goto cleanup;
} }
list_val = NULL; list_val = NULL;
@ -2948,28 +2964,28 @@ xenXMAttachInterface(virDomainPtr domain, xmlXPathContextPtr ctxt, int hvm,
while (node_cur->next) while (node_cur->next)
node_cur = node_cur->next; node_cur = node_cur->next;
if (!(node_tmp = calloc(1, sizeof(xmlNode)))) if (VIR_ALLOC(node_tmp) < 0)
goto node_cleanup; goto node_cleanup;
node_tmp->type = XML_ELEMENT_NODE; node_tmp->type = XML_ELEMENT_NODE;
if (!(node_tmp->name = malloc(4))) if (VIR_ALLOC_N(node_tmp->name, 4) < 0)
goto node_cleanup; goto node_cleanup;
strcpy((char *)node_tmp->name, "mac"); strcpy((char *)node_tmp->name, "mac");
node_tmp->children = NULL; node_tmp->children = NULL;
if (!(attr_node = calloc(1, sizeof(xmlAttr)))) if (VIR_ALLOC(attr_node) < 0)
goto node_cleanup; goto node_cleanup;
attr_node->type = XML_ATTRIBUTE_NODE; attr_node->type = XML_ATTRIBUTE_NODE;
attr_node->ns = NULL; attr_node->ns = NULL;
if (!(attr_node->name = malloc(8))) if (VIR_ALLOC_N(attr_node->name, 8) < 0)
goto node_cleanup; goto node_cleanup;
strcpy((char *) attr_node->name, "address"); strcpy((char *) attr_node->name, "address");
node_tmp->properties = attr_node; node_tmp->properties = attr_node;
if (!(text_node = calloc(1, sizeof(xmlNode)))) if (VIR_ALLOC(text_node) < 0)
goto node_cleanup; goto node_cleanup;
text_node->type = XML_TEXT_NODE; text_node->type = XML_TEXT_NODE;
text_node->_private = NULL; text_node->_private = NULL;
if (!(text_node->name = malloc(8))) if (VIR_ALLOC_N(text_node->name, 5) < 0)
goto node_cleanup; goto node_cleanup;
strcpy((char *) text_node->name, "text"); strcpy((char *) text_node->name, "text");
text_node->children = NULL; text_node->children = NULL;
@ -2989,7 +3005,7 @@ xenXMAttachInterface(virDomainPtr domain, xmlXPathContextPtr ctxt, int hvm,
if (!list_val) { if (!list_val) {
/* insert */ /* insert */
if (!(list_val = malloc(sizeof(virConfValue)))) if (VIR_ALLOC(list_val) < 0)
goto cleanup; goto cleanup;
list_val->type = VIR_CONF_STRING; list_val->type = VIR_CONF_STRING;
list_val->next = NULL; list_val->next = NULL;
@ -3000,7 +3016,7 @@ xenXMAttachInterface(virDomainPtr domain, xmlXPathContextPtr ctxt, int hvm,
prev->next = list_val; prev->next = list_val;
} else { } else {
/* configure */ /* configure */
free(list_val->str); VIR_FREE(list_val->str);
list_val->str = dev; list_val->str = dev;
} }
@ -3012,9 +3028,9 @@ xenXMAttachInterface(virDomainPtr domain, xmlXPathContextPtr ctxt, int hvm,
xmlFree(attr_node); xmlFree(attr_node);
xmlFree(text_node); xmlFree(text_node);
cleanup: cleanup:
free(type); VIR_FREE(type);
free(source); VIR_FREE(source);
free(mac); VIR_FREE(mac);
return (ret); return (ret);
} }
@ -3031,7 +3047,7 @@ char *
xenXMAutoAssignMac() { xenXMAutoAssignMac() {
char *buf; char *buf;
if (!(buf = malloc(18))) if (VIR_ALLOC_N(buf, 18) < 0)
return 0; return 0;
srand((unsigned)time(NULL)); srand((unsigned)time(NULL));
sprintf(buf, "00:16:3e:%02x:%02x:%02x" sprintf(buf, "00:16:3e:%02x:%02x:%02x"
@ -3198,13 +3214,13 @@ xenXMDomainDetachDevice(virDomainPtr domain, const char *xml) {
else { else {
if (!prev) { if (!prev) {
virConfValuePtr value; virConfValuePtr value;
if (!(value = calloc(1, sizeof(virConfValue)))) if (VIR_ALLOC(value) < 0)
goto cleanup; goto cleanup;
value->type = VIR_CONF_LIST; value->type = VIR_CONF_LIST;
value->list = list_val->next; value->list = list_val->next;
list_val->next = NULL; list_val->next = NULL;
if (virConfSetValue(entry->conf, device, value)) { if (virConfSetValue(entry->conf, device, value)) {
free(value); VIR_FREE(value);
goto cleanup; goto cleanup;
} }
} else } else
@ -3223,9 +3239,9 @@ xenXMDomainDetachDevice(virDomainPtr domain, const char *xml) {
xmlXPathFreeContext(ctxt); xmlXPathFreeContext(ctxt);
if (doc) if (doc)
xmlFreeDoc(doc); xmlFreeDoc(doc);
free(domdevice); VIR_FREE(domdevice);
free(key); VIR_FREE(key);
free(list_val); VIR_FREE(list_val);
return (ret); return (ret);
} }

View File

@ -26,6 +26,7 @@
#include "xml.h" #include "xml.h"
#include "buf.h" #include "buf.h"
#include "util.h" #include "util.h"
#include "memory.h"
#include "xs_internal.h" /* for xenStoreDomainGetNetworkID */ #include "xs_internal.h" /* for xenStoreDomainGetNetworkID */
#include "xen_unified.h" #include "xen_unified.h"
#include "xend_internal.h" /* for is_sound_* functions */ #include "xend_internal.h" /* for is_sound_* functions */
@ -274,19 +275,18 @@ virConvertCpuSet(virConnectPtr conn, const char *str, int maxcpu) {
if (maxcpu <= 0) if (maxcpu <= 0)
maxcpu = 4096; maxcpu = 4096;
cpuset = calloc(maxcpu, sizeof(*cpuset)); if (VIR_ALLOC_N(cpuset, maxcpu) < 0) {
if (cpuset == NULL) {
virXMLError(conn, VIR_ERR_NO_MEMORY, _("allocate buffer"), 0); virXMLError(conn, VIR_ERR_NO_MEMORY, _("allocate buffer"), 0);
return(NULL); return(NULL);
} }
ret = virParseCpuSet(conn, &cur, 0, cpuset, maxcpu); ret = virParseCpuSet(conn, &cur, 0, cpuset, maxcpu);
if (ret < 0) { if (ret < 0) {
free(cpuset); VIR_FREE(cpuset);
return(NULL); return(NULL);
} }
res = virSaveCpuSet(conn, cpuset, maxcpu); res = virSaveCpuSet(conn, cpuset, maxcpu);
free(cpuset); VIR_FREE(cpuset);
return (res); return (res);
} }
@ -309,7 +309,7 @@ char * virBuildSoundStringFromXML(virConnectPtr conn,
char *sound; char *sound;
xmlNodePtr *nodes = NULL; xmlNodePtr *nodes = NULL;
if (!(sound = calloc(1, size+1))) { if (VIR_ALLOC_N(sound, size + 1) < 0) {
virXMLError(conn, VIR_ERR_NO_MEMORY, virXMLError(conn, VIR_ERR_NO_MEMORY,
_("failed to allocate sound string"), 0); _("failed to allocate sound string"), 0);
return NULL; return NULL;
@ -332,7 +332,7 @@ char * virBuildSoundStringFromXML(virConnectPtr conn,
if (!is_sound_model_valid(model)) { if (!is_sound_model_valid(model)) {
virXMLError(conn, VIR_ERR_XML_ERROR, virXMLError(conn, VIR_ERR_XML_ERROR,
_("unknown sound model type"), 0); _("unknown sound model type"), 0);
free(model); VIR_FREE(model);
goto error; goto error;
} }
@ -345,21 +345,21 @@ char * virBuildSoundStringFromXML(virConnectPtr conn,
if (*sound && (size >= (strlen(model) + 1))) { if (*sound && (size >= (strlen(model) + 1))) {
strncat(sound, ",", size--); strncat(sound, ",", size--);
} else if (*sound || size < strlen(model)) { } else if (*sound || size < strlen(model)) {
free(model); VIR_FREE(model);
continue; continue;
} }
strncat(sound, model, size); strncat(sound, model, size);
size -= strlen(model); size -= strlen(model);
} }
free(model); VIR_FREE(model);
} }
} }
free(nodes); VIR_FREE(nodes);
return sound; return sound;
error: error:
free(nodes); VIR_FREE(nodes);
return NULL; return NULL;
} }
#endif /* !PROXY */ #endif /* !PROXY */
@ -590,11 +590,11 @@ virXPathNodeSet(const char *xpath, xmlXPathContextPtr ctxt,
ret = obj->nodesetval->nodeNr; ret = obj->nodesetval->nodeNr;
if (list != NULL) { if (list != NULL) {
*list = malloc(ret * sizeof(**list)); if (VIR_ALLOC_N(*list, ret) < 0) {
if (*list == NULL) {
virXMLError(NULL, VIR_ERR_NO_MEMORY, virXMLError(NULL, VIR_ERR_NO_MEMORY,
_("allocate string array"), _("allocate string array"),
ret * sizeof(**list)); ret * sizeof(**list));
ret = -1;
} else { } else {
memcpy(*list, obj->nodesetval->nodeTab, memcpy(*list, obj->nodesetval->nodeTab,
ret * sizeof(xmlNodePtr)); ret * sizeof(xmlNodePtr));
@ -1026,7 +1026,7 @@ virDomainParseXMLOSDescHVM(virConnectPtr conn, xmlNodePtr node,
fdfile = xmlGetProp(cur, BAD_CAST "file"); fdfile = xmlGetProp(cur, BAD_CAST "file");
if (fdfile != NULL) { if (fdfile != NULL) {
virBufferVSprintf(buf, "(fda '%s')", fdfile); virBufferVSprintf(buf, "(fda '%s')", fdfile);
free(fdfile); VIR_FREE(fdfile);
} }
} }
@ -1040,7 +1040,7 @@ virDomainParseXMLOSDescHVM(virConnectPtr conn, xmlNodePtr node,
fdfile = xmlGetProp(cur, BAD_CAST "file"); fdfile = xmlGetProp(cur, BAD_CAST "file");
if (fdfile != NULL) { if (fdfile != NULL) {
virBufferVSprintf(buf, "(fdb '%s')", fdfile); virBufferVSprintf(buf, "(fdb '%s')", fdfile);
free(fdfile); VIR_FREE(fdfile);
} }
} }
@ -1118,7 +1118,7 @@ virDomainParseXMLOSDescHVM(virConnectPtr conn, xmlNodePtr node,
} }
xmlFree(bus); xmlFree(bus);
} }
free(nodes); VIR_FREE(nodes);
nodes = NULL; nodes = NULL;
} }
@ -1157,19 +1157,19 @@ virDomainParseXMLOSDescHVM(virConnectPtr conn, xmlNodePtr node,
if (!(soundstr = virBuildSoundStringFromXML(conn, ctxt))) if (!(soundstr = virBuildSoundStringFromXML(conn, ctxt)))
goto error; goto error;
virBufferVSprintf(buf, "(soundhw '%s')", soundstr); virBufferVSprintf(buf, "(soundhw '%s')", soundstr);
free(soundstr); VIR_FREE(soundstr);
} }
str = virXPathString("string(/domain/clock/@offset)", ctxt); str = virXPathString("string(/domain/clock/@offset)", ctxt);
if (str != NULL && STREQ(str, "localtime")) { if (str != NULL && STREQ(str, "localtime")) {
virBufferAddLit(buf, "(localtime 1)"); virBufferAddLit(buf, "(localtime 1)");
} }
free(str); VIR_FREE(str);
return (0); return (0);
error: error:
free(nodes); VIR_FREE(nodes);
return (-1); return (-1);
} }
@ -1531,7 +1531,7 @@ virDomainParseXMLIfDesc(virConnectPtr conn ATTRIBUTE_UNUSED,
} }
virNetworkFree(network); virNetworkFree(network);
virBufferVSprintf(buf, "(bridge '%s')", bridge); virBufferVSprintf(buf, "(bridge '%s')", bridge);
free(bridge); VIR_FREE(bridge);
} }
} }
if (script != NULL) if (script != NULL)
@ -1578,7 +1578,7 @@ virDomainParseXMLDesc(virConnectPtr conn, const char *xmldesc, char **name,
{ {
xmlDocPtr xml = NULL; xmlDocPtr xml = NULL;
xmlNodePtr node; xmlNodePtr node;
char *nam = NULL; char *nam = NULL, *tmp;
virBuffer buf = VIR_BUFFER_INITIALIZER; virBuffer buf = VIR_BUFFER_INITIALIZER;
xmlChar *prop; xmlChar *prop;
xmlParserCtxtPtr pctxt; xmlParserCtxtPtr pctxt;
@ -1675,30 +1675,29 @@ virDomainParseXMLDesc(virConnectPtr conn, const char *xmldesc, char **name,
* it in a range format guaranteed to be understood by Xen. * it in a range format guaranteed to be understood by Xen.
*/ */
if (maxcpu > 0) { if (maxcpu > 0) {
cpuset = malloc(maxcpu * sizeof(*cpuset)); if (VIR_ALLOC_N(cpuset, maxcpu) < 0) {
if (cpuset != NULL) { virXMLError(conn, VIR_ERR_NO_MEMORY, xmldesc, 0);
goto error;
}
res = virParseCpuSet(conn, &cur, 0, cpuset, maxcpu); res = virParseCpuSet(conn, &cur, 0, cpuset, maxcpu);
if (res > 0) { if (res > 0) {
ranges = virSaveCpuSet(conn, cpuset, maxcpu); ranges = virSaveCpuSet(conn, cpuset, maxcpu);
if (ranges != NULL) { if (ranges != NULL) {
virBufferVSprintf(&buf, "(cpus '%s')", ranges); virBufferVSprintf(&buf, "(cpus '%s')", ranges);
free(ranges); VIR_FREE(ranges);
} }
} }
free(cpuset); VIR_FREE(cpuset);
if (res < 0) if (res < 0)
goto error; goto error;
} else {
virXMLError(conn, VIR_ERR_NO_MEMORY, xmldesc, 0);
} }
} VIR_FREE(str);
free(str);
} }
str = virXPathString("string(/domain/uuid[1])", ctxt); str = virXPathString("string(/domain/uuid[1])", ctxt);
if (str != NULL) { if (str != NULL) {
virBufferVSprintf(&buf, "(uuid '%s')", str); virBufferVSprintf(&buf, "(uuid '%s')", str);
free(str); VIR_FREE(str);
} }
str = virXPathString("string(/domain/bootloader[1])", ctxt); str = virXPathString("string(/domain/bootloader[1])", ctxt);
@ -1709,7 +1708,7 @@ virDomainParseXMLDesc(virConnectPtr conn, const char *xmldesc, char **name,
* significant and should be discarded * significant and should be discarded
*/ */
bootloader = 1; bootloader = 1;
free(str); VIR_FREE(str);
} else if (virXPathNumber("count(/domain/bootloader)", ctxt, &f) == 0 } else if (virXPathNumber("count(/domain/bootloader)", ctxt, &f) == 0
&& (f > 0)) { && (f > 0)) {
virBufferAddLit(&buf, "(bootloader)"); virBufferAddLit(&buf, "(bootloader)");
@ -1726,25 +1725,25 @@ virDomainParseXMLDesc(virConnectPtr conn, const char *xmldesc, char **name,
* ignore the bootloader_args value unless a bootloader was specified * ignore the bootloader_args value unless a bootloader was specified
*/ */
virBufferVSprintf(&buf, "(bootloader_args '%s')", str); virBufferVSprintf(&buf, "(bootloader_args '%s')", str);
free(str); VIR_FREE(str);
} }
str = virXPathString("string(/domain/on_poweroff[1])", ctxt); str = virXPathString("string(/domain/on_poweroff[1])", ctxt);
if (str != NULL) { if (str != NULL) {
virBufferVSprintf(&buf, "(on_poweroff '%s')", str); virBufferVSprintf(&buf, "(on_poweroff '%s')", str);
free(str); VIR_FREE(str);
} }
str = virXPathString("string(/domain/on_reboot[1])", ctxt); str = virXPathString("string(/domain/on_reboot[1])", ctxt);
if (str != NULL) { if (str != NULL) {
virBufferVSprintf(&buf, "(on_reboot '%s')", str); virBufferVSprintf(&buf, "(on_reboot '%s')", str);
free(str); VIR_FREE(str);
} }
str = virXPathString("string(/domain/on_crash[1])", ctxt); str = virXPathString("string(/domain/on_crash[1])", ctxt);
if (str != NULL) { if (str != NULL) {
virBufferVSprintf(&buf, "(on_crash '%s')", str); virBufferVSprintf(&buf, "(on_crash '%s')", str);
free(str); VIR_FREE(str);
} }
if (!bootloader) { if (!bootloader) {
@ -1810,11 +1809,11 @@ virDomainParseXMLDesc(virConnectPtr conn, const char *xmldesc, char **name,
res = virDomainParseXMLDiskDesc(conn, nodes[i], &buf, res = virDomainParseXMLDiskDesc(conn, nodes[i], &buf,
hvm, xendConfigVersion); hvm, xendConfigVersion);
if (res != 0) { if (res != 0) {
free(nodes); VIR_FREE(nodes);
goto error; goto error;
} }
} }
free(nodes); VIR_FREE(nodes);
} }
nb_nodes = virXPathNodeSet("/domain/devices/interface", ctxt, &nodes); nb_nodes = virXPathNodeSet("/domain/devices/interface", ctxt, &nodes);
@ -1825,12 +1824,12 @@ virDomainParseXMLDesc(virConnectPtr conn, const char *xmldesc, char **name,
virDomainParseXMLIfDesc(conn, nodes[i], &buf, hvm, virDomainParseXMLIfDesc(conn, nodes[i], &buf, hvm,
xendConfigVersion); xendConfigVersion);
if (res != 0) { if (res != 0) {
free(nodes); VIR_FREE(nodes);
goto error; goto error;
} }
virBufferAddLit(&buf, ")"); virBufferAddLit(&buf, ")");
} }
free(nodes); VIR_FREE(nodes);
} }
/* New style PV graphics config xen >= 3.0.4, /* New style PV graphics config xen >= 3.0.4,
@ -1842,11 +1841,11 @@ virDomainParseXMLDesc(virConnectPtr conn, const char *xmldesc, char **name,
for (i = 0; i < nb_nodes; i++) { for (i = 0; i < nb_nodes; i++) {
res = virDomainParseXMLGraphicsDescVFB(conn, nodes[i], &buf); res = virDomainParseXMLGraphicsDescVFB(conn, nodes[i], &buf);
if (res != 0) { if (res != 0) {
free(nodes); VIR_FREE(nodes);
goto error; goto error;
} }
} }
free(nodes); VIR_FREE(nodes);
} }
} }
@ -1860,7 +1859,7 @@ virDomainParseXMLDesc(virConnectPtr conn, const char *xmldesc, char **name,
if (name != NULL) if (name != NULL)
*name = nam; *name = nam;
else else
free(nam); VIR_FREE(nam);
if (virBufferError(&buf)) { if (virBufferError(&buf)) {
virXMLError(conn, VIR_ERR_NO_MEMORY, _("allocate buffer"), 0); virXMLError(conn, VIR_ERR_NO_MEMORY, _("allocate buffer"), 0);
@ -1870,7 +1869,7 @@ virDomainParseXMLDesc(virConnectPtr conn, const char *xmldesc, char **name,
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
error: error:
free(nam); VIR_FREE(nam);
if (name != NULL) if (name != NULL)
*name = NULL; *name = NULL;
xmlXPathFreeContext(ctxt); xmlXPathFreeContext(ctxt);
@ -1878,7 +1877,8 @@ virDomainParseXMLDesc(virConnectPtr conn, const char *xmldesc, char **name,
xmlFreeDoc(xml); xmlFreeDoc(xml);
if (pctxt != NULL) if (pctxt != NULL)
xmlFreeParserCtxt(pctxt); xmlFreeParserCtxt(pctxt);
free(virBufferContentAndReset(&buf)); tmp = virBufferContentAndReset(&buf);
VIR_FREE(tmp);
return (NULL); return (NULL);
} }

View File

@ -9,7 +9,7 @@
#include "testutils.h" #include "testutils.h"
static char *progname; static char *progname;
static char *abs_top_srcdir; static char *abs_srcdir;
#define MAX_FILE 4096 #define MAX_FILE 4096
static int testFilterLine(char *buffer, static int testFilterLine(char *buffer,
@ -36,7 +36,7 @@ static int testCompareOutput(const char *expect_rel, const char *filter,
char *actualPtr = &(actualData[0]); char *actualPtr = &(actualData[0]);
char expect[PATH_MAX]; char expect[PATH_MAX];
snprintf(expect, sizeof expect - 1, "%s/tests/%s", abs_top_srcdir, expect_rel); snprintf(expect, sizeof expect - 1, "%s/%s", abs_srcdir, expect_rel);
if (virtTestLoadFile(expect, &expectPtr, MAX_FILE) < 0) if (virtTestLoadFile(expect, &expectPtr, MAX_FILE) < 0)
return -1; return -1;
@ -271,24 +271,25 @@ static int testCompareDomstateByName(const void *data ATTRIBUTE_UNUSED) {
int static int
main(int argc, char **argv) mymain(int argc, char **argv)
{ {
int ret = 0; int ret = 0;
char buffer[PATH_MAX]; char buffer[PATH_MAX];
char cwd[PATH_MAX];
abs_top_srcdir = getenv("abs_top_srcdir"); abs_srcdir = getenv("abs_srcdir");
if (!abs_top_srcdir) if (!abs_srcdir)
return 1; abs_srcdir = getcwd(cwd, sizeof(cwd));
snprintf(buffer, PATH_MAX-1, "test://%s/docs/testnode.xml", abs_top_srcdir); snprintf(buffer, PATH_MAX-1, "test://%s/../docs/testnode.xml", abs_srcdir);
buffer[PATH_MAX-1] = '\0'; buffer[PATH_MAX-1] = '\0';
progname = argv[0]; progname = argv[0];
custom_uri = buffer; custom_uri = buffer;
if (argc > 1) { if (argc > 1) {
fprintf(stderr, "Usage: %s\n", progname); fprintf(stderr, "Usage: %s\n", progname);
exit(EXIT_FAILURE); return(EXIT_FAILURE);
} }
if (virtTestRun("virsh list (default)", if (virtTestRun("virsh list (default)",
@ -355,5 +356,7 @@ main(int argc, char **argv)
1, testCompareDomstateByName, NULL) != 0) 1, testCompareDomstateByName, NULL) != 0)
ret = -1; ret = -1;
exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE); return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
} }
VIRT_TEST_MAIN(mymain)