+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>
* src/memory.h, src/memory.c, tests/testutils.c: Pass allocation
* Structures allocations and deallocations *
* *
************************************************************************/
-static void virConfFreeValue(virConfValuePtr val);
/**
* virConfFreeList:
*
* Free a value
*/
-static void
-virConfFreeValue(virConfValuePtr val)
+void
+__virConfFreeValue(virConfValuePtr val)
{
if (val == NULL)
return;
virConfPtr __virConfReadMem (const char *memory,
int len);
int __virConfFree (virConfPtr conf);
+void __virConfFreeValue (virConfValuePtr val);
virConfValuePtr __virConfGetValue (virConfPtr conf,
const char *setting);
int *len,
virConfPtr conf);
-#define virConfNew() (__virConfNew())
-#define virConfReadFile(f) (__virConfReadFile((f)))
-#define virConfReadMem(m,l) (__virConfReadMem((m),(l)))
-#define virConfFree(c) (__virConfFree((c)))
-#define virConfGetValue(c,s) (__virConfGetValue((c),(s)))
-#define virConfSetValue(c,s,v) (__virConfSetValue((c),(s),(v)))
-#define virConfWriteFile(f,c) (__virConfWriteFile((f),(c)))
-#define virConfWriteMem(m,l,c) (__virConfWriteMem((m),(l),(c)))
+#define virConfNew() __virConfNew()
+#define virConfReadFile(f) __virConfReadFile((f))
+#define virConfReadMem(m,l) __virConfReadMem((m),(l))
+#define virConfFree(c) __virConfFree((c))
+#define virConfFreeValue(v) __virConfFreeValue((v))
+#define virConfGetValue(c,s) __virConfGetValue((c),(s))
+#define virConfSetValue(c,s,v) __virConfSetValue((c),(s),(v))
+#define virConfWriteFile(f,c) __virConfWriteFile((f),(c))
+#define virConfWriteMem(m,l,c) __virConfWriteMem((m),(l),(c))
#ifdef __cplusplus
}
p = virConfGetValue (conf, "vnc_tls_x509_cert_dir");
CHECK_TYPE ("vnc_tls_x509_cert_dir", VIR_CONF_STRING);
if (p && p->str) {
- free(driver->vncTLSx509certdir);
+ VIR_FREE(driver->vncTLSx509certdir);
if (!(driver->vncTLSx509certdir = strdup(p->str))) {
qemudReportError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY,
"%s", _("failed to allocate vncTLSx509certdir"));
while (disk) {
struct qemud_vm_disk_def *prev = disk;
disk = disk->next;
- free(prev);
+ VIR_FREE(prev);
}
while (net) {
struct qemud_vm_net_def *prev = net;
net = net->next;
- free(prev);
+ VIR_FREE(prev);
}
while (input) {
struct qemud_vm_input_def *prev = input;
input = input->next;
- free(prev);
+ VIR_FREE(prev);
}
while (serial) {
struct qemud_vm_chr_def *prev = serial;
serial = serial->next;
- free(prev);
+ VIR_FREE(prev);
}
while (parallel) {
struct qemud_vm_chr_def *prev = parallel;
parallel = parallel->next;
- free(prev);
+ VIR_FREE(prev);
}
while (sound) {
struct qemud_vm_sound_def *prev = sound;
sound = sound->next;
- free(prev);
+ VIR_FREE(prev);
}
xmlFree(def->keymap);
- free(def);
+ VIR_FREE(def);
}
void qemudFreeVM(struct qemud_vm *vm) {
qemudFreeVMDef(vm->def);
if (vm->newDef)
qemudFreeVMDef(vm->newDef);
- free(vm);
+ VIR_FREE(vm);
}
}
for (i = 0; i < obj->nodesetval->nodeNr; i++) {
- struct qemud_vm_chr_def *chr = calloc(1, sizeof(*chr));
- if (!chr) {
+ struct qemud_vm_chr_def *chr;
+ if (VIR_ALLOC(chr) < 0) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,
"%s",
_("failed to allocate space for char device"));
}
if (qemudParseCharXML(conn, chr, i, obj->nodesetval->nodeTab[i]) < 0) {
- free(chr);
+ VIR_FREE(chr);
goto cleanup;
}
if (ndevs)
int i;
struct qemud_vm_def *def;
- if (!(def = calloc(1, sizeof(*def)))) {
+ if (VIR_ALLOC(def) < 0) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,
"%s", _("failed to allocate space for xmlXPathContext"));
return NULL;
"%s", _("invalid domain type attribute"));
goto error;
}
- free(prop);
- prop = NULL;
+ VIR_FREE(prop);
/* Extract domain name */
if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) {
for (i = 0; i < obj->nodesetval->nodeNr; i++) {
- struct qemud_vm_disk_def *disk = calloc(1, sizeof(*disk));
- if (!disk) {
+ struct qemud_vm_disk_def *disk;
+ if (VIR_ALLOC(disk) < 0) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,
"%s", _("failed to allocate space for disk string"));
goto error;
}
if (qemudParseDiskXML(conn, disk, obj->nodesetval->nodeTab[i]) < 0) {
- free(disk);
+ VIR_FREE(disk);
goto error;
}
def->ndisks++;
obj = xmlXPathEval(BAD_CAST "/domain/devices/console", ctxt);
if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr == 1)) {
- struct qemud_vm_chr_def *chr = calloc(1, sizeof(*chr));
- if (!chr) {
+ struct qemud_vm_chr_def *chr;
+ if (VIR_ALLOC(chr) < 0) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,
"%s",
_("failed to allocate space for char device"));
}
if (qemudParseCharXML(conn, chr, 0, obj->nodesetval->nodeTab[0]) < 0) {
- free(chr);
+ VIR_FREE(chr);
goto error;
}
def->nserials = 1;
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) {
struct qemud_vm_net_def *prev = NULL;
for (i = 0; i < obj->nodesetval->nodeNr; i++) {
- struct qemud_vm_net_def *net = calloc(1, sizeof(*net));
- if (!net) {
+ struct qemud_vm_net_def *net;
+ if (VIR_ALLOC(net) < 0) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,
"%s", _("failed to allocate space for net string"));
goto error;
}
if (qemudParseInterfaceXML(conn, net, obj->nodesetval->nodeTab[i]) < 0) {
- free(net);
+ VIR_FREE(net);
goto error;
}
def->nnets++;
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) {
struct qemud_vm_input_def *prev = NULL;
for (i = 0; i < obj->nodesetval->nodeNr; i++) {
- struct qemud_vm_input_def *input = calloc(1, sizeof(*input));
- if (!input) {
+ struct qemud_vm_input_def *input;
+ if (VIR_ALLOC(input) < 0) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,
"%s", _("failed to allocate space for input string"));
goto error;
}
if (qemudParseInputXML(conn, def, input, obj->nodesetval->nodeTab[i]) < 0) {
- free(input);
+ VIR_FREE(input);
goto error;
}
/* Mouse + PS/2 is implicit with graphics, so don't store it */
if (input->bus == QEMU_INPUT_BUS_PS2 &&
input->type == QEMU_INPUT_TYPE_MOUSE) {
- free(input);
+ VIR_FREE(input);
continue;
}
def->ninputs++;
struct qemud_vm_sound_def *prev = NULL;
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;
int collision = 0;
- if (!sound) {
+ if (VIR_ALLOC(sound) < 0) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,
"%s", _("failed to allocate space for sound dev"));
goto error;
}
if (qemudParseSoundXML(conn, sound,
obj->nodesetval->nodeTab[i]) < 0) {
- free(sound);
+ VIR_FREE(sound);
goto error;
}
check = check->next;
}
if (collision) {
- free(sound);
+ VIR_FREE(sound);
continue;
}
}
if (!hasPS2mouse) {
- input = calloc(1, sizeof(*input));
- if (!input) {
+ if (VIR_ALLOC(input) < 0) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,
"%s", _("failed to allocate space for input string"));
goto error;
return def;
error:
- free(prop);
+ VIR_FREE(prop);
xmlXPathFreeObject(obj);
xmlXPathFreeContext(ctxt);
qemudFreeVMDef(def);
char *retval = NULL;
int err;
int tapfd = -1;
- int *tapfds;
if (net->type == QEMUD_NET_NETWORK) {
if (!(network = qemudFindNetworkByName(driver, net->dst.network.name))) {
if (!(retval = strdup(tapfdstr)))
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;
- vm->tapfds = tapfds;
vm->tapfds[vm->ntapfds++] = tapfd;
vm->tapfds[vm->ntapfds] = -1;
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,
"%s", _("failed to allocate space for tapfds string"));
error:
- free(retval);
+ VIR_FREE(retval);
if (tapfd != -1)
close(tapfd);
return NULL;
/* Add sound hardware */
if (sound) {
int size = 100;
- char *modstr = calloc(1, size+1);
- if (!modstr)
+ char *modstr;
+ if (VIR_ALLOC_N(modstr, size+1) < 0)
goto no_memory;
while(sound && size > 0) {
const char *model = qemudSoundModelToString(sound->model);
if (!model) {
- free(modstr);
+ VIR_FREE(modstr);
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
"%s", _("invalid sound model"));
goto error;
if (vm->tapfds) {
for (i = 0; vm->tapfds[i] != -1; i++)
close(vm->tapfds[i]);
- free(vm->tapfds);
+ VIR_FREE(vm->tapfds);
vm->tapfds = NULL;
vm->ntapfds = 0;
}
if (qargv) {
for (i = 0 ; i < qargc ; i++)
- free((qargv)[i]);
- free(qargv);
+ VIR_FREE((qargv)[i]);
+ VIR_FREE(qargv);
}
return -1;
if (fd != -1)
close(fd);
- free(xml);
+ VIR_FREE(xml);
return ret;
}
{
xmlDocPtr xml;
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,
XML_PARSE_NOENT | XML_PARSE_NONET |
XML_PARSE_NOERROR | XML_PARSE_NOWARNING))) {
qemudReportError(conn, NULL, NULL, VIR_ERR_XML_ERROR, NULL);
- return NULL;
+ goto error;
}
node = xmlDocGetRootElement(xml);
error:
if (xml) xmlFreeDoc(xml);
- free(dev);
+ VIR_FREE(dev);
return NULL;
}
return vm;
}
- if (!(vm = calloc(1, sizeof(*vm)))) {
+ if (VIR_ALLOC(vm) < 0) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,
"%s", _("failed to allocate space for vm string"));
return NULL;
cleanup:
- free(xml);
+ VIR_FREE(xml);
return ret;
}
struct qemud_dhcp_range_def *range = def->ranges;
while (range) {
struct qemud_dhcp_range_def *next = range->next;
- free(range);
+ VIR_FREE(range);
range = next;
}
- free(def);
+ VIR_FREE(def);
}
void qemudFreeNetwork(struct qemud_network *network) {
qemudFreeNetworkDef(network->def);
if (network->newDef)
qemudFreeNetworkDef(network->newDef);
- free(network);
+ VIR_FREE(network);
}
static int qemudParseBridgeXML(struct qemud_driver *driver ATTRIBUTE_UNUSED,
continue;
}
- if (!(range = calloc(1, sizeof(*range)))) {
+ if (VIR_ALLOC(range) < 0) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,
"%s", _("failed to allocate space for range string"));
return 0;
def->ranges = range;
def->nranges++;
} else {
- free(range);
+ VIR_FREE(range);
}
xmlFree(start);
xmlXPathObjectPtr obj = NULL, tmp = NULL;
struct qemud_network_def *def;
- if (!(def = calloc(1, sizeof(*def)))) {
+ if (VIR_ALLOC(def) < 0) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,
"%s", _("failed to allocate space for network_def string"));
return NULL;
return network;
}
- if (!(network = calloc(1, sizeof(*network)))) {
+ if (VIR_ALLOC(network) < 0) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,
"%s", _("failed to allocate space for network string"));
return NULL;
else
qemudLoadNetworkConfig(driver, entry->d_name, path, xml, autostartLink);
- free(xml);
+ VIR_FREE(xml);
}
closedir(dir);
const struct qemud_vm_input_def *input;
const struct qemud_vm_sound_def *sound;
const struct qemud_vm_chr_def *chr;
- const char *type = NULL;
+ const char *type = NULL, *tmp;
int n, allones = 1;
if (!(type = qemudVirtTypeToString(def->virtType))) {
goto cleanup;
}
virBufferVSprintf(&buf, " <vcpu cpuset='%s'>%d</vcpu>\n", cpumask, def->vcpus);
- free(cpumask);
+ VIR_FREE(cpumask);
}
if (def->os.bootloader[0])
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,
"%s", _("failed to generate XML: out of memory"));
cleanup:
- free(virBufferContentAndReset(&buf));
+ tmp = virBufferContentAndReset(&buf);
+ VIR_FREE(tmp);
return NULL;
}
struct qemud_network_def *def) {
virBuffer buf = VIR_BUFFER_INITIALIZER;
unsigned char *uuid;
+ char *tmp;
char uuidstr[VIR_UUID_STRING_BUFLEN];
virBufferAddLit(&buf, "<network>\n");
no_memory:
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,
"%s", _("failed to generate XML: out of memory"));
- free(virBufferContentAndReset(&buf));
+ tmp = virBufferContentAndReset(&buf);
+ VIR_FREE(tmp);
return NULL;
}
char *base = NULL;
char driverConf[PATH_MAX];
- if (!(qemu_driver = calloc(1, sizeof(*qemu_driver)))) {
+ if (VIR_ALLOC(qemu_driver) < 0)
return -1;
- }
/* Don't have a dom0 so start from 1 */
qemu_driver->nextvmid = 1;
base) == -1)
goto out_of_memory;
- free(base);
- base = NULL;
+ VIR_FREE(base);
if ((qemu_driver->caps = qemudCapsInit()) == NULL)
goto out_of_memory;
out_of_memory:
qemudLog (QEMUD_ERR,
"%s", _("qemudStartup: out of memory"));
- free (base);
- free(qemu_driver);
- qemu_driver = NULL;
+ VIR_FREE(base);
+ VIR_FREE(qemu_driver);
return -1;
}
qemu_driver->nactivenetworks = 0;
qemu_driver->ninactivenetworks = 0;
- free(qemu_driver->configDir);
- free(qemu_driver->autostartDir);
- free(qemu_driver->networkConfigDir);
- free(qemu_driver->networkAutostartDir);
- free(qemu_driver->vncTLSx509certdir);
+ VIR_FREE(qemu_driver->configDir);
+ VIR_FREE(qemu_driver->autostartDir);
+ VIR_FREE(qemu_driver->networkConfigDir);
+ VIR_FREE(qemu_driver->networkAutostartDir);
+ VIR_FREE(qemu_driver->vncTLSx509certdir);
if (qemu_driver->brctl)
brShutdown(qemu_driver->brctl);
if (qemu_driver->iptables)
iptablesContextFree(qemu_driver->iptables);
- free(qemu_driver);
- qemu_driver = NULL;
+ VIR_FREE(qemu_driver);
return 0;
}
if (lastVcpu != (vm->def->vcpus - 1))
goto error;
- free(qemucpus);
+ VIR_FREE(qemucpus);
return 0;
error:
VIR_FREE(vm->vcpupids);
- vm->vcpupids = 0;
- free(qemucpus);
+ vm->nvcpupids = 0;
+ VIR_FREE(qemucpus);
/* Explicitly return success, not error. Older KVM does
not have vCPU -> Thread mapping info and we don't
"%s", _("resume operation failed"));
return -1;
}
- free(info);
+ VIR_FREE(info);
return 0;
}
}
for (i = 0 ; argv[i] ; i++)
- free(argv[i]);
- free(argv);
+ VIR_FREE(argv[i]);
+ VIR_FREE(argv);
if (vm->tapfds) {
for (i = 0; vm->tapfds[i] != -1; i++) {
close(vm->tapfds[i]);
vm->tapfds[i] = -1;
}
- free(vm->tapfds);
- vm->tapfds = NULL;
+ VIR_FREE(vm->tapfds);
vm->ntapfds = 0;
}
vm->pid = -1;
vm->id = -1;
vm->state = VIR_DOMAIN_SHUTOFF;
- free(vm->vcpupids);
- vm->vcpupids = NULL;
+ VIR_FREE(vm->vcpupids);
vm->nvcpupids = 0;
if (vm->newDef) {
(2 * network->def->nranges) + /* --dhcp-range 10.0.0.2,10.0.0.254 */
1; /* NULL */
- if (!(*argv = calloc(len, sizeof(**argv))))
+ if (VIR_ALLOC_N(*argv, len) < 0)
goto no_memory;
#define APPEND_ARG(v, n, s) do { \
no_memory:
if (argv) {
for (i = 0; (*argv)[i]; i++)
- free((*argv)[i]);
- free(*argv);
+ VIR_FREE((*argv)[i]);
+ VIR_FREE(*argv);
}
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,
"%s", _("failed to allocate space for dnsmasq argv"));
ret = virExecNonBlock(conn, argv, &network->dnsmasqPid, -1, NULL, NULL);
for (i = 0; argv[i]; i++)
- free(argv[i]);
- free(argv);
+ VIR_FREE(argv[i]);
+ VIR_FREE(argv);
return ret;
}
for (;;) {
char data[1024];
int got = read(vm->monitor, data, sizeof(data));
- char *b;
if (got == 0)
goto error;
break;
goto error;
}
- if (!(b = realloc(buf, size+got+1)))
+ if (VIR_REALLOC_N(buf, size+got+1) < 0)
goto error;
- buf = b;
memmove(buf+size, data, got);
buf[size+got] = '\0';
size += got;
if (safewrite(vm->logfile, buf, strlen(buf)) < 0)
qemudLog(QEMUD_WARN, _("Unable to log VM console data: %s"),
strerror(errno));
- free(buf);
+ VIR_FREE(buf);
}
return -1;
}
}
vm->state = VIR_DOMAIN_PAUSED;
qemudDebug("Reply %s", info);
- free(info);
+ VIR_FREE(info);
return 0;
}
}
vm->state = VIR_DOMAIN_RUNNING;
qemudDebug("Reply %s", info);
- free(info);
+ VIR_FREE(info);
return 0;
}
}
}
- if ((out = (char *)malloc(len + 1)) == NULL)
+ if (VIR_ALLOC_N(out, len + 1) < 0)
return NULL;
for (i = j = 0; in[i] != '\0'; i++) {
if ((fd = open(path, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR)) < 0) {
qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
_("failed to create '%s'"), path);
- free(xml);
+ VIR_FREE(xml);
return -1;
}
qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
"%s", _("failed to write save header"));
close(fd);
- free(xml);
+ VIR_FREE(xml);
return -1;
}
qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
"%s", _("failed to write xml"));
close(fd);
- free(xml);
+ VIR_FREE(xml);
return -1;
}
close(fd);
- free(xml);
+ VIR_FREE(xml);
/* Migrate to file */
safe_path = qemudEscapeShellArg(path);
"\"", safe_path) == -1) {
qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
"%s", _("out of memory"));
- free(safe_path);
+ VIR_FREE(safe_path);
return -1;
}
free(safe_path);
if (qemudMonitorCommand(driver, vm, command, &info) < 0) {
qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
"%s", _("migrate operation failed"));
- free(command);
+ VIR_FREE(command);
return -1;
}
- free(info);
- free(command);
+ VIR_FREE(info);
+ VIR_FREE(command);
/* Shut it down */
qemudShutdownVMDaemon(dom->conn, driver, vm);
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,
"%s", _("out of memory"));
close(fd);
qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_FAILED,
"%s", _("failed to read XML"));
close(fd);
- free(xml);
+ VIR_FREE(xml);
return -1;
}
qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_FAILED,
"%s", _("failed to parse XML"));
close(fd);
- free(xml);
+ VIR_FREE(xml);
return -1;
}
- free(xml);
+ VIR_FREE(xml);
/* Ensure the name and UUID don't already exist in an active VM */
vm = qemudFindVMByUUID(driver, def->uuid);
"%s", _("failed to resume domain"));
return -1;
}
- free(info);
+ VIR_FREE(info);
vm->state = VIR_DOMAIN_RUNNING;
}
cleanup:
for (i = 0 ; i < got ; i++)
- free(names[i]);
+ VIR_FREE(names[i]);
return -1;
}
safe_path) == -1) {
qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
"%s", _("out of memory"));
- free(safe_path);
+ VIR_FREE(safe_path);
return -1;
}
- free(safe_path);
+ VIR_FREE(safe_path);
} else if (asprintf(&cmd, "eject cdrom") == -1) {
qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
if (qemudMonitorCommand(driver, vm, cmd, &reply) < 0) {
qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
"%s", _("cannot change cdrom media"));
- free(cmd);
+ VIR_FREE(cmd);
return -1;
}
- free(reply);
- free(cmd);
+ VIR_FREE(reply);
+ VIR_FREE(cmd);
strcpy(olddisk->src, newdisk->src);
olddisk->type = newdisk->type;
return 0;
if (dev->type != QEMUD_DEVICE_DISK || dev->data.disk.device != QEMUD_DISK_CDROM) {
qemudReportError(dom->conn, dom, NULL, VIR_ERR_NO_SUPPORT,
"%s", _("only CDROM disk devices can be attached"));
- free(dev);
+ VIR_FREE(dev);
return -1;
}
if (!disk) {
qemudReportError(dom->conn, dom, NULL, VIR_ERR_NO_SUPPORT,
"%s", _("CDROM not attached, cannot change media"));
- free(dev);
+ VIR_FREE(dev);
return -1;
}
if (qemudDomainChangeCDROM(dom, vm, disk, &dev->data.disk) < 0) {
- free(dev);
+ VIR_FREE(dev);
return -1;
}
- free(dev);
+ VIR_FREE(dev);
return 0;
}
cleanup:
for (i = 0 ; i < got ; i++)
- free(names[i]);
+ VIR_FREE(names[i]);
return -1;
}
cleanup:
for (i = 0 ; i < got ; i++)
- free(names[i]);
+ VIR_FREE(names[i]);
return -1;
}
#include "util.h"
#include "uuid.h"
#include "capabilities.h"
+#include "memory.h"
/* Flags that determine the action to take on a shutdown or crash of a domain
*/
testError(conn, NULL, NULL, VIR_ERR_XML_ERROR, _("domain uuid"));
goto error;
}
- free(str);
+ VIR_FREE(str);
ret = virXPathLong("string(/domain/memory[1])", ctxt, &l);
if (str != NULL) {
if (!(onReboot = testRestartStringToFlag(str))) {
testError(conn, NULL, NULL, VIR_ERR_XML_ERROR, _("domain reboot behaviour"));
- free(str);
+ VIR_FREE(str);
goto error;
}
- free(str);
+ VIR_FREE(str);
}
str = virXPathString("string(/domain/on_poweroff[1])", ctxt);
if (str != NULL) {
if (!(onPoweroff = testRestartStringToFlag(str))) {
testError(conn, NULL, NULL, VIR_ERR_XML_ERROR, _("domain poweroff behaviour"));
- free(str);
+ VIR_FREE(str);
goto error;
}
- free(str);
+ VIR_FREE(str);
}
str = virXPathString("string(/domain/on_crash[1])", ctxt);
if (str != NULL) {
if (!(onCrash = testRestartStringToFlag(str))) {
testError(conn, NULL, NULL, VIR_ERR_XML_ERROR, _("domain crash behaviour"));
- free(str);
+ VIR_FREE(str);
goto error;
}
- free(str);
+ VIR_FREE(str);
}
for (i = 0 ; i < MAX_DOMAINS ; i++) {
privconn->domains[handle].id = domid;
strncpy(privconn->domains[handle].name, name, sizeof(privconn->domains[handle].name)-1);
privconn->domains[handle].name[sizeof(privconn->domains[handle].name)-1] = '\0';
- free(name);
+ VIR_FREE(name);
name = NULL;
if (memory > maxMem)
error:
xmlXPathFreeContext(ctxt);
- free(name);
+ VIR_FREE(name);
return (-1);
}
testError(conn, NULL, NULL, VIR_ERR_XML_ERROR, _("network uuid"));
goto error;
}
- free(str);
+ VIR_FREE(str);
forward = virXPathBoolean("count(/network/forward) != 0", ctxt);
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);
privconn->networks[handle].bridge[sizeof(privconn->networks[handle].bridge)-1] = '\0';
- free(name);
+ VIR_FREE(name);
name = NULL;
if (bridge) {
- free(bridge);
+ VIR_FREE(bridge);
bridge = NULL;
}
if (forwardDev) {
strncpy(privconn->networks[handle].forwardDev, forwardDev, sizeof(privconn->networks[handle].forwardDev)-1);
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);
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);
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);
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);
privconn->networks[handle].dhcpEnd[sizeof(privconn->networks[handle].dhcpEnd)-1] = '\0';
- free(dhcpend);
+ VIR_FREE(dhcpend);
xmlXPathFreeContext(ctxt);
return (handle);
error:
xmlXPathFreeContext(ctxt);
- free (forwardDev);
- free(ipaddress);
- free(ipnetmask);
- free(dhcpstart);
- free(dhcpend);
- free(name);
+ VIR_FREE (forwardDev);
+ VIR_FREE(ipaddress);
+ VIR_FREE(ipnetmask);
+ VIR_FREE(dhcpstart);
+ VIR_FREE(dhcpend);
+ VIR_FREE(name);
return (-1);
}
static int testOpenDefault(virConnectPtr conn) {
int u;
struct timeval tv;
- testConnPtr privconn = malloc(sizeof(*privconn));
- if (!privconn) {
+ testConnPtr privconn;
+ if (VIR_ALLOC(privconn) < 0) {
testError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "testConn");
return VIR_DRV_OPEN_ERROR;
}
offset = strrchr(relativeTo, '/');
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);
absFile[baseLen] = '\0';
strcat(absFile, filename);
xmlNodePtr *domains, *networks = NULL;
xmlXPathContextPtr ctxt = NULL;
virNodeInfoPtr nodeInfo;
- testConnPtr privconn = calloc(1, sizeof(*privconn));
- if (!privconn) {
+ testConnPtr privconn;
+ if (VIR_ALLOC(privconn) < 0) {
testError(NULL, NULL, NULL, VIR_ERR_NO_MEMORY, "testConn");
return VIR_DRV_OPEN_ERROR;
}
if (str != NULL) {
strncpy(nodeInfo->model, str, sizeof(nodeInfo->model)-1);
nodeInfo->model[sizeof(nodeInfo->model)-1] = '\0';
- free(str);
+ VIR_FREE(str);
}
ret = virXPathLong("string(/node/memory[1])", ctxt, &l);
xmlChar *domFile = xmlGetProp(domains[i], BAD_CAST "file");
char *absFile = testBuildFilename(file, (const char *)domFile);
int domid = privconn->nextDomID++, handle;
- free(domFile);
+ VIR_FREE(domFile);
if (!absFile) {
testError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, _("resolving domain filename"));
goto error;
}
if ((handle = testLoadDomainFromFile(conn, domid, absFile)) < 0) {
- free(absFile);
+ VIR_FREE(absFile);
goto error;
}
privconn->domains[handle].config = 1;
- free(absFile);
+ VIR_FREE(absFile);
privconn->numDomains++;
}
if (domains != NULL) {
- free(domains);
+ VIR_FREE(domains);
domains = NULL;
}
xmlChar *netFile = xmlGetProp(networks[i], BAD_CAST "file");
char *absFile = testBuildFilename(file, (const char *)netFile);
int handle;
- free(netFile);
+ VIR_FREE(netFile);
if (!absFile) {
testError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, _("resolving network filename"));
goto error;
}
if ((handle = testLoadNetworkFromFile(conn, absFile)) < 0) {
- free(absFile);
+ VIR_FREE(absFile);
goto error;
}
privconn->networks[handle].config = 1;
- free(absFile);
+ VIR_FREE(absFile);
privconn->numNetworks++;
}
if (networks != NULL) {
- free(networks);
+ VIR_FREE(networks);
networks = NULL;
}
}
error:
xmlXPathFreeContext(ctxt);
- free(domains);
- free(networks);
+ VIR_FREE(domains);
+ VIR_FREE(networks);
if (xml)
xmlFreeDoc(xml);
if (fd != -1)
close(fd);
- free(privconn);
+ VIR_FREE(privconn);
conn->privateData = NULL;
return VIR_DRV_OPEN_ERROR;
}
static int testClose(virConnectPtr conn)
{
GET_CONNECTION(conn, -1);
- free (privconn);
+ VIR_FREE (privconn);
conn->privateData = conn;
return 0;
}
if (safewrite(fd, xml, len) < 0) {
testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR,
_("cannot write metadata"));
- free(xml);
+ VIR_FREE(xml);
close(fd);
return (-1);
}
- free(xml);
+ VIR_FREE(xml);
if (close(fd) < 0) {
testError(domain->conn, domain, NULL, VIR_ERR_INTERNAL_ERROR,
_("cannot save domain data"));
close(fd);
return (-1);
}
- xml = malloc(len+1);
- if (!xml) {
+ if (VIR_ALLOC_N(xml, len+1) < 0) {
testError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, "xml");
close(fd);
return (-1);
close(fd);
domid = privconn->nextDomID++;
ret = testLoadDomainFromDoc(conn, domid, xml);
- free(xml);
+ VIR_FREE(xml);
return ret < 0 ? -1 : 0;
}
#include "event.h"
#include "buf.h"
#include "util.h"
-
+#include "memory.h"
#include "util-lib.c"
#ifndef MIN
size_t requested;
if (size + BUFSIZ + 1 > alloc) {
- char *new_buf;
-
alloc += alloc / 2;
if (alloc < size + BUFSIZ + 1)
alloc = size + BUFSIZ + 1;
- new_buf = realloc (buf, alloc);
- if (!new_buf) {
+ if (VIR_ALLOC_N(buf, alloc) < 0) {
save_errno = errno;
break;
}
-
- buf = new_buf;
}
/* Ensure that (size + requested <= max_len); */
}
if (len > maxlen || (int)len != len) {
- free(s);
+ VIR_FREE(s);
virLog("File '%s' is too large %d, max %d",
path, (int)len, maxlen);
goto error;
#include "xend_internal.h"
#include "xen_internal.h" /* for DOM0_INTERFACE_VERSION */
#include "xs_internal.h" /* To extract VNC port & Serial console TTY */
+#include "memory.h"
/* required for cpumap_t */
#include <xen/dom0_ops.h>
content = virBufferContentAndReset(&buf);
ret = http2unix(xend, xend_post(xend, path, content, error, n_error));
- free(content);
+ VIR_FREE(content);
return ret;
}
urlencode(const char *string)
{
size_t len = strlen(string);
- char *buffer = malloc(len * 3 + 1);
- char *ptr = buffer;
+ char *buffer;
+ char *ptr;
size_t i;
- if (buffer == NULL) {
+ if (VIR_ALLOC_N(buffer, len * 3 + 1) < 0) {
virXendError(NULL, VIR_ERR_NO_MEMORY, _("allocate new buffer"));
return (NULL);
}
+ ptr = buffer;
for (i = 0; i < len; i++) {
switch (string[i]) {
case ' ':
char *sound_string_to_xml(const char *sound) {
virBuffer buf = VIR_BUFFER_INITIALIZER;
+ char *tmp;
while (sound) {
int modelsize, valid, collision = 0;
if (STREQ(model, "all")) {
int i;
if (virBufferError(&buf)) {
- free(model);
+ VIR_FREE(model);
goto error;
}
- free(virBufferContentAndReset(&buf));
+ tmp = virBufferContentAndReset(&buf);
+ VIR_FREE(tmp);
for (i=0; i < sizeof(sound_models)/sizeof(*sound_models); ++i)
virBufferVSprintf(&buf, " <sound model='%s'/>\n",
sound_models[i]);
- free(model);
+ VIR_FREE(model);
break;
}
}
virBufferVSprintf(&buf, " <sound model='%s'/>\n", model);
sound = (model_end ? ++model_end : NULL);
- free(model);
+ VIR_FREE(model);
}
if (virBufferError(&buf))
return virBufferContentAndReset(&buf);
error:
- free(virBufferContentAndReset(&buf));
+ tmp = virBufferContentAndReset(&buf);
+ VIR_FREE(tmp);
return NULL;
}
count++;
}
- ptr = malloc((count + 1) * sizeof(char *) + extra);
- if (ptr == NULL)
+ if (VIR_ALLOC_N(ptr, count + 1 + extra) < 0)
goto error;
ret = (char **) ptr;
ret = xend_op(xend, "", "op", "create", "config", ptr, NULL);
serrno = errno;
- free(ptr);
+ VIR_FREE(ptr);
errno = serrno;
return ret;
error:
sexpr_free(root);
- if (domname && *domname) {
- free(*domname);
- *domname = NULL;
- }
+ if (domname)
+ VIR_FREE(*domname);
return (-1);
}
error:
- free(path);
- free(bindHost);
- free(bindPort);
- free(connectHost);
- free(connectPort);
+ VIR_FREE(path);
+ VIR_FREE(bindHost);
+ VIR_FREE(bindPort);
+ VIR_FREE(connectHost);
+ VIR_FREE(connectPort);
return ret;
}
{
struct sexpr *cur, *node;
const char *tmp;
- char *tty;
+ char *tty, *val;
virBuffer buf = VIR_BUFFER_INITIALIZER;
int hvm = 0, bootloader = 0, vfb = 0;
int domid = -1;
goto bad_parse;
}
- drvName = malloc((offset-src)+1);
- if (!drvName) {
+ if (VIR_ALLOC_N(drvName, (offset-src)+1) < 0) {
virXendError(conn, VIR_ERR_NO_MEMORY,
_("allocate new buffer"));
goto bad_parse;
goto bad_parse;
}
- drvType = malloc((offset-src)+1);
- if (!drvType) {
+ if (VIR_ALLOC_N(drvType, (offset-src)+1)< 0) {
virXendError(conn, VIR_ERR_NO_MEMORY,
_("allocate new buffer"));
goto bad_parse;
virBufferAddLit(&buf, " </disk>\n");
bad_parse:
- free(drvName);
- free(drvType);
+ VIR_FREE(drvName);
+ VIR_FREE(drvType);
} else if (sexpr_lookup(node, "device/vif")) {
const char *tmp2, *model;
tmp2 = sexpr_node(node, "device/vif/script");
virBufferAddLit(&buf, " <target port='0'/>\n");
virBufferAddLit(&buf, " </console>\n");
}
- free(tty);
+ VIR_FREE(tty);
if (hvm) {
if (sexpr_node(root, "domain/image/hvm/soundhw")) {
if (tmp && *tmp) {
if ((soundxml = sound_string_to_xml(tmp))) {
virBufferVSprintf(&buf, "%s", soundxml);
- free(soundxml);
+ VIR_FREE(soundxml);
} else {
virXendError(conn, VIR_ERR_INTERNAL_ERROR,
_("parsing soundhw string failed."));
return virBufferContentAndReset(&buf);
error:
- free(virBufferContentAndReset(&buf));
+ val = virBufferContentAndReset(&buf);
+ VIR_FREE(val);
return (NULL);
}
numCpus = sexpr_int(root, "node/nr_cpus");
- cpuset = malloc(numCpus * sizeof(*cpuset));
- if (cpuset == NULL)
+ if (VIR_ALLOC_N(cpuset, numCpus) < 0)
goto memory_error;
- cpuNums = malloc(numCpus * sizeof(*cpuNums));
- if (cpuNums == NULL)
+ if (VIR_ALLOC_N(cpuNums, numCpus) < 0)
goto memory_error;
cur = nodeToCpu;
cpuNums) < 0)
goto memory_error;
}
- free(cpuNums);
- free(cpuset);
+ VIR_FREE(cpuNums);
+ VIR_FREE(cpuset);
return (0);
parse_error:
virXendError(conn, VIR_ERR_XEN_CALL, _("topology syntax error"));
error:
- free(cpuNums);
- free(cpuset);
+ VIR_FREE(cpuNums);
+ VIR_FREE(cpuset);
return (-1);
memory_error:
- free(cpuNums);
- free(cpuset);
+ VIR_FREE(cpuNums);
+ VIR_FREE(cpuset);
virXendError(conn, VIR_ERR_NO_MEMORY, _("allocate buffer"));
return (-1);
}
}
error:
- sexpr_free(root);
+ sexpr_free(root);
return(ret);
}
}
error:
- sexpr_free(root);
+ sexpr_free(root);
return(ret);
}
#endif /* ! PROXY */
if (ret == NULL) return NULL;
ret->id = id;
- free(name);
+ VIR_FREE(name);
return (ret);
error:
- free(name);
+ VIR_FREE(name);
return (NULL);
}
}
tmp++;
}
- free(names);
+ VIR_FREE(names);
} else { /* New approach for xen >= 3.0.4 */
char *domname = NULL;
char uuidstr[VIR_UUID_STRING_BUFLEN];
if (ret == NULL) return NULL;
ret->id = id;
- free(name);
+ VIR_FREE(name);
return (ret);
}
if ((sexpr == NULL) || (name == NULL)) {
virXendError(conn, VIR_ERR_XML_ERROR,
_("failed to parse domain description"));
- free(sexpr);
- free(name);
+ VIR_FREE(sexpr);
+ VIR_FREE(name);
return (NULL);
}
ret = xenDaemonDomainCreateLinux(conn, sexpr);
- free(sexpr);
+ VIR_FREE(sexpr);
if (ret != 0) {
goto error;
}
if ((ret = xenDaemonDomainResume(dom)) < 0)
goto error;
- free(name);
+ VIR_FREE(name);
return (dom);
xenDaemonDomainDestroy(dom);
virUnrefDomain(dom);
}
- free(name);
+ VIR_FREE(name);
return (NULL);
}
str = virDomainGetOSType(domain);
if (STREQ(str, "hvm"))
hvm = 1;
- free(str);
+ VIR_FREE(str);
sexpr = virParseXMLDevice(domain->conn, xml, hvm, priv->xendConfigVersion);
if (sexpr == NULL)
return (-1);
ret = xend_op(domain->conn, domain->name, "op", "device_configure",
"config", conf, "dev", ref, NULL);
}
- free(sexpr);
+ VIR_FREE(sexpr);
return ret;
}
// Change the autostart value in place, then define the new sexpr
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")
: strdup("ignore"));
if (!(autonode->u.s.car->u.value)) {
"port", port,
"resource", "0", /* required, xend ignores it */
NULL);
- free (hostname);
+ VIR_FREE (hostname);
DEBUG0("migration done");
if ((sexpr == NULL) || (name == NULL)) {
virXendError(conn, VIR_ERR_XML_ERROR,
_("failed to parse domain description"));
- free(sexpr);
- free(name);
+ VIR_FREE(sexpr);
+ VIR_FREE(name);
return (NULL);
}
ret = xend_op(conn, "", "op", "new", "config", sexpr, NULL);
- free(sexpr);
+ VIR_FREE(sexpr);
if (ret != 0) {
fprintf(stderr, _("Failed to create inactive domain %s\n"), name);
goto error;
return (dom);
error:
- free(name);
+ VIR_FREE(name);
return (NULL);
}
int xenDaemonDomainCreate(virDomainPtr domain)
error:
sexpr_free(root);
- free(sched_type);
+ VIR_FREE(sched_type);
return (ret);
}
error:
sexpr_free(root);
- free(sched_type);
+ VIR_FREE(sched_type);
return (ret);
}
#include "buf.h"
#include "uuid.h"
#include "util.h"
+#include "memory.h"
static int xenXMConfigSetString(virConfPtr conf, const char *setting,
const char *str);
/* Had better have a name...*/
if (xenXMConfigGetString(conf, "name", &name) < 0) {
virConfValuePtr value;
- value = malloc(sizeof(*value));
- if (!value) {
+ if (VIR_ALLOC(value) < 0)
return (-1);
- }
/* Set name based on filename */
value->type = VIR_CONF_STRING;
value->str = strdup(filename);
if (!value->str) {
- free(value);
+ VIR_FREE(value);
return (-1);
}
if (virConfSetValue(conf, "name", value) < 0)
virConfValuePtr value;
char uuidstr[VIR_UUID_STRING_BUFLEN];
- value = malloc(sizeof(*value));
- if (!value) {
+ if (VIR_ALLOC(value) < 0)
return (-1);
- }
/* ... then generate one */
virUUIDGenerate(uuid);
value->type = VIR_CONF_STRING;
value->str = strdup(uuidstr);
if (!value->str) {
- free(value);
+ VIR_FREE(value);
return (-1);
}
static void xenXMConfigFree(void *payload, const char *key ATTRIBUTE_UNUSED) {
xenXMConfCachePtr entry = (xenXMConfCachePtr)payload;
virConfFree(entry->conf);
- free(entry);
+ VIR_FREE(entry);
}
entry->conf = NULL;
} else { /* Completely new entry */
newborn = 1;
- if (!(entry = malloc(sizeof(*entry)))) {
+ if (VIR_ALLOC(entry) < 0) {
xenXMError (conn, VIR_ERR_NO_MEMORY, strerror (errno));
goto cleanup;
}
if (!newborn) {
virHashRemoveEntry(configCache, path, NULL);
}
- free(entry);
+ VIR_FREE(entry);
continue;
}
if (!newborn) {
virHashRemoveEntry(configCache, path, NULL);
}
- free(entry);
+ VIR_FREE(entry);
xenXMError (conn, VIR_ERR_INTERNAL_ERROR,
_("xenXMConfigCacheRefresh: name"));
goto cleanup;
if (newborn) {
if (virHashAddEntry(configCache, entry->filename, entry) < 0) {
virConfFree(entry->conf);
- free(entry);
+ VIR_FREE(entry);
xenXMError (conn, VIR_ERR_INTERNAL_ERROR,
_("xenXMConfigCacheRefresh: virHashAddEntry"));
goto cleanup;
if (virHashAddEntry(nameConfigMap, domname, entry->filename) < 0) {
virHashRemoveEntry(configCache, ent->d_name, NULL);
virConfFree(entry->conf);
- free(entry);
+ VIR_FREE(entry);
}
}
}
ranges = virConvertCpuSet(conn, str, 0);
if (ranges != NULL) {
virBufferVSprintf(&buf, " cpuset='%s'", ranges);
- free(ranges);
+ VIR_FREE(ranges);
} else
virBufferVSprintf(&buf, " cpuset='%s'", str);
}
char *soundxml;
if ((soundxml = sound_string_to_xml(str))) {
virBufferVSprintf(&buf, "%s", soundxml);
- free(soundxml);
+ VIR_FREE(soundxml);
} else {
xenXMError(conn, VIR_ERR_INTERNAL_ERROR,
_("parsing soundhw string failed."));
return virBufferContentAndReset(&buf);
error:
- free(virBufferContentAndReset(&buf));
+ str = virBufferContentAndReset(&buf);
+ VIR_FREE(str);
return NULL;
}
if (!(entry = virHashLookup(configCache, filename)))
return (-1);
- if (!(value = malloc(sizeof(*value))))
+ if (VIR_ALLOC(value) < 0)
return (-1);
value->type = VIR_CONF_LONG;
if (!(entry = virHashLookup(configCache, filename)))
return (-1);
- if (!(value = malloc(sizeof(*value))))
+ if (VIR_ALLOC(value) < 0)
return (-1);
value->type = VIR_CONF_LONG;
if (!(entry = virHashLookup(configCache, filename)))
return (-1);
- if (!(value = malloc(sizeof(*value))))
+ if (VIR_ALLOC(value) < 0)
return (-1);
value->type = VIR_CONF_LONG;
ret = 0;
cleanup:
- free(mapstr);
- free(ranges);
+ VIR_FREE(mapstr);
+ VIR_FREE(ranges);
return (ret);
}
priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
if (!(sexpr = virDomainParseXMLDesc(domain->conn, xml, NULL, priv->xendConfigVersion))) {
- free(xml);
+ VIR_FREE(xml);
return (-1);
}
- free(xml);
+ VIR_FREE(xml);
ret = xenDaemonDomainCreateLinux(domain->conn, sexpr);
- free(sexpr);
+ VIR_FREE(sexpr);
if (ret != 0) {
return (-1);
}
int xenXMConfigSetInt(virConfPtr conf, const char *setting, long l) {
virConfValuePtr value = NULL;
- if (!(value = malloc(sizeof(*value))))
+ if (VIR_ALLOC(value) < 0)
return -1;
value->type = VIR_CONF_LONG;
int xenXMConfigSetString(virConfPtr conf, const char *setting, const char *str) {
virConfValuePtr value = NULL;
- if (!(value = malloc(sizeof(*value))))
+ if (VIR_ALLOC(value) < 0)
return -1;
value->type = VIR_CONF_STRING;
value->next = NULL;
if (!(value->str = strdup(str))) {
- free(value);
+ VIR_FREE(value);
return -1;
}
buflen += 2; /* mode */
- if (!(buf = malloc(buflen)))
+ if (VIR_ALLOC_N(buf, buflen) < 0)
goto cleanup;
if(source) {
if (ip)
buflen += 4 + strlen((const char*)ip);
- if (!(buf = malloc(buflen)))
+ if (VIR_ALLOC_N(buf, buflen) < 0)
goto cleanup;
strcpy(buf, "mac=");
}
cleanup:
- free(bridge);
+ VIR_FREE(bridge);
xmlFree(mac);
xmlFree(source);
xmlFree(script);
ranges = virConvertCpuSet(conn, cpus, 0);
if (ranges != NULL) {
- free(cpus);
+ VIR_FREE(cpus);
if (xenXMConfigSetString(conf, "cpus", ranges) < 0) {
- free(ranges);
+ VIR_FREE(ranges);
goto error;
}
- free(ranges);
+ VIR_FREE(ranges);
} else {
if (xenXMConfigSetString(conf, "cpus", cpus) < 0) {
- free(cpus);
+ VIR_FREE(cpus);
goto error;
}
- free(cpus);
+ VIR_FREE(cpus);
}
}
(obj->stringval != NULL) && STREQ((char*)obj->stringval, "hvm"))
hvm = 1;
xmlXPathFreeObject(obj);
+ obj = NULL;
priv = (xenUnifiedPrivatePtr) conn->privateData;
boot = "d";
}
xmlXPathFreeObject(obj);
+ obj = NULL;
if (xenXMConfigSetString(conf, "boot", boot) < 0)
goto error;
clockLocal = 1;
}
xmlXPathFreeObject(obj);
+ obj = NULL;
if (xenXMConfigSetInt(conf, "localtime", clockLocal) < 0)
goto error;
obj = xmlXPathEval(BAD_CAST "/domain/devices/graphics", ctxt);
if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) {
- if (!(vfb = malloc(sizeof(*vfb)))) {
+ if (VIR_ALLOC(vfb) < 0) {
xenXMError(conn, VIR_ERR_NO_MEMORY, _("config"));
goto error;
}
len += 11 + strlen((const char*)vncpasswd);
if (keymap)
len += 8 + strlen((const char*)keymap);
- if ((val = malloc(len)) != NULL) {
- strcpy(val, "type=vnc");
- if (vncunused) {
- strcat(val, ",vncunused=1");
- } else {
- char portstr[50];
- int port = atoi((const char*)vncport);
- snprintf(portstr, sizeof(portstr), "%d", port-5900);
- strcat(val, ",vncdisplay=");
- strcat(val, portstr);
- }
+ if (VIR_ALLOC_N(val, len) < 0) {
+ xmlFree(type);
xmlFree(vncport);
- if (vnclisten) {
- strcat(val, ",vnclisten=");
- strcat(val, (const char*)vnclisten);
- xmlFree(vnclisten);
- }
- if (vncpasswd) {
- strcat(val, ",vncpasswd=");
- strcat(val, (const char*)vncpasswd);
- xmlFree(vncpasswd);
- }
- if (keymap) {
- strcat(val, ",keymap=");
- strcat(val, (const char*)keymap);
- xmlFree(keymap);
- }
+ xmlFree(vnclisten);
+ xmlFree(vncpasswd);
+ xmlFree(keymap);
+ VIR_FREE(vfb);
+ xenXMError (conn, VIR_ERR_NO_MEMORY, strerror (errno));
+ goto error;
+ }
+ strcpy(val, "type=vnc");
+ if (vncunused) {
+ strcat(val, ",vncunused=1");
+ } else {
+ char portstr[50];
+ int port = atoi((const char*)vncport);
+ snprintf(portstr, sizeof(portstr), "%d", port-5900);
+ strcat(val, ",vncdisplay=");
+ strcat(val, portstr);
+ }
+ xmlFree(vncport);
+ if (vnclisten) {
+ strcat(val, ",vnclisten=");
+ strcat(val, (const char*)vnclisten);
+ xmlFree(vnclisten);
+ }
+ if (vncpasswd) {
+ strcat(val, ",vncpasswd=");
+ strcat(val, (const char*)vncpasswd);
+ xmlFree(vncpasswd);
+ }
+ if (keymap) {
+ strcat(val, ",keymap=");
+ strcat(val, (const char*)keymap);
+ xmlFree(keymap);
}
}
xmlFree(type);
if (val) {
virConfValuePtr disp;
- if (!(disp = malloc(sizeof(*disp)))) {
- free(val);
+ if (VIR_ALLOC(disp) < 0) {
+ VIR_FREE(val);
+ VIR_FREE(vfb);
xenXMError(conn, VIR_ERR_NO_MEMORY, _("config"));
goto error;
}
if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) {
virConfValuePtr disks;
- if (!(disks = malloc(sizeof(*disks)))) {
+ if (VIR_ALLOC(disks) < 0) {
xenXMError(conn, VIR_ERR_NO_MEMORY, _("config"));
goto error;
}
for (i = obj->nodesetval->nodeNr -1 ; i >= 0 ; i--) {
virConfValuePtr thisDisk;
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;
+ }
if (disk) {
- if (!(thisDisk = malloc(sizeof(*thisDisk)))) {
- free(disk);
+ if (VIR_ALLOC(thisDisk) < 0) {
+ VIR_FREE(disk);
+ virConfFreeValue(disks);
xenXMError(conn, VIR_ERR_NO_MEMORY, _("config"));
goto error;
}
if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) {
virConfValuePtr vifs;
- if (!(vifs = malloc(sizeof(*vifs)))) {
+ if (VIR_ALLOC(vifs) < 0) {
xenXMError(conn, VIR_ERR_NO_MEMORY, _("config"));
goto error;
}
for (i = obj->nodesetval->nodeNr - 1; i >= 0; i--) {
virConfValuePtr thisVif;
char *vif = xenXMParseXMLVif(conn, obj->nodesetval->nodeTab[i], hvm);
- if (!vif)
+ if (!vif) {
+ virConfFreeValue(vifs);
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"));
goto error;
}
if (!(soundstr = virBuildSoundStringFromXML(conn, ctxt)))
goto error;
if (xenXMConfigSetString(conf, "soundhw", soundstr) < 0) {
- free(soundstr);
+ VIR_FREE(soundstr);
goto error;
}
- free(soundstr);
+ VIR_FREE(soundstr);
}
}
goto error;
}
- if (!(entry = calloc(1, sizeof(*entry)))) {
+ if (VIR_ALLOC(entry) < 0) {
xenXMError(conn, VIR_ERR_NO_MEMORY, _("config"));
goto error;
}
return (ret);
error:
- free(entry);
+ VIR_FREE(entry);
if (conf)
virConfFree(conf);
return (NULL);
ret = 0;
cleanup:
- free(domxml);
+ VIR_FREE(domxml);
xmlXPathFreeObject(obj);
xmlXPathFreeContext(ctxt);
if (doc)
list_val = list_val->next;
}
} else if (!list_item) {
- if (!(list_item = calloc(1, sizeof(virConfValue))))
+ if (VIR_ALLOC(list_item) < 0)
goto cleanup;
list_item->type = VIR_CONF_LIST;
if(virConfSetValue(entry->conf, "disk", list_item)) {
- free(list_item);
+ VIR_FREE(list_item);
goto cleanup;
}
list_val = NULL;
if (!list_val) {
/* insert */
- if (!(list_val = malloc(sizeof(virConfValue))))
+ if (VIR_ALLOC(list_val) < 0)
goto cleanup;
list_val->type = VIR_CONF_STRING;
list_val->next = NULL;
prev->next = list_val;
} else {
/* configure */
- free(list_val->str);
+ VIR_FREE(list_val->str);
list_val->str = dev;
}
goto cleanup;
cleanup:
- free(type);
- free(source);
- free(target);
+ VIR_FREE(type);
+ VIR_FREE(source);
+ VIR_FREE(target);
return (ret);
}
if (virMacAddrCompare (dommac, (const char *) mac) == 0) {
if (autoassign) {
- free(mac);
+ VIR_FREE(mac);
mac = NULL;
if (!(mac = (xmlChar *)xenXMAutoAssignMac()))
goto cleanup;
list_val = list_val->next;
}
} else if (!list_item) {
- if (!(list_item = calloc(1, sizeof(virConfValue))))
+ if (VIR_ALLOC(list_item) < 0)
goto cleanup;
list_item->type = VIR_CONF_LIST;
if(virConfSetValue(entry->conf, "vif", list_item)) {
- free(list_item);
+ VIR_FREE(list_item);
goto cleanup;
}
list_val = NULL;
while (node_cur->next)
node_cur = node_cur->next;
- if (!(node_tmp = calloc(1, sizeof(xmlNode))))
+ if (VIR_ALLOC(node_tmp) < 0)
goto node_cleanup;
node_tmp->type = XML_ELEMENT_NODE;
- if (!(node_tmp->name = malloc(4)))
+ if (VIR_ALLOC_N(node_tmp->name, 4) < 0)
goto node_cleanup;
strcpy((char *)node_tmp->name, "mac");
node_tmp->children = NULL;
- if (!(attr_node = calloc(1, sizeof(xmlAttr))))
+ if (VIR_ALLOC(attr_node) < 0)
goto node_cleanup;
attr_node->type = XML_ATTRIBUTE_NODE;
attr_node->ns = NULL;
- if (!(attr_node->name = malloc(8)))
+ if (VIR_ALLOC_N(attr_node->name, 8) < 0)
goto node_cleanup;
strcpy((char *) attr_node->name, "address");
node_tmp->properties = attr_node;
- if (!(text_node = calloc(1, sizeof(xmlNode))))
+ if (VIR_ALLOC(text_node) < 0)
goto node_cleanup;
text_node->type = XML_TEXT_NODE;
text_node->_private = NULL;
- if (!(text_node->name = malloc(8)))
+ if (VIR_ALLOC_N(text_node->name, 5) < 0)
goto node_cleanup;
strcpy((char *) text_node->name, "text");
text_node->children = NULL;
if (!list_val) {
/* insert */
- if (!(list_val = malloc(sizeof(virConfValue))))
+ if (VIR_ALLOC(list_val) < 0)
goto cleanup;
list_val->type = VIR_CONF_STRING;
list_val->next = NULL;
prev->next = list_val;
} else {
/* configure */
- free(list_val->str);
+ VIR_FREE(list_val->str);
list_val->str = dev;
}
xmlFree(attr_node);
xmlFree(text_node);
cleanup:
- free(type);
- free(source);
- free(mac);
+ VIR_FREE(type);
+ VIR_FREE(source);
+ VIR_FREE(mac);
return (ret);
}
xenXMAutoAssignMac() {
char *buf;
- if (!(buf = malloc(18)))
+ if (VIR_ALLOC_N(buf, 18) < 0)
return 0;
srand((unsigned)time(NULL));
sprintf(buf, "00:16:3e:%02x:%02x:%02x"
else {
if (!prev) {
virConfValuePtr value;
- if (!(value = calloc(1, sizeof(virConfValue))))
+ if (VIR_ALLOC(value) < 0)
goto cleanup;
value->type = VIR_CONF_LIST;
value->list = list_val->next;
list_val->next = NULL;
if (virConfSetValue(entry->conf, device, value)) {
- free(value);
+ VIR_FREE(value);
goto cleanup;
}
} else
xmlXPathFreeContext(ctxt);
if (doc)
xmlFreeDoc(doc);
- free(domdevice);
- free(key);
- free(list_val);
+ VIR_FREE(domdevice);
+ VIR_FREE(key);
+ VIR_FREE(list_val);
return (ret);
}
#include "xml.h"
#include "buf.h"
#include "util.h"
+#include "memory.h"
#include "xs_internal.h" /* for xenStoreDomainGetNetworkID */
#include "xen_unified.h"
#include "xend_internal.h" /* for is_sound_* functions */
if (maxcpu <= 0)
maxcpu = 4096;
- cpuset = calloc(maxcpu, sizeof(*cpuset));
- if (cpuset == NULL) {
+ if (VIR_ALLOC_N(cpuset, maxcpu) < 0) {
virXMLError(conn, VIR_ERR_NO_MEMORY, _("allocate buffer"), 0);
return(NULL);
}
ret = virParseCpuSet(conn, &cur, 0, cpuset, maxcpu);
if (ret < 0) {
- free(cpuset);
+ VIR_FREE(cpuset);
return(NULL);
}
res = virSaveCpuSet(conn, cpuset, maxcpu);
- free(cpuset);
+ VIR_FREE(cpuset);
return (res);
}
char *sound;
xmlNodePtr *nodes = NULL;
- if (!(sound = calloc(1, size+1))) {
+ if (VIR_ALLOC_N(sound, size + 1) < 0) {
virXMLError(conn, VIR_ERR_NO_MEMORY,
_("failed to allocate sound string"), 0);
return NULL;
if (!is_sound_model_valid(model)) {
virXMLError(conn, VIR_ERR_XML_ERROR,
_("unknown sound model type"), 0);
- free(model);
+ VIR_FREE(model);
goto error;
}
if (*sound && (size >= (strlen(model) + 1))) {
strncat(sound, ",", size--);
} else if (*sound || size < strlen(model)) {
- free(model);
+ VIR_FREE(model);
continue;
}
strncat(sound, model, size);
size -= strlen(model);
}
- free(model);
+ VIR_FREE(model);
}
}
- free(nodes);
+ VIR_FREE(nodes);
return sound;
error:
- free(nodes);
+ VIR_FREE(nodes);
return NULL;
}
#endif /* !PROXY */
ret = obj->nodesetval->nodeNr;
if (list != NULL) {
- *list = malloc(ret * sizeof(**list));
- if (*list == NULL) {
+ if (VIR_ALLOC_N(*list, ret) < 0) {
virXMLError(NULL, VIR_ERR_NO_MEMORY,
_("allocate string array"),
ret * sizeof(**list));
+ ret = -1;
} else {
memcpy(*list, obj->nodesetval->nodeTab,
ret * sizeof(xmlNodePtr));
fdfile = xmlGetProp(cur, BAD_CAST "file");
if (fdfile != NULL) {
virBufferVSprintf(buf, "(fda '%s')", fdfile);
- free(fdfile);
+ VIR_FREE(fdfile);
}
}
fdfile = xmlGetProp(cur, BAD_CAST "file");
if (fdfile != NULL) {
virBufferVSprintf(buf, "(fdb '%s')", fdfile);
- free(fdfile);
+ VIR_FREE(fdfile);
}
}
}
xmlFree(bus);
}
- free(nodes);
+ VIR_FREE(nodes);
nodes = NULL;
}
if (!(soundstr = virBuildSoundStringFromXML(conn, ctxt)))
goto error;
virBufferVSprintf(buf, "(soundhw '%s')", soundstr);
- free(soundstr);
+ VIR_FREE(soundstr);
}
str = virXPathString("string(/domain/clock/@offset)", ctxt);
if (str != NULL && STREQ(str, "localtime")) {
virBufferAddLit(buf, "(localtime 1)");
}
- free(str);
+ VIR_FREE(str);
return (0);
error:
- free(nodes);
+ VIR_FREE(nodes);
return (-1);
}
}
virNetworkFree(network);
virBufferVSprintf(buf, "(bridge '%s')", bridge);
- free(bridge);
+ VIR_FREE(bridge);
}
}
if (script != NULL)
{
xmlDocPtr xml = NULL;
xmlNodePtr node;
- char *nam = NULL;
+ char *nam = NULL, *tmp;
virBuffer buf = VIR_BUFFER_INITIALIZER;
xmlChar *prop;
xmlParserCtxtPtr pctxt;
* it in a range format guaranteed to be understood by Xen.
*/
if (maxcpu > 0) {
- cpuset = malloc(maxcpu * sizeof(*cpuset));
- if (cpuset != NULL) {
- res = virParseCpuSet(conn, &cur, 0, cpuset, maxcpu);
- if (res > 0) {
- ranges = virSaveCpuSet(conn, cpuset, maxcpu);
- if (ranges != NULL) {
- virBufferVSprintf(&buf, "(cpus '%s')", ranges);
- free(ranges);
- }
- }
- free(cpuset);
- if (res < 0)
- goto error;
- } else {
+ if (VIR_ALLOC_N(cpuset, maxcpu) < 0) {
virXMLError(conn, VIR_ERR_NO_MEMORY, xmldesc, 0);
+ goto error;
+ }
+ res = virParseCpuSet(conn, &cur, 0, cpuset, maxcpu);
+ if (res > 0) {
+ ranges = virSaveCpuSet(conn, cpuset, maxcpu);
+ if (ranges != NULL) {
+ virBufferVSprintf(&buf, "(cpus '%s')", ranges);
+ VIR_FREE(ranges);
+ }
}
+ VIR_FREE(cpuset);
+ if (res < 0)
+ goto error;
}
- free(str);
+ VIR_FREE(str);
}
str = virXPathString("string(/domain/uuid[1])", ctxt);
if (str != NULL) {
virBufferVSprintf(&buf, "(uuid '%s')", str);
- free(str);
+ VIR_FREE(str);
}
str = virXPathString("string(/domain/bootloader[1])", ctxt);
* significant and should be discarded
*/
bootloader = 1;
- free(str);
+ VIR_FREE(str);
} else if (virXPathNumber("count(/domain/bootloader)", ctxt, &f) == 0
&& (f > 0)) {
virBufferAddLit(&buf, "(bootloader)");
* ignore the bootloader_args value unless a bootloader was specified
*/
virBufferVSprintf(&buf, "(bootloader_args '%s')", str);
- free(str);
+ VIR_FREE(str);
}
str = virXPathString("string(/domain/on_poweroff[1])", ctxt);
if (str != NULL) {
virBufferVSprintf(&buf, "(on_poweroff '%s')", str);
- free(str);
+ VIR_FREE(str);
}
str = virXPathString("string(/domain/on_reboot[1])", ctxt);
if (str != NULL) {
virBufferVSprintf(&buf, "(on_reboot '%s')", str);
- free(str);
+ VIR_FREE(str);
}
str = virXPathString("string(/domain/on_crash[1])", ctxt);
if (str != NULL) {
virBufferVSprintf(&buf, "(on_crash '%s')", str);
- free(str);
+ VIR_FREE(str);
}
if (!bootloader) {
res = virDomainParseXMLDiskDesc(conn, nodes[i], &buf,
hvm, xendConfigVersion);
if (res != 0) {
- free(nodes);
+ VIR_FREE(nodes);
goto error;
}
}
- free(nodes);
+ VIR_FREE(nodes);
}
nb_nodes = virXPathNodeSet("/domain/devices/interface", ctxt, &nodes);
virDomainParseXMLIfDesc(conn, nodes[i], &buf, hvm,
xendConfigVersion);
if (res != 0) {
- free(nodes);
+ VIR_FREE(nodes);
goto error;
}
virBufferAddLit(&buf, ")");
}
- free(nodes);
+ VIR_FREE(nodes);
}
/* New style PV graphics config xen >= 3.0.4,
for (i = 0; i < nb_nodes; i++) {
res = virDomainParseXMLGraphicsDescVFB(conn, nodes[i], &buf);
if (res != 0) {
- free(nodes);
+ VIR_FREE(nodes);
goto error;
}
}
- free(nodes);
+ VIR_FREE(nodes);
}
}
if (name != NULL)
*name = nam;
else
- free(nam);
+ VIR_FREE(nam);
if (virBufferError(&buf)) {
virXMLError(conn, VIR_ERR_NO_MEMORY, _("allocate buffer"), 0);
return virBufferContentAndReset(&buf);
error:
- free(nam);
+ VIR_FREE(nam);
if (name != NULL)
*name = NULL;
xmlXPathFreeContext(ctxt);
xmlFreeDoc(xml);
if (pctxt != NULL)
xmlFreeParserCtxt(pctxt);
- free(virBufferContentAndReset(&buf));
+ tmp = virBufferContentAndReset(&buf);
+ VIR_FREE(tmp);
return (NULL);
}
#include "testutils.h"
static char *progname;
-static char *abs_top_srcdir;
+static char *abs_srcdir;
#define MAX_FILE 4096
static int testFilterLine(char *buffer,
char *actualPtr = &(actualData[0]);
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)
return -1;
-int
-main(int argc, char **argv)
+static int
+mymain(int argc, char **argv)
{
int ret = 0;
char buffer[PATH_MAX];
+ char cwd[PATH_MAX];
- abs_top_srcdir = getenv("abs_top_srcdir");
- if (!abs_top_srcdir)
- return 1;
+ abs_srcdir = getenv("abs_srcdir");
+ if (!abs_srcdir)
+ 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';
progname = argv[0];
custom_uri = buffer;
if (argc > 1) {
fprintf(stderr, "Usage: %s\n", progname);
- exit(EXIT_FAILURE);
+ return(EXIT_FAILURE);
}
if (virtTestRun("virsh list (default)",
1, testCompareDomstateByName, NULL) != 0)
ret = -1;
- exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
+ return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
+
+VIRT_TEST_MAIN(mymain)