Devel
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
May 2008
- 32 participants
- 114 discussions
I had this problem and another user confirmed the same behavior on his machine:
http://pastie.caboo.se/65417
Haven't tried it with *2925.10* yet. Also, is there a way to get more verbose
info about what calls are causing the "configuration file syntax error" errors?
Thanks.
virt-install
How large would you like the disk () to be (in gigabytes)? 4
ERROR: Must provide a file, not a directory for the disk
What would you like to use as the disk (path)? /xen/images/x6.img
Would you like to enable graphics support? (yes or no) no
What is the install location?
http://mirror.anl.gov/pub/fedora-linux-core/test/6.93/Fedora/i386/os/
Starting install...
libvir: Xen Daemon error : GET operation failed:
libvir: error : configuration file syntax error: expecting a name
libvir: error : configuration file syntax error: expecting a name
libvir: error : configuration file syntax error: expecting a name
Retrieving Fedora... 276 kB 00:01
Retrieving vmlinuz... 100% |=========================| 2.1 MB 00:16
Retrieving initrd.img... 100% |=========================| 5.4 MB 00:28
libvir: Xen Daemon error : GET operation failed:
libvir: error : configuration file syntax error: expecting a name
libvir: error : configuration file syntax error: expecting a name
libvir: error : configuration file syntax error: expecting a name
Creating domain... 0 B 00:06
Linux version 2.6.20-2925.5.fc7xen (brewbuilder(a)ls20-bc1-14.build.redhat.com)
(gcc version 4.1.2 20070317 (Red Hat 4.1.2-5)) #1 SMP Thu Mar 22 13:51:38 EDT 2007
BIOS-provided physical RAM map:
sanitize start
sanitize bail 0
copy_e820_map() start: 0000000000000000 size: 0000000020800000 end:
0000000020800000 type: 1
Xen: 0000000000000000 - 0000000020800000 (usable)
0MB HIGHMEM available.
520MB LOWMEM available.
Using x86 segment limits to approximate NX protection
Zone PFN ranges:
DMA 0 -> 133120
Normal 133120 -> 133120
HighMem 133120 -> 133120
early_node_map[1] active PFN ranges
0: 0 -> 133120
ACPI in unprivileged domain disabled
Built 1 zonelists. Total pages: 132080
Kernel command line:
method=http://mirror.anl.gov/pub/fedora-linux-core/test/6.93/Fedora/i386/os/
Enabling fast FPU save and restore... done.
Enabling unmasked SIMD FPU exception support... done.
Initializing CPU#0
CPU 0 irqstacks, hard=c135f000 soft=c133f000
PID hash table entries: 4096 (order: 12, 16384 bytes)
Xen reported: 1694.994 MHz processor.
Console: colour dummy device 80x25
Lock dependency validator: Copyright (c) 2006 Red Hat, Inc., Ingo Molnar
... MAX_LOCKDEP_SUBCLASSES: 8
... MAX_LOCK_DEPTH: 30
... MAX_LOCKDEP_KEYS: 2048
... CLASSHASH_SIZE: 1024
... MAX_LOCKDEP_ENTRIES: 8192
... MAX_LOCKDEP_CHAINS: 16384
... CHAINHASH_SIZE: 8192
memory used by lock dependency info: 1064 kB
per task-struct memory footprint: 1200 bytes
Dentry cache hash table entries: 131072 (order: 7, 524288 bytes)
Inode-cache hash table entries: 65536 (order: 6, 262144 bytes)
Software IO TLB disabled
vmalloc area: e1000000-f4ffe000, maxmem 2d7fe000
Memory: 503936k/532480k available (2030k kernel code, 19948k reserved, 1079k
data, 180k init, 0k highmem)
virtual kernel memory layout:
fixmap : 0xf5315000 - 0xf57fe000 (5028 kB)
pkmap : 0xf5000000 - 0xf5200000 (2048 kB)
vmalloc : 0xe1000000 - 0xf4ffe000 ( 319 MB)
lowmem : 0xc0000000 - 0xe0800000 ( 520 MB)
.init : 0xc130e000 - 0xc133b000 ( 180 kB)
.data : 0xc11fb9d9 - 0xc1309714 (1079 kB)
.text : 0xc1000000 - 0xc11fb9d9 (2030 kB)
Checking if this processor honours the WP bit even in supervisor mode... Ok.
Calibrating delay using timer specific routine.. 4262.67 BogoMIPS (lpj=8525343)
Security Framework v1.0.0 initialized
SELinux: Initializing.
SELinux: Starting in permissive mode
selinux_register_security: Registering secondary module capability
Capability LSM initialized as secondary
Mount-cache hash table entries: 512
CPU: Trace cache: 12K uops, L1 D cache: 8K
CPU: L2 cache: 256K
Checking 'hlt' instruction... OK.
SMP alternatives: switching to UP code
Freeing SMP alternatives: 11k freed
Brought up 1 CPUs
Grant table initialized
NET: Registered protocol family 16
Brought up 1 CPUs
PCI: Fatal: No config space access function found
PCI: setting up Xen PCI frontend stub
Setting up standard PCI resources
ACPI: Interpreter disabled.
Linux Plug and Play Support v0.97 (c) Adam Belay
pnp: PnP ACPI: disabled
xen_mem: Initialising balloon driver.
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
PCI: System does not support PCI
PCI: System does not support PCI
NetLabel: Initializing
NetLabel: domain hash size = 128
NetLabel: protocols = UNLABELED CIPSOv4
NetLabel: unlabeled traffic allowed by default
NET: Registered protocol family 2
IP route cache hash table entries: 32768 (order: 5, 131072 bytes)
TCP established hash table entries: 131072 (order: 10, 4194304 bytes)
TCP bind hash table entries: 65536 (order: 9, 2097152 bytes)
TCP: Hash tables configured (established 131072 bind 65536)
TCP reno registered
checking if image is initramfs... it is
Freeing initrd memory: 7256k freed
IA-32 Microcode Update Driver: v1.14-xen <tigran(a)veritas.com>
audit: initializing netlink socket (disabled)
audit(1180379657.981:1): initialized
VFS: Disk quotas dquot_6.5.1
Dquot-cache hash table entries: 1024 (order 0, 4096 bytes)
SELinux: Registering netfilter hooks
io scheduler noop registered
io scheduler anticipatory registered
io scheduler deadline registered
io scheduler cfq registered (default)
pci_hotplug: PCI Hot Plug PCI Core version: 0.5
BUG: at kernel/fork.c:994 copy_process()
[<c1005d9a>] show_trace_log_lvl+0x1a/0x2f
[<c1006343>] show_trace+0x12/0x14
[<c10063be>] dump_stack+0x16/0x18
[<c101d044>] copy_process+0x195/0x1245
[<c101e144>] do_fork+0x50/0x117
[<c1003351>] kernel_thread+0x8e/0x96
[<c102c701>] __call_usermodehelper+0x2d/0x46
[<c102cd4f>] run_workqueue+0x89/0x145
[<c102d711>] worker_thread+0xd5/0x102
[<c102ff27>] kthread+0xb3/0xdc
[<c10058db>] kernel_thread_helper+0x7/0x10
=======================
rtc: IRQ 8 is not free.
Non-volatile memory driver v1.2
Linux agpgart interface v0.101 (c) Dave Jones
RAMDISK driver initialized: 16 RAM disks of 16384K size 4096 blocksize
input: Macintosh mouse button emulation as /class/input/input0
Xen virtual console successfully installed as xvc0
Event-channel device installed.
usbcore: registered new interface driver libusual
usbcore: registered new interface driver hiddev
usbcore: registered new interface driver usbhid
drivers/usb/input/hid-core.c: v2.6:USB HID core driver
PNP: No PS/2 controller found. Probing ports directly.
i8042.c: No controller found.
mice: PS/2 mouse device common for all mice
TCP bic registered
Initializing XFRM netlink socket
NET: Registered protocol family 1
NET: Registered protocol family 17
Using IPI No-Shortcut mode
XENBUS: Device with no driver: device/vbd/51712
XENBUS: Device with no driver: device/vif/0
Freeing unused kernel memory: 180k freed
Write protecting the kernel read-only data: 762k
^[Domain installation still in progress. You can reconnect
2
1
Hi!
I'd like to propose that the following patch gets applied against
libvirt. It adds the option of putting a bus attribute on a disk target.
To acommodate this, it also changes the way drives are defined for kvm
from the old "-hda /path/to/file -boot c" style to the new "-drive
file=/path/to/file,if=ide,boot=on". This makes it possible to specify
virtio, scsi, and ide disks.
=== modified file 'src/qemu_conf.c'
--- src/qemu_conf.c 2008-04-28 15:14:59 +0000
+++ src/qemu_conf.c 2008-04-29 07:43:11 +0000
@@ -568,6 +568,7 @@
xmlChar *source = NULL;
xmlChar *target = NULL;
xmlChar *type = NULL;
+ xmlChar *bus = NULL;
int typ = 0;
type = xmlGetProp(node, BAD_CAST "type");
@@ -598,6 +599,7 @@
} else if ((target == NULL) &&
(xmlStrEqual(cur->name, BAD_CAST "target"))) {
target = xmlGetProp(cur, BAD_CAST "dev");
+ bus = xmlGetProp(cur, BAD_CAST "bus");
} else if (xmlStrEqual(cur->name, BAD_CAST "readonly")) {
disk->readonly = 1;
}
@@ -646,7 +648,9 @@
strcmp((const char *)target, "hda") &&
strcmp((const char *)target, "hdb") &&
strcmp((const char *)target, "hdc") &&
- strcmp((const char *)target, "hdd")) {
+ strcmp((const char *)target, "hdd") &&
+ strcmp((const char *)target, "hdd") &&
+ strncmp((const char *)target, "vd", 2)) {
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
_("Invalid harddisk device name: %s"), target);
goto error;
@@ -673,6 +677,20 @@
goto error;
}
+ if (!bus)
+ disk->bus = QEMUD_DISK_BUS_IDE;
+ else if (!strcmp((const char *)bus, "ide"))
+ disk->bus = QEMUD_DISK_BUS_IDE;
+ else if (!strcmp((const char *)bus, "scsi"))
+ disk->bus = QEMUD_DISK_BUS_SCSI;
+ else if (!strcmp((const char *)bus, "virtio"))
+ disk->bus = QEMUD_DISK_BUS_VIRTIO;
+ else {
+ qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, "Invalid bus type: %s", bus);
+ goto error;
+ }
+
+ xmlFree(bus);
xmlFree(device);
xmlFree(target);
xmlFree(source);
@@ -688,6 +706,8 @@
xmlFree(source);
if (device)
xmlFree(device);
+ if (bus)
+ xmlFree(bus);
return -1;
}
@@ -1350,6 +1370,68 @@
return -1;
}
+static int qemudDiskCompare(const void *aptr, const void *bptr) {
+ struct qemud_vm_disk_def *a = (struct qemud_vm_disk_def *) aptr;
+ struct qemud_vm_disk_def *b = (struct qemud_vm_disk_def *) bptr;
+ if (a->device == b->device)
+ return virDiskNameToIndex(a->dst) - virDiskNameToIndex(b->dst);
+ else
+ return a->device - b->device;
+}
+
+static const char *qemudBusIdToName(int busId) {
+ const char *busnames[] = { "ide",
+ "scsi",
+ "virtio" };
+
+ if (busId >= 0 && busId < 3)
+ return busnames[busId];
+ else
+ return 0;
+}
+
+static char *qemudDriveOpt(struct qemud_vm_disk_def *disk, int boot)
+{
+ char opt[PATH_MAX];
+
+ switch (disk->device) {
+ case QEMUD_DISK_CDROM:
+ snprintf(opt, PATH_MAX, "file=%s,if=ide,media=cdrom%s",
+ disk->src, boot ? ",boot=on" : "");
+ break;
+ case QEMUD_DISK_FLOPPY:
+ snprintf(opt, PATH_MAX, "file=%s,if=floppy%s",
+ disk->src, boot ? ",boot=on" : "");
+ break;
+ case QEMUD_DISK_DISK:
+ snprintf(opt, PATH_MAX, "file=%s,if=%s%s",
+ disk->src, qemudBusIdToName(disk->bus), boot ? ",boot=on" : "");
+ break;
+ default:
+ return 0;
+ }
+ return strdup(opt);
+}
+
+static char *qemudAddBootDrive(virConnectPtr conn,
+ struct qemud_vm_def *def,
+ char *handledDisks,
+ int type) {
+ int j = 0;
+ struct qemud_vm_disk_def *disk = def->disks;
+
+ while (disk) {
+ if (!handledDisks[j] && disk->device == type) {
+ handledDisks[j] = 1;
+ return qemudDriveOpt(disk, 1);
+ }
+ j++;
+ disk = disk->next;
+ }
+ qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
+ "Requested boot device type %d, but no such device defined.", type);
+ return 0;
+}
/*
* Parses a libvirt XML definition of a guest, and populates the
@@ -1739,7 +1821,6 @@
obj = xmlXPathEval(BAD_CAST "/domain/devices/disk", ctxt);
if ((obj != NULL) && (obj->type == XPATH_NODESET) &&
(obj->nodesetval != NULL) && (obj->nodesetval->nodeNr >= 0)) {
- struct qemud_vm_disk_def *prev = NULL;
for (i = 0; i < obj->nodesetval->nodeNr; i++) {
struct qemud_vm_disk_def *disk = calloc(1, sizeof(*disk));
if (!disk) {
@@ -1752,13 +1833,20 @@
goto error;
}
def->ndisks++;
- disk->next = NULL;
if (i == 0) {
+ disk->next = NULL;
def->disks = disk;
} else {
- prev->next = disk;
+ struct qemud_vm_disk_def *ptr = def->disks;
+ while (ptr) {
+ if (!ptr->next || qemudDiskCompare(ptr->next, disk) < 0) {
+ disk->next = ptr->next;
+ ptr->next = disk;
+ break;
+ }
+ ptr = ptr->next;
+ }
}
- prev = disk;
}
}
xmlXPathFreeObject(obj);
@@ -2207,30 +2295,32 @@
goto no_memory;
}
- for (i = 0 ; i < vm->def->os.nBootDevs ; i++) {
- switch (vm->def->os.bootDevs[i]) {
- case QEMUD_BOOT_CDROM:
- boot[i] = 'd';
- break;
- case QEMUD_BOOT_FLOPPY:
- boot[i] = 'a';
- break;
- case QEMUD_BOOT_DISK:
- boot[i] = 'c';
- break;
- case QEMUD_BOOT_NET:
- boot[i] = 'n';
- break;
- default:
- boot[i] = 'c';
- break;
+ if (vm->def->virtType != QEMUD_VIRT_KVM) {
+ for (i = 0 ; i < vm->def->os.nBootDevs ; i++) {
+ switch (vm->def->os.bootDevs[i]) {
+ case QEMUD_BOOT_CDROM:
+ boot[i] = 'd';
+ break;
+ case QEMUD_BOOT_FLOPPY:
+ boot[i] = 'a';
+ break;
+ case QEMUD_BOOT_DISK:
+ boot[i] = 'c';
+ break;
+ case QEMUD_BOOT_NET:
+ boot[i] = 'n';
+ break;
+ default:
+ boot[i] = 'c';
+ break;
+ }
}
+ boot[vm->def->os.nBootDevs] = '\0';
+ if (!((*argv)[++n] = strdup("-boot")))
+ goto no_memory;
+ if (!((*argv)[++n] = strdup(boot)))
+ goto no_memory;
}
- boot[vm->def->os.nBootDevs] = '\0';
- if (!((*argv)[++n] = strdup("-boot")))
- goto no_memory;
- if (!((*argv)[++n] = strdup(boot)))
- goto no_memory;
if (vm->def->os.kernel[0]) {
if (!((*argv)[++n] = strdup("-kernel")))
@@ -2251,28 +2341,74 @@
goto no_memory;
}
- while (disk) {
- char dev[NAME_MAX];
- char file[PATH_MAX];
- if (!strcmp(disk->dst, "hdc") &&
- disk->device == QEMUD_DISK_CDROM) {
- if (disk->src[0])
- snprintf(dev, NAME_MAX, "-%s", "cdrom");
- else {
- /* Don't put anything on the cmdline for an empty cdrom*/
- disk = disk->next;
- continue;
- }
- } else
- snprintf(dev, NAME_MAX, "-%s", disk->dst);
- snprintf(file, PATH_MAX, "%s", disk->src);
-
- if (!((*argv)[++n] = strdup(dev)))
- goto no_memory;
- if (!((*argv)[++n] = strdup(file)))
- goto no_memory;
-
- disk = disk->next;
+ if (vm->def->virtType == QEMUD_VIRT_KVM) {
+ char *handledDisks = NULL;
+ int j;
+
+ handledDisks = calloc(sizeof(*handledDisks), vm->def->ndisks);
+
+ if (!handledDisks)
+ goto no_memory;
+
+ /* When using -drive notation, we need to provide the devices in boot
+ * preference order. */
+ for (i = 0 ; i < vm->def->os.nBootDevs ; i++) {
+ if (!((*argv)[++n] = strdup("-drive")))
+ goto no_memory;
+
+ switch (vm->def->os.bootDevs[i]) {
+ case QEMUD_BOOT_CDROM:
+ if (!((*argv)[++n] = qemudAddBootDrive(conn, vm->def, handledDisks, QEMUD_DISK_CDROM)))
+ goto error;
+ break;
+ case QEMUD_BOOT_FLOPPY:
+ if (!((*argv)[++n] = qemudAddBootDrive(conn, vm->def, handledDisks, QEMUD_DISK_FLOPPY)))
+ goto error;
+ break;
+ case QEMUD_BOOT_DISK:
+ if (!((*argv)[++n] = qemudAddBootDrive(conn, vm->def, handledDisks, QEMUD_DISK_DISK)))
+ goto error;
+ break;
+ }
+ }
+
+ /* Pick up the rest of the devices */
+ j=0;
+ while (disk) {
+ if (!handledDisks[j]) {
+ handledDisks[j] = 1;
+ if (!((*argv)[++n] = strdup("-drive")))
+ goto no_memory;
+ if (!((*argv)[++n] = qemudDriveOpt(disk, 0)))
+ goto no_memory;
+ }
+ disk = disk->next;
+ j++;
+ }
+ } else {
+ while (disk) {
+ char dev[NAME_MAX];
+ char file[PATH_MAX];
+
+ if (!strcmp(disk->dst, "hdc") &&
+ disk->device == QEMUD_DISK_CDROM)
+ if (disk->src[0])
+ snprintf(dev, NAME_MAX, "-%s", "cdrom");
+ else {
+ disk = disk->next;
+ continue;
+ }
+ else
+ snprintf(dev, NAME_MAX, "-%s", disk->dst);
+ snprintf(file, PATH_MAX, "%s", disk->src);
+
+ if (!((*argv)[++n] = strdup(dev)))
+ goto no_memory;
+ if (!((*argv)[++n] = strdup(file)))
+ goto no_memory;
+
+ disk = disk->next;
+ }
}
if (!net) {
@@ -3565,6 +3701,7 @@
virBufferVSprintf(&buf, " <source %s='%s'/>\n",
typeAttrs[disk->type], disk->src);
+ virBufferVSprintf(&buf, " <target dev='%s' bus='%s'/>\n", disk->dst, qemudBusIdToName(disk->bus));
virBufferVSprintf(&buf, " <target dev='%s'/>\n", disk->dst);
if (disk->readonly)
=== modified file 'src/qemu_conf.h'
--- src/qemu_conf.h 2008-04-25 20:46:13 +0000
+++ src/qemu_conf.h 2008-04-29 07:13:16 +0000
@@ -56,10 +56,17 @@
QEMUD_DISK_FLOPPY,
};
+enum qemud_vm_disk_bus {
+ QEMUD_DISK_BUS_IDE,
+ QEMUD_DISK_BUS_SCSI,
+ QEMUD_DISK_BUS_VIRTIO
+};
+
/* Stores the virtual disk configuration */
struct qemud_vm_disk_def {
int type;
int device;
+ int bus;
char src[PATH_MAX];
char dst[NAME_MAX];
int readonly;
=== modified file 'src/util.c'
--- src/util.c 2008-04-25 14:53:05 +0000
+++ src/util.c 2008-04-29 06:59:49 +0000
@@ -771,3 +771,43 @@
return -1;
}
+
+/* Translates a device name of the form (regex) "[fhv]d[a-z]+" into
+ * the corresponding index (e.g. sda => 1, hdz => 26, vdaa => 27)
+ * @param name The name of the device
+ * @return name's index, or 0 on failure
+ */
+int virDiskNameToIndex(const char *name) {
+ const char *ptr = NULL;
+ int idx = 0;
+
+ if (strlen(name) < 3)
+ return 0;
+
+ switch (*name) {
+ case 'f':
+ case 'h':
+ case 'v':
+ break;
+ default:
+ return 0;
+ }
+
+ if (*(name + 1) != 'd')
+ return 0;
+
+ ptr = name+2;
+
+ while (*ptr) {
+ idx = idx * 26;
+
+ if ('a' > *ptr || 'z' < *ptr)
+ return 0;
+
+ idx += *ptr - 'a' + 1;
+ ptr++;
+ }
+
+ return idx;
+}
+
=== modified file 'src/util.h'
--- src/util.h 2008-04-25 14:53:05 +0000
+++ src/util.h 2008-04-29 06:59:57 +0000
@@ -92,4 +92,6 @@
int virParseMacAddr(const char* str, unsigned char *addr);
+int virDiskNameToIndex(const char* str);
+
#endif /* __VIR_UTIL_H__ */
--
Soren Hansen |
Virtualisation specialist | Ubuntu Server Team
Canonical Ltd. | http://www.ubuntu.com/
6
17
Brecht Sanders wrote:
> Hi,
> I saw on the following link:
> http://www.mail-archive.com/libvir-list@redhat.com/msg04103.html
> that you are also trying to compile libvirt on win32.
> I'm also attempting to do this, and I guess I got stuck at the same
> point your post was about.
> Have you in the mean time found an XDR implementation that compiles on
> MinGW and that implements xdr_u_quad_t?
> If you did, can you please tell me where to find it?
You'll find the answer to this question and more if you look through the
libvir-list archives for the current month:
https://www.redhat.com/archives/libvir-list/2008-January/thread.html
Rich.
--
Emerging Technologies, Red Hat - http://et.redhat.com/~rjones/
Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod
Street, Windsor, Berkshire, SL4 1TE, United Kingdom. Registered in
England and Wales under Company Registration No. 03798903
3
12
[Libvir] [PATCH] Fix USB device name mis-conversion from S-Expr to XML
by Hiroyuki Kaguchi 23 Jun '08
by Hiroyuki Kaguchi 23 Jun '08
23 Jun '08
"tablet" and "mouse" are set as a value of the
/local/domain/<domid>/image/hvm/usbdevice,
but libvirt expects "usbdevice" and "usbmouse" as a value.
This causes the following.
If a USB device is attached by virt-manager,
the USB device is not seen from virt-manager.
This patch fixes expected value of libvirt
Thanks,
Hiroyuki Kaguchi
Index: xend_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/xend_internal.c,v
retrieving revision 1.162
diff -u -r1.162 xend_internal.c
--- xend_internal.c 21 Jan 2008 16:29:10 -0000 1.162
+++ xend_internal.c 23 Jan 2008 00:37:02 -0000
@@ -1743,11 +1743,9 @@
node = cur->u.s.car;
if (sexpr_lookup(node, "usbdevice")) {
tmp = sexpr_node(node, "usbdevice");
- if (tmp && *tmp) {
- if (!strcmp(tmp, "usbtablet"))
- virBufferAdd(&buf, " <input type='tablet'
bus='usb'/>\n", 37);
- else if (!strcmp(tmp, "usbmouse"))
- virBufferAdd(&buf, " <input type='mouse'
bus='usb'/>\n", 36);
+ if (!strcmp(tmp, "tablet") ||
+ !strcmp(tmp, "mouse")) {
+ virBufferVSprintf(&buf, " <input type='%s'
bus='usb'/>\n", tmp);
}
}
}
3
4
09 Jun '08
Virt-df[1] has now gained the ability to fully parse LVM2 partitions,
thus:
# virt-df -c qemu:///system -h
Filesystem Size Used Available Type
rhel51x32kvm:hda1 96.8 MiB 14.6 MiB 82.2 MiB Linux ext2/3
rhel51x32kvm:VolGroup00/LogVol00 6.4 GiB 3.6 GiB 2.8 GiB Linux ext2/3
rhel51x32kvm:VolGroup00/LogVol01 992.0 MiB Linux swap
However it still has to do it by opening the local partitions / files,
which means it isn't using a "proper" part of libvirt and more
importantly it cannot run remotely.
I'd like to find out whether the time has come for us to look again at
a virDomainBlockPeek call for libvirt. Here is the original thread
plus patch from 7 months ago:
http://www.redhat.com/archives/libvir-list/2007-October/thread.html#00089
(I've attached an updated patch against current CVS).
I appreciate that some cases might not be simple (iSCSI?), but the
same argument applies to block device statistics too, and we make
those available where possible. I think a best-effort call allowing
callers to peek into the block devices of guests would be very useful.
Rich.
[1] http://hg.et.redhat.com/applications/virt/applications/virt-df--devel
--
Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones
virt-top is 'top' for virtual machines. Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://et.redhat.com/~rjones/virt-top
4
10
06 Jun '08
This patch switches all remaining code over to use the memory allocation
APIs, with exception of virsh which is going to be slightly more complex
It was mostly a straight conversion - there were only a few places which
weren't checking for failure corecttly - the most notable being sexpr.c.
bridge.c | 18 +++----
conf.c | 51 ++++++++++----------
iptables.c | 60 ++++++++++--------------
lxc_conf.c | 45 ++++++++----------
lxc_container.c | 5 +-
lxc_driver.c | 25 ++++------
openvz_conf.c | 49 ++++++++-----------
openvz_driver.c | 3 -
proxy_internal.c | 8 +--
remote_internal.c | 85 +++++++++++++++-------------------
sexpr.c | 31 ++++++++----
storage_backend.c | 32 ++++++------
storage_backend_disk.c | 24 ++++-----
storage_backend_fs.c | 56 ++++++++++------------
storage_backend_iscsi.c | 30 +++++-------
storage_backend_logical.c | 20 +++-----
storage_conf.c | 114 +++++++++++++++++++++++-----------------------
storage_driver.c | 5 --
xen_internal.c | 38 +++++++--------
xen_unified.c | 23 ++++-----
xend_internal.c | 1
xmlrpc.c | 67 +++++++++++++--------------
22 files changed, 379 insertions(+), 411 deletions(-)
Regards,
Daniel.
diff -r ff6b92c70738 src/bridge.c
--- a/src/bridge.c Fri May 30 10:36:42 2008 -0400
+++ b/src/bridge.c Fri May 30 10:55:44 2008 -0400
@@ -45,6 +45,7 @@
#include <net/if_arp.h> /* ARPHRD_ETHER */
#include "internal.h"
+#include "memory.h"
#define MAX_BRIDGE_ID 256
@@ -84,8 +85,7 @@
return err;
}
- *ctlp = malloc(sizeof(**ctlp));
- if (!*ctlp) {
+ if (VIR_ALLOC(*ctlp) < 0) {
close(fd);
return ENOMEM;
}
@@ -110,7 +110,7 @@
close(ctl->fd);
ctl->fd = 0;
- free(ctl);
+ VIR_FREE(ctl);
}
/**
@@ -681,7 +681,7 @@
snprintf(delayStr, sizeof(delayStr), "%d", delay);
- if (!(argv = calloc(n + 1, sizeof(*argv))))
+ if (VIR_ALLOC_N(argv, n + 1) < 0)
goto error;
n = 0;
@@ -706,8 +706,8 @@
if (argv) {
n = 0;
while (argv[n])
- free(argv[n++]);
- free(argv);
+ VIR_FREE(argv[n++]);
+ VIR_FREE(argv);
}
return retval;
@@ -738,7 +738,7 @@
1 + /* brige name */
1; /* value */
- if (!(argv = calloc(n + 1, sizeof(*argv))))
+ if (VIR_ALLOC_N(argv, n + 1) < 0)
goto error;
n = 0;
@@ -763,8 +763,8 @@
if (argv) {
n = 0;
while (argv[n])
- free(argv[n++]);
- free(argv);
+ VIR_FREE(argv[n++]);
+ VIR_FREE(argv);
}
return retval;
diff -r ff6b92c70738 src/conf.c
--- a/src/conf.c Fri May 30 10:36:42 2008 -0400
+++ b/src/conf.c Fri May 30 10:55:44 2008 -0400
@@ -23,6 +23,7 @@
#include "conf.h"
#include "util.h"
#include "c-ctype.h"
+#include "memory.h"
/************************************************************************
* *
@@ -138,11 +139,11 @@
return;
if (val->type == VIR_CONF_STRING &&
val->str != NULL)
- free(val->str);
+ VIR_FREE(val->str);
if (val->type == VIR_CONF_LIST &&
val->list != NULL)
virConfFreeList(val->list);
- free(val);
+ VIR_FREE(val);
}
virConfPtr
@@ -150,8 +151,7 @@
{
virConfPtr ret;
- ret = calloc(1, sizeof(*ret));
- if (ret == NULL) {
+ if (VIR_ALLOC(ret) < 0) {
virConfError(NULL, VIR_ERR_NO_MEMORY, _("allocating configuration"), 0);
return(NULL);
}
@@ -199,8 +199,7 @@
if ((comm == NULL) && (name == NULL))
return(NULL);
- ret = calloc(1, sizeof(*ret));
- if (ret == NULL) {
+ if (VIR_ALLOC(ret) < 0) {
virConfError(NULL, VIR_ERR_NO_MEMORY, _("allocating configuration"), 0);
return(NULL);
}
@@ -441,7 +440,8 @@
NEXT;
SKIP_BLANKS_AND_EOL;
if ((ctxt->cur < ctxt->end) && (CUR != ']')) {
- lst = virConfParseValue(ctxt);
+ if ((lst = virConfParseValue(ctxt)) == NULL)
+ return(NULL);
SKIP_BLANKS_AND_EOL;
}
while ((ctxt->cur < ctxt->end) && (CUR != ']')) {
@@ -484,10 +484,10 @@
ctxt->line);
return(NULL);
}
- ret = calloc(1, sizeof(*ret));
- if (ret == NULL) {
+ if (VIR_ALLOC(ret) < 0) {
virConfError(NULL, VIR_ERR_NO_MEMORY, _("allocating configuration"), 0);
- free(str);
+ virConfFreeList(lst);
+ VIR_FREE(str);
return(NULL);
}
ret->type = type;
@@ -618,7 +618,7 @@
SKIP_BLANKS;
value = virConfParseValue(ctxt);
if (value == NULL) {
- free(name);
+ VIR_FREE(name);
return(-1);
}
SKIP_BLANKS;
@@ -630,15 +630,15 @@
if (comm == NULL) {
virConfError(NULL, VIR_ERR_NO_MEMORY, _("allocating configuration"),
ctxt->line);
- free(name);
+ VIR_FREE(name);
virConfFreeValue(value);
return(-1);
}
}
if (virConfAddEntry(ctxt->conf, name, value, comm) == NULL) {
- free(name);
+ VIR_FREE(name);
virConfFreeValue(value);
- free(comm);
+ VIR_FREE(comm);
return(-1);
}
return(0);
@@ -720,7 +720,7 @@
conf = virConfParse(filename, content, len);
- free(content);
+ VIR_FREE(content);
return conf;
}
@@ -769,14 +769,14 @@
tmp = conf->entries;
while (tmp) {
virConfEntryPtr next;
- free(tmp->name);
+ VIR_FREE(tmp->name);
virConfFreeValue(tmp->value);
- free(tmp->comment);
+ VIR_FREE(tmp->comment);
next = tmp->next;
- free(tmp);
+ VIR_FREE(tmp);
tmp = next;
}
- free(conf);
+ VIR_FREE(conf);
return(0);
}
@@ -834,14 +834,14 @@
}
if (!cur) {
- if (!(cur = malloc(sizeof(*cur)))) {
+ if (VIR_ALLOC(cur) < 0) {
virConfFreeValue(value);
return (-1);
}
cur->comment = NULL;
if (!(cur->name = strdup(setting))) {
virConfFreeValue(value);
- free(cur);
+ VIR_FREE(cur);
return (-1);
}
cur->value = value;
@@ -897,15 +897,16 @@
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR );
if (fd < 0) {
+ char *tmp = virBufferContentAndReset(&buf);
virConfError(NULL, VIR_ERR_WRITE_FAILED, _("failed to open file"), 0);
- free(virBufferContentAndReset(&buf));
+ VIR_FREE(tmp);
return -1;
}
use = virBufferUse(&buf);
content = virBufferContentAndReset(&buf);
ret = safewrite(fd, content, use);
- free(content);
+ VIR_FREE(content);
close(fd);
if (ret != (int)use) {
virConfError(NULL, VIR_ERR_WRITE_FAILED, _("failed to save content"), 0);
@@ -955,11 +956,11 @@
if ((int)use >= *len) {
*len = (int)use;
- free(content);
+ VIR_FREE(content);
return -1;
}
memcpy(memory, content, use);
- free(content);
+ VIR_FREE(content);
*len = use;
return use;
}
diff -r ff6b92c70738 src/iptables.c
--- a/src/iptables.c Fri May 30 10:36:42 2008 -0400
+++ b/src/iptables.c Fri May 30 10:55:44 2008 -0400
@@ -45,6 +45,7 @@
#include "internal.h"
#include "iptables.h"
#include "util.h"
+#include "memory.h"
#define qemudLog(level, msg...) fprintf(stderr, msg)
@@ -156,7 +157,7 @@
snprintf(arg, sizeof(arg), "--custom-rules=ipv4:%s:%s", table, path);
if (!stripLine(content, len, arg)) {
- free(content);
+ VIR_FREE(content);
return;
}
@@ -171,7 +172,7 @@
goto write_error;
}
- free(content);
+ VIR_FREE(content);
return;
@@ -181,7 +182,7 @@
strerror(errno));
if (f)
fclose(f);
- free(content);
+ VIR_FREE(content);
#undef MAX_FILE_LEN
}
@@ -264,14 +265,14 @@
static void
iptRuleFree(iptRule *rule)
{
- free(rule->rule);
+ VIR_FREE(rule->rule);
rule->rule = NULL;
if (rule->argv) {
int i = 0;
while (rule->argv[i])
- free(rule->argv[i++]);
- free(rule->argv);
+ VIR_FREE(rule->argv[i++]);
+ VIR_FREE(rule->argv);
rule->argv = NULL;
}
}
@@ -282,17 +283,13 @@
char **argv,
int command_idx)
{
- iptRule *r;
-
- if (!(r = realloc(rules->rules, sizeof(*r) * (rules->nrules+1)))) {
+ if (VIR_REALLOC_N(rules->rules, rules->nrules+1) < 0) {
int i = 0;
while (argv[i])
- free(argv[i++]);
- free(argv);
+ VIR_FREE(argv[i++]);
+ VIR_FREE(argv);
return ENOMEM;
}
-
- rules->rules = r;
rules->rules[rules->nrules].rule = rule;
rules->rules[rules->nrules].argv = argv;
@@ -332,23 +329,17 @@
{
int i;
- if (rules->table) {
- free(rules->table);
- rules->table = NULL;
- }
+ if (rules->table)
+ VIR_FREE(rules->table);
- if (rules->chain) {
- free(rules->chain);
- rules->chain = NULL;
- }
-
+ if (rules->chain)
+ VIR_FREE(rules->chain);
if (rules->rules) {
for (i = 0; i < rules->nrules; i++)
iptRuleFree(&rules->rules[i]);
- free(rules->rules);
- rules->rules = NULL;
+ VIR_FREE(rules->rules);
rules->nrules = 0;
}
@@ -358,7 +349,7 @@
rules->path[0] = '\0';
#endif /* ENABLE_IPTABLES_LOKKIT */
- free(rules);
+ VIR_FREE(rules);
}
static iptRules *
@@ -367,7 +358,7 @@
{
iptRules *rules;
- if (!(rules = calloc(1, sizeof (*rules))))
+ if (VIR_ALLOC(rules) < 0)
return NULL;
if (!(rules->table = strdup(table)))
@@ -404,8 +395,9 @@
for (len = 1, i = 0; argv[i]; i++)
len += strlen(argv[i]) + 1;
- if (!(p = ret = (char *)malloc(len)))
+ if (VIR_ALLOC_N(ret, len) < 0)
return NULL;
+ p = ret;
for (i = 0; argv[i]; i++) {
if (i != 0)
@@ -441,7 +433,7 @@
va_end(args);
- if (!(argv = calloc(n + 1, sizeof(*argv))))
+ if (VIR_ALLOC_N(argv, n + 1) < 0)
goto error;
n = 0;
@@ -478,7 +470,7 @@
goto error;
if (action == REMOVE) {
- free(argv[command_idx]);
+ VIR_FREE(argv[command_idx]);
if (!(argv[command_idx] = strdup("--delete")))
goto error;
}
@@ -497,13 +489,13 @@
}
error:
- free(rule);
+ VIR_FREE(rule);
if (argv) {
n = 0;
while (argv[n])
- free(argv[n++]);
- free(argv);
+ VIR_FREE(argv[n++]);
+ VIR_FREE(argv);
}
return retval;
@@ -521,7 +513,7 @@
{
iptablesContext *ctx;
- if (!(ctx = calloc(1, sizeof (*ctx))))
+ if (VIR_ALLOC(ctx) < 0)
return NULL;
if (!(ctx->input_filter = iptRulesNew("filter", "INPUT")))
@@ -555,7 +547,7 @@
iptRulesFree(ctx->forward_filter);
if (ctx->nat_postrouting)
iptRulesFree(ctx->nat_postrouting);
- free(ctx);
+ VIR_FREE(ctx);
}
/**
diff -r ff6b92c70738 src/lxc_conf.c
--- a/src/lxc_conf.c Fri May 30 10:36:42 2008 -0400
+++ b/src/lxc_conf.c Fri May 30 10:55:44 2008 -0400
@@ -42,7 +42,7 @@
#include "util.h"
#include "uuid.h"
#include "xml.h"
-
+#include "memory.h"
#include "lxc_conf.h"
/* debug macros */
@@ -183,10 +183,10 @@
if (virUUIDParse(res, uuid) < 0) {
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
_("invalid uuid element"));
- free(res);
+ VIR_FREE(res);
return(-1);
}
- free(res);
+ VIR_FREE(res);
}
return(0);
}
@@ -206,15 +206,14 @@
res = virXPathNodeSet("/domain/devices/filesystem", contextPtr, &list);
if (res > 0) {
for (i = 0; i < res; ++i) {
- mountObj = calloc(1, sizeof(lxc_mount_t));
- if (NULL == mountObj) {
+ if (VIR_ALLOC(mountObj) < 0) {
lxcError(conn, NULL, VIR_ERR_NO_MEMORY, "mount");
goto parse_complete;
}
rc = lxcParseMountXML(conn, list[i], mountObj);
if (0 > rc) {
- free(mountObj);
+ VIR_FREE(mountObj);
goto parse_complete;
}
@@ -228,7 +227,7 @@
}
prevObj = mountObj;
}
- free(list);
+ VIR_FREE(list);
}
rc = nmounts;
@@ -252,7 +251,7 @@
if (strlen(res) >= PATH_MAX - 1) {
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
_("init string too long"));
- free(res);
+ VIR_FREE(res);
return(-1);
}
@@ -307,7 +306,7 @@
xmlChar *xmlProp = NULL;
lxc_vm_def_t *containerDef;
- if (!(containerDef = calloc(1, sizeof(*containerDef)))) {
+ if (VIR_ALLOC(containerDef) < 0) {
lxcError(conn, NULL, VIR_ERR_NO_MEMORY, "containerDef");
return NULL;
}
@@ -339,8 +338,7 @@
_("invalid domain type"));
goto error;
}
- free(xmlProp);
- xmlProp = NULL;
+ VIR_FREE(xmlProp);
if ((xmlProp = xmlGetProp(rootNodePtr, BAD_CAST "id"))) {
if (0 > virStrToLong_i((char*)xmlProp, NULL, 10, &(containerDef->id))) {
@@ -351,8 +349,7 @@
} else {
containerDef->id = -1;
}
- free(xmlProp);
- xmlProp = NULL;
+ VIR_FREE(xmlProp);
if (lxcParseDomainName(conn, &(containerDef->name), contextPtr) < 0) {
goto error;
@@ -385,7 +382,7 @@
return containerDef;
error:
- free(xmlProp);
+ VIR_FREE(xmlProp);
xmlXPathFreeContext(contextPtr);
lxcFreeVMDef(containerDef);
@@ -436,7 +433,7 @@
return vm;
}
- if (!(vm = calloc(1, sizeof(lxc_vm_t)))) {
+ if (VIR_ALLOC(vm) < 0) {
lxcError(conn, NULL, VIR_ERR_NO_MEMORY, "vm");
return NULL;
}
@@ -529,7 +526,7 @@
close(fd);
}
- free(xmlDef);
+ VIR_FREE(xmlDef);
return rc;
}
@@ -637,7 +634,7 @@
lxcLoadConfig(driver, file, tempPath, xmlData);
- free(xmlData);
+ VIR_FREE(xmlData);
load_complete:
return rc;
@@ -744,14 +741,14 @@
curMount = vmdef->mounts;
while (curMount) {
nextMount = curMount->next;
- free(curMount);
+ VIR_FREE(curMount);
curMount = nextMount;
}
- free(vmdef->name);
- free(vmdef->init);
- free(vmdef->tty);
- free(vmdef);
+ VIR_FREE(vmdef->name);
+ VIR_FREE(vmdef->init);
+ VIR_FREE(vmdef->tty);
+ VIR_FREE(vmdef);
}
void lxcFreeVMs(lxc_vm_t *vms)
@@ -769,8 +766,8 @@
void lxcFreeVM(lxc_vm_t *vm)
{
lxcFreeVMDef(vm->def);
- free(vm->containerTty);
- free(vm);
+ VIR_FREE(vm->containerTty);
+ VIR_FREE(vm);
}
lxc_vm_t *lxcFindVMByID(const lxc_driver_t *driver, int id)
diff -r ff6b92c70738 src/lxc_container.c
--- a/src/lxc_container.c Fri May 30 10:36:42 2008 -0400
+++ b/src/lxc_container.c Fri May 30 10:55:44 2008 -0400
@@ -35,6 +35,7 @@
#include "lxc_container.h"
#include "lxc_conf.h"
#include "util.h"
+#include "memory.h"
#define DEBUG(fmt,...) VIR_DEBUG(__FILE__, fmt, __VA_ARGS__)
#define DEBUG0(msg) VIR_DEBUG(__FILE__, "%s", msg)
@@ -54,8 +55,8 @@
char* execString;
size_t execStringLen = strlen(vmDef->init) + 1 + 5;
- if (NULL == (execString = calloc(execStringLen, sizeof(char)))) {
- lxcError(NULL, NULL, VIR_ERR_NO_MEMORY,
+ if (VIR_ALLOC_N(execString, execStringLen) < 0) {
+ lxcError(NULL, NULL, VIR_ERR_NO_MEMORY,
_("failed to calloc memory for init string: %s"),
strerror(errno));
goto error_out;
diff -r ff6b92c70738 src/lxc_driver.c
--- a/src/lxc_driver.c Fri May 30 10:36:42 2008 -0400
+++ b/src/lxc_driver.c Fri May 30 10:55:44 2008 -0400
@@ -42,6 +42,7 @@
#include "driver.h"
#include "internal.h"
#include "util.h"
+#include "memory.h"
/* debug macros */
#define DEBUG(fmt,...) VIR_DEBUG(__FILE__, fmt, __VA_ARGS__)
@@ -85,8 +86,7 @@
char *stack;
int childStatus;
- stack = malloc(getpagesize() * 4);
- if(!stack) {
+ if (VIR_ALLOC_N(stack, getpagesize() * 4) < 0) {
DEBUG0("Unable to allocate stack");
rc = -1;
goto check_complete;
@@ -102,7 +102,7 @@
waitpid(cpid, &childStatus, 0);
}
- free(stack);
+ VIR_FREE(stack);
check_complete:
return rc;
@@ -263,7 +263,7 @@
cleanup:
for (i = 0 ; i < numDoms ; i++) {
- free(names[i]);
+ VIR_FREE(names[i]);
}
return -1;
@@ -398,16 +398,15 @@
int rc = -1;
int flags;
int stacksize = getpagesize() * 4;
- void *stack, *stacktop;
+ char *stack, *stacktop;
/* allocate a stack for the container */
- stack = malloc(stacksize);
- if (!stack) {
+ if (VIR_ALLOC_N(stack, stacksize) < 0) {
lxcError(conn, NULL, VIR_ERR_NO_MEMORY,
_("unable to allocate container stack"));
goto error_exit;
}
- stacktop = (char*)stack + stacksize;
+ stacktop = stack + stacksize;
flags = CLONE_NEWPID|CLONE_NEWNS|CLONE_NEWUTS|CLONE_NEWUSER|CLONE_NEWIPC|SIGCHLD;
@@ -572,8 +571,7 @@
goto cleanup;
}
- *ttyName = malloc(sizeof(char) * (strlen(tempTtyName) + 1));
- if (NULL == ttyName) {
+ if (VIR_ALLOC_N(*ttyName, strlen(tempTtyName) + 1) < 0) {
lxcError(conn, NULL, VIR_ERR_NO_MEMORY,
_("unable to allocate container name string"));
goto cleanup;
@@ -1034,8 +1032,7 @@
return -1;
}
- lxc_driver = calloc(1, sizeof(lxc_driver_t));
- if (NULL == lxc_driver) {
+ if (VIR_ALLOC(lxc_driver) < 0) {
return -1;
}
@@ -1062,8 +1059,8 @@
static void lxcFreeDriver(lxc_driver_t *driver)
{
- free(driver->configDir);
- free(driver);
+ VIR_FREE(driver->configDir);
+ VIR_FREE(driver);
}
static int lxcShutdown(void)
diff -r ff6b92c70738 src/openvz_conf.c
--- a/src/openvz_conf.c Fri May 30 10:36:42 2008 -0400
+++ b/src/openvz_conf.c Fri May 30 10:55:44 2008 -0400
@@ -53,6 +53,7 @@
#include "openvz_conf.h"
#include "uuid.h"
#include "buf.h"
+#include "memory.h"
#include <string.h>
@@ -152,23 +153,22 @@
struct ovz_quota *prev = quota;
quota = quota->next;
- free(prev);
+ VIR_FREE(prev);
}
while (ip) {
struct ovz_ip *prev = ip;
ip = ip->next;
- free(prev);
+ VIR_FREE(prev);
}
while (ns) {
struct ovz_ns *prev = ns;
ns = ns->next;
- free(prev);
+ VIR_FREE(prev);
}
- free(def);
- def = NULL;
+ VIR_FREE(def);
}
}
@@ -201,8 +201,7 @@
}
if (vms) {
openvzFreeVMDef(vm->vmdef);
- free(vm);
- vm = NULL;
+ VIR_FREE(vm);
}
}
@@ -217,8 +216,7 @@
if (driver->vms)
for(next = driver->vms->next; driver->vms; driver->vms = next)
openvzFreeVM(driver, driver->vms, 0);
- free(driver);
- driver = NULL;
+ VIR_FREE(driver);
}
struct openvz_vm *
@@ -247,7 +245,7 @@
return vm;
}
- if (!(vm = calloc(1, sizeof(*vm)))) {
+ if (VIR_ALLOC(vm) < 0) {
openvzFreeVMDef(def);
error(conn, VIR_ERR_NO_MEMORY, "vm");
return NULL;
@@ -299,7 +297,7 @@
struct ovz_ip *ovzIp;
struct ovz_ns *ovzNs;
- if (!(def = calloc(1, sizeof(*def)))) {
+ if (VIR_ALLOC(def) < 0) {
error(conn, VIR_ERR_NO_MEMORY, "xmlXPathContext");
return NULL;
}
@@ -328,8 +326,7 @@
error(conn, VIR_ERR_INTERNAL_ERROR, _("invalid domain type attribute"));
goto bail_out;
}
- free(prop);
- prop = NULL;
+ VIR_FREE(prop);
/* Extract domain name */
obj = xmlXPathEval(BAD_CAST "string(/domain/name[1])", ctxt);
@@ -396,7 +393,7 @@
error(conn, VIR_ERR_INTERNAL_ERROR, errorMessage);
goto bail_out;
}
- if (!(ovzIp = calloc(1, sizeof(*ovzIp)))) {
+ if (VIR_ALLOC(ovzIp) < 0) {
openvzLog(OPENVZ_ERR,
_("Failed to Create Memory for 'ovz_ip' structure"));
goto bail_out;
@@ -478,7 +475,7 @@
error(conn, VIR_ERR_INTERNAL_ERROR, errorMessage);
goto bail_out;
}
- if (!(ovzNs = calloc(1, sizeof(*ovzNs)))) {
+ if (VIR_ALLOC(ovzNs) < 0) {
openvzLog(OPENVZ_ERR,
_("Failed to Create Memory for 'ovz_ns' structure"));
goto bail_out;
@@ -509,7 +506,7 @@
return def;
bail_out:
- free(prop);
+ VIR_FREE(prop);
xmlXPathFreeObject(obj);
xmlXPathFreeContext(ctxt);
openvzFreeVMDef(def);
@@ -539,8 +536,7 @@
}
pnext = &vm;
while(!feof(fp)) {
- *pnext = calloc(1, sizeof(**pnext));
- if(!*pnext) {
+ if (VIR_ALLOC(*pnext) < 0) {
error(conn, VIR_ERR_INTERNAL_ERROR, _("calloc failed"));
goto error;
}
@@ -568,8 +564,7 @@
(*pnext)->vpsid = -1;
}
- vmdef = calloc(1, sizeof(*vmdef));
- if(!vmdef) {
+ if (VIR_ALLOC(vmdef) < 0) {
error(conn, VIR_ERR_INTERNAL_ERROR, _("calloc failed"));
goto error;
}
@@ -581,7 +576,7 @@
if(ret == -1) {
error(conn, VIR_ERR_INTERNAL_ERROR,
_("UUID in config file malformed"));
- free(vmdef);
+ VIR_FREE(vmdef);
goto error;
}
@@ -594,8 +589,8 @@
struct openvz_vm *next;
next = vm->next;
- free(vm->vmdef);
- free(vm);
+ VIR_FREE(vm->vmdef);
+ VIR_FREE(vm);
vm = next;
}
return NULL;
@@ -656,7 +651,7 @@
if (conf_dir == NULL)
return -1;
sprintf(conf_file, "%s/%d.conf", conf_dir, vpsid);
- free(conf_dir);
+ VIR_FREE(conf_dir);
fd = open(conf_file, O_RDWR);
if(fd == -1)
@@ -697,7 +692,7 @@
if (conf_dir == NULL)
return -1;
sprintf(conf_file, "%s/%d.conf", conf_dir, vpsid);
- free(conf_dir);
+ VIR_FREE(conf_dir);
if (openvzGetVPSUUID(vpsid, uuidstr))
return -1;
@@ -741,7 +736,7 @@
dp = opendir(conf_dir);
if(dp == NULL) {
- free(conf_dir);
+ VIR_FREE(conf_dir);
return 0;
}
@@ -753,7 +748,7 @@
openvzSetUUID(vpsid);
}
closedir(dp);
- free(conf_dir);
+ VIR_FREE(conf_dir);
return 0;
}
diff -r ff6b92c70738 src/openvz_driver.c
--- a/src/openvz_driver.c Fri May 30 10:36:42 2008 -0400
+++ b/src/openvz_driver.c Fri May 30 10:55:44 2008 -0400
@@ -49,8 +49,7 @@
#include <stdio.h>
#include <sys/wait.h>
-#include "libvirt/virterror.h"
-
+#include "internal.h"
#include "openvz_driver.h"
#include "event.h"
#include "buf.h"
diff -r ff6b92c70738 src/proxy_internal.c
--- a/src/proxy_internal.c Fri May 30 10:36:42 2008 -0400
+++ b/src/proxy_internal.c Fri May 30 10:55:44 2008 -0400
@@ -28,6 +28,7 @@
#include "proxy_internal.h"
#include "util.h"
#include "xen_unified.h"
+#include "memory.h"
#define STANDALONE
@@ -992,8 +993,7 @@
}
xmllen = ans.len - sizeof (virProxyPacket);
- xml = malloc (xmllen+1);
- if (!xml) {
+ if (VIR_ALLOC_N(xml, xmllen+1) < 0) {
virProxyError (conn, VIR_ERR_NO_MEMORY, __FUNCTION__);
return NULL;
}
@@ -1044,7 +1044,7 @@
return (NULL);
}
xmllen = ans.len - sizeof(virProxyPacket);
- if (!(xml = malloc(xmllen+1))) {
+ if (VIR_ALLOC_N(xml, xmllen+1) < 0) {
virProxyError(domain->conn, VIR_ERR_NO_MEMORY, __FUNCTION__);
return NULL;
}
@@ -1097,7 +1097,7 @@
return (NULL);
}
oslen = ans.len - sizeof(virProxyPacket);
- if (!(ostype = malloc(oslen+1))) {
+ if (VIR_ALLOC_N(ostype, oslen+1) < 0) {
virProxyError(domain->conn, VIR_ERR_NO_MEMORY, __FUNCTION__);
return NULL;
}
diff -r ff6b92c70738 src/remote_internal.c
--- a/src/remote_internal.c Fri May 30 10:36:42 2008 -0400
+++ b/src/remote_internal.c Fri May 30 10:55:44 2008 -0400
@@ -71,6 +71,7 @@
#include "qparams.h"
#include "remote_internal.h"
#include "remote_protocol.h"
+#include "memory.h"
#define DEBUG(fmt,...) VIR_DEBUG(__FILE__, fmt,__VA_ARGS__)
#define DEBUG0(msg) VIR_DEBUG(__FILE__, "%s", msg)
@@ -638,8 +639,7 @@
// Generate the final command argv[] array.
// ssh -p $port [-l $username] $hostname $netcat -U $sockname [NULL]
- cmd_argv = malloc (nr_args * sizeof (*cmd_argv));
- if (cmd_argv == NULL) {
+ if (VIR_ALLOC_N(cmd_argv, nr_args) < 0) {
error (conn, VIR_ERR_SYSTEM_ERROR, strerror (errno));
goto failed;
}
@@ -702,8 +702,7 @@
// Run the external process.
if (!cmd_argv) {
- cmd_argv = malloc (2 * sizeof (*cmd_argv));
- if (cmd_argv == NULL) {
+ if (VIR_ALLOC_N(cmd_argv, 2) < 0) {
error (conn, VIR_ERR_SYSTEM_ERROR, strerror (errno));
goto failed;
}
@@ -811,8 +810,7 @@
if (inside_daemon)
return VIR_DRV_OPEN_DECLINED;
- priv = calloc (1, sizeof(*priv));
- if (!priv) {
+ if (VIR_ALLOC(priv) < 0) {
error (conn, VIR_ERR_NO_MEMORY, _("struct private_data"));
return VIR_DRV_OPEN_ERROR;
}
@@ -856,7 +854,7 @@
ret = doRemoteOpen(conn, priv, uri, auth, rflags);
if (ret != VIR_DRV_OPEN_SUCCESS) {
conn->privateData = NULL;
- free(priv);
+ VIR_FREE(priv);
} else {
priv->magic = MAGIC;
conn->privateData = priv;
@@ -2268,9 +2266,7 @@
/* Serialise the scheduler parameters. */
args.params.params_len = nparams;
- args.params.params_val = malloc (sizeof (*args.params.params_val)
- * nparams);
- if (args.params.params_val == NULL) {
+ if (VIR_ALLOC_N(args.params.params_val, nparams) < 0) {
error (domain->conn, VIR_ERR_RPC, _("out of memory allocating array"));
return -1;
}
@@ -2400,9 +2396,9 @@
* use the UNIX transport. This handles Xen driver
* which doesn't have its own impl of the network APIs.
*/
- struct private_data *priv = calloc (1, sizeof(*priv));
+ struct private_data *priv;
int ret, rflags = 0;
- if (!priv) {
+ if (VIR_ALLOC(priv) < 0) {
error (conn, VIR_ERR_NO_MEMORY, _("struct private_data"));
return VIR_DRV_OPEN_ERROR;
}
@@ -2415,7 +2411,7 @@
ret = doRemoteOpen(conn, priv, uri, auth, rflags);
if (ret != VIR_DRV_OPEN_SUCCESS) {
conn->networkPrivateData = NULL;
- free(priv);
+ VIR_FREE(priv);
} else {
priv->magic = MAGIC;
priv->localUses = 1;
@@ -2434,7 +2430,7 @@
priv->localUses--;
if (!priv->localUses) {
ret = doRemoteClose(conn, priv);
- free(priv);
+ VIR_FREE(priv);
conn->networkPrivateData = NULL;
}
}
@@ -2806,9 +2802,9 @@
* use the UNIX transport. This handles Xen driver
* which doesn't have its own impl of the network APIs.
*/
- struct private_data *priv = calloc (1, sizeof(struct private_data));
+ struct private_data *priv;
int ret, rflags = 0;
- if (!priv) {
+ if (VIR_ALLOC(priv) < 0) {
error (NULL, VIR_ERR_NO_MEMORY, _("struct private_data"));
return VIR_DRV_OPEN_ERROR;
}
@@ -2821,7 +2817,7 @@
ret = doRemoteOpen(conn, priv, uri, auth, rflags);
if (ret != VIR_DRV_OPEN_SUCCESS) {
conn->storagePrivateData = NULL;
- free(priv);
+ VIR_FREE(priv);
} else {
priv->magic = MAGIC;
priv->localUses = 1;
@@ -2840,7 +2836,7 @@
priv->localUses--;
if (!priv->localUses) {
ret = doRemoteClose(conn, priv);
- free(priv);
+ VIR_FREE(priv);
conn->storagePrivateData = NULL;
}
}
@@ -3559,7 +3555,7 @@
mech = authtype + 5;
if (remoteAuthSASL(conn, priv, in_open, auth, mech) < 0) {
- free(ret.types.types_val);
+ VIR_FREE(ret.types.types_val);
return -1;
}
break;
@@ -3569,7 +3565,7 @@
#if HAVE_POLKIT
case REMOTE_AUTH_POLKIT:
if (remoteAuthPolkit(conn, priv, in_open, auth) < 0) {
- free(ret.types.types_val);
+ VIR_FREE(ret.types.types_val);
return -1;
}
break;
@@ -3585,11 +3581,11 @@
NULL, NULL, NULL, 0, 0,
_("unsupported authentication type %d"),
ret.types.types_val[0]);
- free(ret.types.types_val);
- return -1;
- }
-
- free(ret.types.types_val);
+ VIR_FREE(ret.types.types_val);
+ return -1;
+ }
+
+ VIR_FREE(ret.types.types_val);
return 0;
}
@@ -3618,8 +3614,7 @@
return NULL;
}
- addr = malloc(strlen(host) + 1 + strlen(port) + 1);
- if (!addr) {
+ if (VIR_ALLOC_N(addr, strlen(host) + 1 + strlen(port) + 1) < 0) {
__virRaiseError (NULL, NULL, NULL, VIR_FROM_REMOTE,
VIR_ERR_NO_MEMORY, VIR_ERR_ERROR,
NULL, NULL, NULL, 0, 0,
@@ -3712,9 +3707,9 @@
*/
static sasl_callback_t *remoteAuthMakeCallbacks(int *credtype, int ncredtype)
{
- sasl_callback_t *cbs = calloc(ncredtype+1, sizeof (*cbs));
+ sasl_callback_t *cbs;
int i, n;
- if (!cbs) {
+ if (VIR_ALLOC_N(cbs, ncredtype+1) < 0) {
return NULL;
}
@@ -3749,14 +3744,13 @@
for (ninteract = 0 ; interact[ninteract].id != 0 ; ninteract++)
; /* empty */
- *cred = calloc(ninteract, sizeof(*cred));
- if (!*cred)
+ if (VIR_ALLOC_N(*cred, ninteract) < 0)
return -1;
for (ninteract = 0 ; interact[ninteract].id != 0 ; ninteract++) {
(*cred)[ninteract].type = remoteAuthCredSASL2Vir(interact[ninteract].id);
if (!(*cred)[ninteract].type) {
- free(*cred);
+ VIR_FREE(*cred);
return -1;
}
if (interact[ninteract].challenge)
@@ -3775,8 +3769,8 @@
{
int i;
for (i = 0 ; i < ncred ; i++)
- free(cred[i].result);
- free(cred);
+ VIR_FREE(cred[i].result);
+ VIR_FREE(cred);
}
@@ -3944,7 +3938,7 @@
NULL, NULL, NULL, 0, 0,
_("SASL mechanism %s not supported by server"),
wantmech);
- free(iret.mechlist);
+ VIR_FREE(iret.mechlist);
goto cleanup;
}
mechlist = wantmech;
@@ -3963,7 +3957,7 @@
VIR_ERR_AUTH_FAILED, VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
_("Failed to start SASL negotiation: %d (%s)"),
err, sasl_errdetail(saslconn));
- free(iret.mechlist);
+ VIR_FREE(iret.mechlist);
goto cleanup;
}
@@ -3980,7 +3974,7 @@
VIR_ERR_AUTH_FAILED, VIR_ERR_ERROR,
NULL, NULL, NULL, 0, 0,
"%s", _("Failed to make auth credentials"));
- free(iret.mechlist);
+ VIR_FREE(iret.mechlist);
goto cleanup;
}
/* Run the authentication callback */
@@ -3998,7 +3992,7 @@
0, 0, "%s", msg);
goto cleanup;
}
- free(iret.mechlist);
+ VIR_FREE(iret.mechlist);
if (clientoutlen > REMOTE_AUTH_SASL_DATA_MAX) {
__virRaiseError (in_open ? NULL : conn, NULL, NULL, VIR_FROM_REMOTE,
@@ -4077,8 +4071,7 @@
}
if (serverin) {
- free(serverin);
- serverin = NULL;
+ VIR_FREE(serverin);
}
DEBUG("Client step result %d. Data %d bytes %p", err, clientoutlen, clientout);
@@ -4110,7 +4103,7 @@
/* This server call shows complete, and earlier client step was OK */
if (complete && err == SASL_OK) {
- free(serverin);
+ VIR_FREE(serverin);
break;
}
}
@@ -4140,11 +4133,11 @@
ret = 0;
cleanup:
- free(localAddr);
- free(remoteAddr);
- free(serverin);
-
- free(saslcb);
+ VIR_FREE(localAddr);
+ VIR_FREE(remoteAddr);
+ VIR_FREE(serverin);
+
+ VIR_FREE(saslcb);
remoteAuthFreeCredentials(cred, ncred);
if (ret != 0 && saslconn)
sasl_dispose(&saslconn);
diff -r ff6b92c70738 src/sexpr.c
--- a/src/sexpr.c Fri May 30 10:36:42 2008 -0400
+++ b/src/sexpr.c Fri May 30 10:55:44 2008 -0400
@@ -21,6 +21,7 @@
#include "internal.h"
#include "sexpr.h"
#include "util.h"
+#include "memory.h"
/**
* virSexprError:
@@ -55,8 +56,7 @@
{
struct sexpr *ret;
- ret = (struct sexpr *) malloc(sizeof(*ret));
- if (ret == NULL) {
+ if (VIR_ALLOC(ret) < 0) {
virSexprError(VIR_ERR_NO_MEMORY, _("failed to allocate a node"));
return (NULL);
}
@@ -85,13 +85,13 @@
sexpr_free(sexpr->u.s.cdr);
break;
case SEXPR_VALUE:
- free(sexpr->u.value);
+ VIR_FREE(sexpr->u.value);
break;
case SEXPR_NIL:
break;
}
- free(sexpr);
+ VIR_FREE(sexpr);
errno = serrno;
}
@@ -171,16 +171,23 @@
*
* Internal operation appending a value at the end of an existing list
*/
-static void
+static int
append(struct sexpr *lst, const struct sexpr *value)
{
+ struct sexpr *nil = sexpr_nil();
+
+ if (nil == NULL)
+ return -1;
+
while (lst->kind != SEXPR_NIL) {
lst = lst->u.s.cdr;
}
lst->kind = SEXPR_CONS;
lst->u.s.car = (struct sexpr *) value;
- lst->u.s.cdr = sexpr_nil();
+ lst->u.s.cdr = nil;
+
+ return 0;
}
/**
@@ -198,7 +205,8 @@
return (NULL);
if (value == NULL)
return (lst);
- append(lst, value);
+ if (append(lst, value) < 0)
+ return (NULL);
return (lst);
}
@@ -318,8 +326,11 @@
tmp = _string2sexpr(ptr, &tmp_len);
if (tmp == NULL)
- return NULL;
- append(ret, tmp);
+ goto error;
+ if (append(ret, tmp) < 0) {
+ sexpr_free(tmp);
+ goto error;
+ }
#if 0
if (0) {
char buf[4096];
@@ -351,6 +362,7 @@
if (ret->u.value == NULL) {
virSexprError(VIR_ERR_NO_MEMORY,
_("failed to copy a string"));
+ goto error;
}
if (*ptr == '\'')
@@ -367,6 +379,7 @@
if (ret->u.value == NULL) {
virSexprError(VIR_ERR_NO_MEMORY,
_("failed to copy a string"));
+ goto error;
}
}
diff -r ff6b92c70738 src/storage_backend.c
--- a/src/storage_backend.c Fri May 30 10:36:42 2008 -0400
+++ b/src/storage_backend.c Fri May 30 10:55:44 2008 -0400
@@ -50,6 +50,7 @@
#endif
#include "util.h"
+#include "memory.h"
#include "storage_backend.h"
#include "storage_backend_fs.h"
@@ -237,8 +238,7 @@
vol->target.perms.uid = sb.st_uid;
vol->target.perms.gid = sb.st_gid;
- free(vol->target.perms.label);
- vol->target.perms.label = NULL;
+ VIR_FREE(vol->target.perms.label);
#if HAVE_SELINUX
if (fgetfilecon(fd, &filecon) == -1) {
@@ -310,9 +310,8 @@
if (dent->d_name[0] == '.')
continue;
- stablepath = malloc(strlen(pool->def->target.path) +
- 1 + strlen(dent->d_name) + 1);
- if (stablepath == NULL) {
+ if (VIR_ALLOC_N(stablepath, strlen(pool->def->target.path) +
+ 1 + strlen(dent->d_name) + 1) < 0) {
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("path"));
closedir(dh);
return NULL;
@@ -327,7 +326,7 @@
return stablepath;
}
- free(stablepath);
+ VIR_FREE(stablepath);
}
closedir(dh);
@@ -365,7 +364,7 @@
char **groups;
/* Compile all regular expressions */
- if ((reg = calloc(nregex, sizeof(*reg))) == NULL) {
+ if (VIR_ALLOC_N(reg, nregex) < 0) {
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("regex"));
return -1;
}
@@ -379,7 +378,7 @@
_("Failed to compile regex %s"), error);
for (j = 0 ; j <= i ; j++)
regfree(®[j]);
- free(reg);
+ VIR_FREE(reg);
return -1;
}
@@ -390,12 +389,12 @@
}
/* Storage for matched variables */
- if ((groups = calloc(totgroups, sizeof(*groups))) == NULL) {
+ if (VIR_ALLOC_N(groups, totgroups) < 0) {
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
"%s", _("regex groups"));
goto cleanup;
}
- if ((vars = calloc(maxvars+1, sizeof(*vars))) == NULL) {
+ if (VIR_ALLOC_N(vars, maxvars+1) < 0) {
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
"%s", _("regex groups"));
goto cleanup;
@@ -445,7 +444,7 @@
/* Release matches & restart to matching the first regex */
for (j = 0 ; j < totgroups ; j++) {
- free(groups[j]);
+ VIR_FREE(groups[j]);
groups[j] = NULL;
}
maxReg = 0;
@@ -460,15 +459,15 @@
cleanup:
if (groups) {
for (j = 0 ; j < totgroups ; j++)
- free(groups[j]);
- free(groups);
+ VIR_FREE(groups[j]);
+ VIR_FREE(groups);
}
- free(vars);
+ VIR_FREE(vars);
for (i = 0 ; i < nregex ; i++)
regfree(®[i]);
- free(reg);
+ VIR_FREE(reg);
if (list)
fclose(list);
@@ -534,8 +533,7 @@
if (n_columns == 0)
return -1;
- if (n_columns > SIZE_MAX / sizeof *v
- || (v = malloc (n_columns * sizeof *v)) == NULL) {
+ if (VIR_ALLOC_N(v, n_columns) < 0) {
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
"%s", _("n_columns too large"));
return -1;
diff -r ff6b92c70738 src/storage_backend_disk.c
--- a/src/storage_backend_disk.c Fri May 30 10:36:42 2008 -0400
+++ b/src/storage_backend_disk.c Fri May 30 10:55:44 2008 -0400
@@ -26,6 +26,7 @@
#include "internal.h"
#include "storage_backend_disk.h"
#include "util.h"
+#include "memory.h"
enum {
VIR_STORAGE_POOL_DISK_DOS = 0,
@@ -174,7 +175,7 @@
char *tmp, *devpath;
if (vol == NULL) {
- if ((vol = calloc(1, sizeof(virStorageVolDef))) == NULL) {
+ if (VIR_ALLOC(vol) < 0) {
virStorageReportError(conn, VIR_ERR_NO_MEMORY, _("volume"));
return -1;
}
@@ -211,8 +212,7 @@
return -1;
if (devpath != vol->target.path)
- free(devpath);
- devpath = NULL;
+ VIR_FREE(devpath);
}
if (vol->key == NULL) {
@@ -224,8 +224,7 @@
}
if (vol->source.extents == NULL) {
- if ((vol->source.extents =
- calloc(1, sizeof(*(vol->source.extents)))) == NULL) {
+ if (VIR_ALLOC(vol->source.extents) < 0) {
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
_("volume extents"));
return -1;
@@ -275,16 +274,15 @@
virStoragePoolObjPtr pool,
char **const groups)
{
- virStoragePoolSourceDeviceExtentPtr tmp;
virStoragePoolSourceDevicePtr dev = &pool->def->source.devices[0];
- if ((tmp = realloc(dev->freeExtents,
- sizeof(*tmp) * (dev->nfreeExtent+1))) == NULL)
+ if (VIR_REALLOC_N(dev->freeExtents,
+ dev->nfreeExtent + 1) < 0)
return -1;
- dev->freeExtents = tmp;
memset(dev->freeExtents +
- dev->nfreeExtent, 0, sizeof(*tmp));
+ dev->nfreeExtent, 0,
+ sizeof(dev->freeExtents[0]));
if (virStrToLong_ull(groups[3], NULL, 10,
&dev->freeExtents[dev->nfreeExtent].start) < 0)
@@ -388,9 +386,8 @@
virStorageBackendDiskRefreshPool(virConnectPtr conn,
virStoragePoolObjPtr pool)
{
- free(pool->def->source.devices[0].freeExtents);
+ VIR_FREE(pool->def->source.devices[0].freeExtents);
pool->def->source.devices[0].nfreeExtent = 0;
- pool->def->source.devices[0].freeExtents = NULL;
return virStorageBackendDiskReadPartitions(conn, pool, NULL);
}
@@ -476,9 +473,8 @@
return -1;
/* Blow away free extent info, as we're about to re-populate it */
- free(pool->def->source.devices[0].freeExtents);
+ VIR_FREE(pool->def->source.devices[0].freeExtents);
pool->def->source.devices[0].nfreeExtent = 0;
- pool->def->source.devices[0].freeExtents = NULL;
/* Fetch actual extent info */
if (virStorageBackendDiskReadPartitions(conn, pool, vol) < 0)
diff -r ff6b92c70738 src/storage_backend_fs.c
--- a/src/storage_backend_fs.c Fri May 30 10:36:42 2008 -0400
+++ b/src/storage_backend_fs.c Fri May 30 10:55:44 2008 -0400
@@ -40,8 +40,7 @@
#include "storage_backend_fs.h"
#include "storage_conf.h"
#include "util.h"
-#include "config.h"
-
+#include "memory.h"
enum {
VIR_STORAGE_POOL_FS_AUTO = 0,
@@ -530,25 +529,27 @@
}
if (pool->def->type == VIR_STORAGE_POOL_NETFS) {
- src = malloc(strlen(pool->def->source.host.name) +
- 1 + strlen(pool->def->source.dir) + 1);
+ if (VIR_ALLOC_N(src, strlen(pool->def->source.host.name) +
+ 1 + strlen(pool->def->source.dir) + 1) < 0) {
+ virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("source"));
+ return -1;
+ }
strcpy(src, pool->def->source.host.name);
strcat(src, ":");
strcat(src, pool->def->source.dir);
} else {
- src = strdup(pool->def->source.devices[0].path);
- }
- if (src == NULL) {
- virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("source"));
- return -1;
+ if ((src = strdup(pool->def->source.devices[0].path)) == NULL) {
+ virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("source"));
+ return -1;
+ }
}
mntargv[3] = src;
if (virRun(conn, (char**)mntargv, NULL) < 0) {
- free(src);
+ VIR_FREE(src);
return -1;
}
- free(src);
+ VIR_FREE(src);
return 0;
}
@@ -679,8 +680,7 @@
virStorageVolDefPtr vol;
int ret;
- vol = calloc(1, sizeof(virStorageVolDef));
- if (vol == NULL) {
+ if (VIR_ALLOC(vol) < 0) {
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
"%s", _("volume"));
goto cleanup;
@@ -688,18 +688,17 @@
vol->name = strdup(ent->d_name);
if (vol->name == NULL) {
- free(vol);
+ VIR_FREE(vol);
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
"%s", _("volume name"));
goto cleanup;
}
vol->target.format = VIR_STORAGE_VOL_RAW; /* Real value is filled in during probe */
- vol->target.path = malloc(strlen(pool->def->target.path) +
- 1 + strlen(vol->name) + 1);
- if (vol->target.path == NULL) {
- free(vol->target.path);
- free(vol);
+ if (VIR_ALLOC_N(vol->target.path, strlen(pool->def->target.path) +
+ 1 + strlen(vol->name) + 1) < 0) {
+ VIR_FREE(vol->target.path);
+ VIR_FREE(vol);
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
"%s", _("volume name"));
goto cleanup;
@@ -708,19 +707,19 @@
strcat(vol->target.path, "/");
strcat(vol->target.path, vol->name);
if ((vol->key = strdup(vol->target.path)) == NULL) {
- free(vol->name);
- free(vol->target.path);
- free(vol);
+ VIR_FREE(vol->name);
+ VIR_FREE(vol->target.path);
+ VIR_FREE(vol);
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
"%s", _("volume key"));
goto cleanup;
}
if ((ret = virStorageBackendProbeFile(conn, vol) < 0)) {
- free(vol->key);
- free(vol->name);
- free(vol->target.path);
- free(vol);
+ VIR_FREE(vol->key);
+ VIR_FREE(vol->name);
+ VIR_FREE(vol->target.path);
+ VIR_FREE(vol);
if (ret == -1)
goto cleanup;
else
@@ -821,9 +820,8 @@
{
int fd;
- vol->target.path = malloc(strlen(pool->def->target.path) +
- 1 + strlen(vol->name) + 1);
- if (vol->target.path == NULL) {
+ if (VIR_ALLOC_N(vol->target.path, strlen(pool->def->target.path) +
+ 1 + strlen(vol->name) + 1) < 0) {
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("target"));
return -1;
}
diff -r ff6b92c70738 src/storage_backend_iscsi.c
--- a/src/storage_backend_iscsi.c Fri May 30 10:36:42 2008 -0400
+++ b/src/storage_backend_iscsi.c Fri May 30 10:55:44 2008 -0400
@@ -37,6 +37,7 @@
#include "internal.h"
#include "storage_backend_iscsi.h"
#include "util.h"
+#include "memory.h"
static int
virStorageBackendISCSITargetIP(virConnectPtr conn,
@@ -253,7 +254,7 @@
snprintf(lunid, sizeof(lunid)-1, "lun-%s", groups[3]);
- if ((vol = calloc(1, sizeof(virStorageVolDef))) == NULL) {
+ if (VIR_ALLOC(vol) < 0) {
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("volume"));
goto cleanup;
}
@@ -263,14 +264,13 @@
goto cleanup;
}
- if ((devpath = malloc(5 + strlen(dev) + 1)) == NULL) {
+ if (VIR_ALLOC_N(devpath, 5 + strlen(dev) + 1) < 0) {
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("devpath"));
goto cleanup;
}
strcpy(devpath, "/dev/");
strcat(devpath, dev);
- free(dev);
- dev = NULL;
+ VIR_FREE(dev);
/* It can take a little while between logging into the ISCSI
* server and udev creating the /dev nodes, so if we get ENOENT
* we must retry a few times - they should eventually appear.
@@ -303,8 +303,7 @@
goto cleanup;
if (devpath != vol->target.path)
- free(devpath);
- devpath = NULL;
+ VIR_FREE(devpath);
if (virStorageBackendUpdateVolInfoFD(conn, vol, fd, 1) < 0)
goto cleanup;
@@ -330,9 +329,9 @@
cleanup:
if (fd != -1) close(fd);
- free(devpath);
+ VIR_FREE(devpath);
virStorageVolDefFree(vol);
- free(dev);
+ VIR_FREE(dev);
return -1;
}
@@ -422,8 +421,7 @@
ipaddr, sizeof(ipaddr)) < 0)
return NULL;
- portal = malloc(strlen(ipaddr) + 1 + 4 + 2 + 1);
- if (portal == NULL) {
+ if (VIR_ALLOC_N(portal, strlen(ipaddr) + 1 + 4 + 2 + 1) < 0) {
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("portal"));
return NULL;
}
@@ -457,10 +455,10 @@
if ((portal = virStorageBackendISCSIPortal(conn, pool)) == NULL)
return -1;
if (virStorageBackendISCSILogin(conn, pool, portal) < 0) {
- free(portal);
+ VIR_FREE(portal);
return -1;
}
- free(portal);
+ VIR_FREE(portal);
return 0;
}
@@ -478,12 +476,12 @@
goto cleanup;
if (virStorageBackendISCSIFindLUNs(conn, pool, session) < 0)
goto cleanup;
- free(session);
+ VIR_FREE(session);
return 0;
cleanup:
- free(session);
+ VIR_FREE(session);
return -1;
}
@@ -498,10 +496,10 @@
return -1;
if (virStorageBackendISCSILogout(conn, pool, portal) < 0) {
- free(portal);
+ VIR_FREE(portal);
return -1;
}
- free(portal);
+ VIR_FREE(portal);
return 0;
}
diff -r ff6b92c70738 src/storage_backend_logical.c
--- a/src/storage_backend_logical.c Fri May 30 10:36:42 2008 -0400
+++ b/src/storage_backend_logical.c Fri May 30 10:55:44 2008 -0400
@@ -35,7 +35,7 @@
#include "storage_backend_logical.h"
#include "storage_conf.h"
#include "util.h"
-
+#include "memory.h"
#define PV_BLANK_SECTOR_SIZE 512
@@ -97,7 +97,6 @@
void *data)
{
virStorageVolDefPtr vol = NULL;
- virStorageVolSourceExtentPtr tmp;
unsigned long long offset, size, length;
/* See if we're only looking for a specific volume */
@@ -113,7 +112,7 @@
/* Or a completely new volume */
if (vol == NULL) {
- if ((vol = calloc(1, sizeof(*vol))) == NULL) {
+ if (VIR_ALLOC(vol) < 0) {
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("volume"));
return -1;
}
@@ -129,8 +128,8 @@
}
if (vol->target.path == NULL) {
- if ((vol->target.path = malloc(strlen(pool->def->target.path) +
- 1 + strlen(vol->name) + 1)) == NULL) {
+ if (VIR_ALLOC_N(vol->target.path, strlen(pool->def->target.path) +
+ 1 + strlen(vol->name) + 1) < 0) {
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("volume"));
return -1;
}
@@ -150,12 +149,11 @@
/* Finally fill in extents information */
- if ((tmp = realloc(vol->source.extents, sizeof(*tmp)
- * (vol->source.nextent + 1))) == NULL) {
+ if (VIR_REALLOC_N(vol->source.extents,
+ vol->source.nextent + 1) < 0) {
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("extents"));
return -1;
}
- vol->source.extents = tmp;
if ((vol->source.extents[vol->source.nextent].path =
strdup(groups[2])) == NULL) {
@@ -266,7 +264,7 @@
memset(zeros, 0, sizeof(zeros));
/* XXX multiple pvs */
- if ((vgargv = malloc(sizeof(char*) * (1))) == NULL) {
+ if (VIR_ALLOC_N(vgargv, 1) < 0) {
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("command line"));
return -1;
}
@@ -318,12 +316,12 @@
if (virRun(conn, (char**)vgargv, NULL) < 0)
goto cleanup;
- free(vgargv);
+ VIR_FREE(vgargv);
return 0;
cleanup:
- free(vgargv);
+ VIR_FREE(vgargv);
return -1;
}
diff -r ff6b92c70738 src/storage_conf.c
--- a/src/storage_conf.c Fri May 30 10:36:42 2008 -0400
+++ b/src/storage_conf.c Fri May 30 10:55:44 2008 -0400
@@ -45,6 +45,7 @@
#include "uuid.h"
#include "buf.h"
#include "util.h"
+#include "memory.h"
#define virStorageLog(msg...) fprintf(stderr, msg)
@@ -70,40 +71,40 @@
void
virStorageVolDefFree(virStorageVolDefPtr def) {
int i;
- free(def->name);
- free(def->key);
+ VIR_FREE(def->name);
+ VIR_FREE(def->key);
for (i = 0 ; i < def->source.nextent ; i++) {
- free(def->source.extents[i].path);
+ VIR_FREE(def->source.extents[i].path);
}
- free(def->source.extents);
+ VIR_FREE(def->source.extents);
- free(def->target.path);
- free(def->target.perms.label);
- free(def);
+ VIR_FREE(def->target.path);
+ VIR_FREE(def->target.perms.label);
+ VIR_FREE(def);
}
void
virStoragePoolDefFree(virStoragePoolDefPtr def) {
int i;
- free(def->name);
- free(def->source.host.name);
+ VIR_FREE(def->name);
+ VIR_FREE(def->source.host.name);
for (i = 0 ; i < def->source.ndevice ; i++) {
- free(def->source.devices[i].freeExtents);
- free(def->source.devices[i].path);
+ VIR_FREE(def->source.devices[i].freeExtents);
+ VIR_FREE(def->source.devices[i].path);
}
- free(def->source.devices);
- free(def->source.dir);
+ VIR_FREE(def->source.devices);
+ VIR_FREE(def->source.dir);
if (def->source.authType == VIR_STORAGE_POOL_AUTH_CHAP) {
- free(def->source.auth.chap.login);
- free(def->source.auth.chap.passwd);
+ VIR_FREE(def->source.auth.chap.login);
+ VIR_FREE(def->source.auth.chap.passwd);
}
- free(def->target.path);
- free(def->target.perms.label);
- free(def);
+ VIR_FREE(def->target.path);
+ VIR_FREE(def->target.perms.label);
+ VIR_FREE(def);
}
@@ -114,9 +115,9 @@
if (obj->newDef)
virStoragePoolDefFree(obj->newDef);
- free(obj->configFile);
- free(obj->autostartLink);
- free(obj);
+ VIR_FREE(obj->configFile);
+ VIR_FREE(obj->autostartLink);
+ VIR_FREE(obj);
}
void
@@ -225,8 +226,11 @@
char *uuid = NULL;
char *authType = NULL;
- if ((ret = calloc(1, sizeof(virStoragePoolDef))) == NULL)
+ if (VIR_ALLOC(ret) < 0) {
+ virStorageReportError(conn, VIR_ERR_NO_MEMORY,
+ "%s", _("cannot allocate storage pool"));
return NULL;
+ }
if (STRNEQ((const char *)root->name, "pool")) {
virStorageReportError(conn, VIR_ERR_XML_ERROR,
@@ -263,17 +267,16 @@
"%s", _("malformed uuid element"));
goto cleanup;
}
- free(uuid);
- uuid = NULL;
+ VIR_FREE(uuid);
}
if (options->formatFromString) {
char *format = virXPathString("string(/pool/source/format/@type)", ctxt);
if ((ret->source.format = (options->formatFromString)(conn, format)) < 0) {
- free(format);
+ VIR_FREE(format);
goto cleanup;
}
- free(format);
+ VIR_FREE(format);
}
if (options->flags & VIR_STORAGE_BACKEND_POOL_SOURCE_HOST) {
@@ -292,22 +295,22 @@
"%s", _("cannot extract source devices"));
goto cleanup;
}
- if ((ret->source.devices = calloc(nsource, sizeof(*ret->source.devices))) == NULL) {
- free(nodeset);
+ if (VIR_ALLOC_N(ret->source.devices, nsource) < 0) {
+ VIR_FREE(nodeset);
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("device"));
goto cleanup;
}
for (i = 0 ; i < nsource ; i++) {
xmlChar *path = xmlGetProp(nodeset[i], BAD_CAST "path");
if (path == NULL) {
- free(nodeset);
+ VIR_FREE(nodeset);
virStorageReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("missing source device path"));
goto cleanup;
}
ret->source.devices[i].path = (char *)path;
}
- free(nodeset);
+ VIR_FREE(nodeset);
ret->source.ndevice = nsource;
}
if (options->flags & VIR_STORAGE_BACKEND_POOL_SOURCE_DIR) {
@@ -329,12 +332,10 @@
virStorageReportError(conn, VIR_ERR_XML_ERROR,
_("unknown auth type '%s'"),
(const char *)authType);
- free(authType);
- authType = NULL;
+ VIR_FREE(authType);
goto cleanup;
}
- free(authType);
- authType = NULL;
+ VIR_FREE(authType);
}
if (ret->source.authType == VIR_STORAGE_POOL_AUTH_CHAP) {
@@ -354,7 +355,7 @@
return ret;
cleanup:
- free(uuid);
+ VIR_FREE(uuid);
xmlFree(type);
virStoragePoolDefFree(ret);
return NULL;
@@ -649,8 +650,11 @@
if (options == NULL)
return NULL;
- if ((ret = calloc(1, sizeof(virStorageVolDef))) == NULL)
+ if (VIR_ALLOC(ret) < 0) {
+ virStorageReportError(conn, VIR_ERR_NO_MEMORY,
+ "%s", _("cannot allocate storage vol"));
return NULL;
+ }
if (STRNEQ((const char *)root->name, "volume")) {
virStorageReportError(conn, VIR_ERR_XML_ERROR,
@@ -677,20 +681,16 @@
}
if (virStorageSize(conn, unit, capacity, &ret->capacity) < 0)
goto cleanup;
- free(capacity);
- capacity = NULL;
- free(unit);
- unit = NULL;
+ VIR_FREE(capacity);
+ VIR_FREE(unit);
allocation = virXPathString("string(/volume/allocation)", ctxt);
if (allocation) {
unit = virXPathString("string(/volume/allocation/@unit)", ctxt);
if (virStorageSize(conn, unit, allocation, &ret->allocation) < 0)
goto cleanup;
- free(allocation);
- allocation = NULL;
- free(unit);
- unit = NULL;
+ VIR_FREE(allocation);
+ VIR_FREE(unit);
} else {
ret->allocation = ret->capacity;
}
@@ -699,10 +699,10 @@
if (options->formatFromString) {
char *format = virXPathString("string(/volume/target/format/@type)", ctxt);
if ((ret->target.format = (options->formatFromString)(conn, format)) < 0) {
- free(format);
+ VIR_FREE(format);
goto cleanup;
}
- free(format);
+ VIR_FREE(format);
}
if (virStorageVolDefParsePerms(conn, ctxt, &ret->target.perms) < 0)
@@ -711,9 +711,9 @@
return ret;
cleanup:
- free(allocation);
- free(capacity);
- free(unit);
+ VIR_FREE(allocation);
+ VIR_FREE(capacity);
+ VIR_FREE(unit);
virStorageVolDefFree(ret);
return NULL;
}
@@ -772,6 +772,7 @@
virStorageVolDefPtr def) {
virStorageBackendVolOptionsPtr options;
virBuffer buf = VIR_BUFFER_INITIALIZER;
+ char *tmp;
options = virStorageBackendVolOptionsForType(pool->type);
if (options == NULL)
@@ -849,7 +850,8 @@
no_memory:
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("xml"));
cleanup:
- free(virBufferContentAndReset(&buf));
+ tmp = virBufferContentAndReset(&buf);
+ VIR_FREE(tmp);
return NULL;
}
@@ -955,7 +957,7 @@
return pool;
}
- if (!(pool = calloc(1, sizeof(virStoragePoolObj)))) {
+ if (VIR_ALLOC(pool) < 0) {
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
"%s", _("pool"));
return NULL;
@@ -1063,7 +1065,7 @@
virStoragePoolObjLoad(driver, entry->d_name, path, xml, autostartLink);
- free(xml);
+ VIR_FREE(xml);
}
closedir(dir);
@@ -1108,15 +1110,13 @@
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot construct "
"autostart link path"));
- free(pool->configFile);
- pool->configFile = NULL;
+ VIR_FREE(pool->configFile);
return -1;
}
if (!(pool->autostartLink = strdup(path))) {
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
"%s", _("config file"));
- free(pool->configFile);
- pool->configFile = NULL;
+ VIR_FREE(pool->configFile);
return -1;
}
}
@@ -1157,7 +1157,7 @@
if (fd != -1)
close(fd);
- free(xml);
+ VIR_FREE(xml);
return ret;
}
diff -r ff6b92c70738 src/storage_driver.c
--- a/src/storage_driver.c Fri May 30 10:36:42 2008 -0400
+++ b/src/storage_driver.c Fri May 30 10:55:44 2008 -0400
@@ -37,7 +37,7 @@
#include "util.h"
#include "storage_driver.h"
#include "storage_conf.h"
-
+#include "memory.h"
#include "storage_backend.h"
#define storageLog(msg...) fprintf(stderr, msg)
@@ -104,9 +104,8 @@
char *base = NULL;
char driverConf[PATH_MAX];
- if (!(driverState = calloc(1, sizeof(virStorageDriverState)))) {
+ if (VIR_ALLOC(driverState) < 0)
return -1;
- }
if (!uid) {
if ((base = strdup (SYSCONF_DIR "/libvirt")) == NULL)
diff -r ff6b92c70738 src/xen_internal.c
--- a/src/xen_internal.c Fri May 30 10:36:42 2008 -0400
+++ b/src/xen_internal.c Fri May 30 10:55:44 2008 -0400
@@ -48,6 +48,7 @@
#include "buf.h"
#include "capabilities.h"
+#include "memory.h"
#define DEBUG(fmt,...) VIR_DEBUG(__FILE__, fmt, __VA_ARGS__)
#define DEBUG0(msg) VIR_DEBUG(__FILE__, "%s", msg)
@@ -223,17 +224,17 @@
#define XEN_GETDOMAININFOLIST_ALLOC(domlist, size) \
(hypervisor_version < 2 ? \
- ((domlist.v0 = malloc(sizeof(*domlist.v0)*(size))) != NULL) : \
+ (VIR_ALLOC_N(domlist.v0, (size)) == 0) : \
(dom_interface_version < 5 ? \
- ((domlist.v2 = malloc(sizeof(*domlist.v2)*(size))) != NULL) : \
- ((domlist.v2d5 = malloc(sizeof(*domlist.v2d5)*(size))) != NULL)))
+ (VIR_ALLOC_N(domlist.v2, (size)) == 0) : \
+ (VIR_ALLOC_N(domlist.v2d5, (size)) == 0)))
-#define XEN_GETDOMAININFOLIST_FREE(domlist) \
- (hypervisor_version < 2 ? \
- free(domlist.v0) : \
- (dom_interface_version < 5 ? \
- free(domlist.v2) : \
- free(domlist.v2d5)))
+#define XEN_GETDOMAININFOLIST_FREE(domlist) \
+ (hypervisor_version < 2 ? \
+ VIR_FREE(domlist.v0) : \
+ (dom_interface_version < 5 ? \
+ VIR_FREE(domlist.v2) : \
+ VIR_FREE(domlist.v2d5)))
#define XEN_GETDOMAININFOLIST_CLEAR(domlist, size) \
(hypervisor_version < 2 ? \
@@ -796,8 +797,7 @@
{
char *msg_s;
- msg_s = malloc (strlen (msg) + 10);
- if (msg_s) {
+ if (VIR_ALLOC_N(msg_s, strlen (msg) + 10) == 0) {
strcpy (msg_s, msg);
strcat (msg_s, ": %s");
}
@@ -1659,8 +1659,7 @@
/* The allocated memory to cpumap must be 'sizeof(uint64_t)' byte *
* for Xen, and also nr_cpus must be 'sizeof(uint64_t) * 8' */
if (maplen < 8) {
- new = calloc(1, sizeof(uint64_t));
- if (!new) {
+ if (VIR_ALLOC_N(new, sizeof(uint64_t)) < 0) {
virXenErrorFunc(NULL, VIR_ERR_NO_MEMORY, __FUNCTION__,
"allocating private data", 0);
return (-1);
@@ -1683,7 +1682,7 @@
op.u.setvcpumapd5.cpumap.nr_cpus = nr_cpus;
}
ret = xenHypervisorDoV2Dom(handle, &op);
- free(new);
+ VIR_FREE(new);
if (unlock_pages(cpumap, maplen) < 0) {
virXenError(NULL, VIR_ERR_XEN_CALL, " release", maplen);
@@ -1985,8 +1984,7 @@
*/
hypervisor_version = 2;
- ipt = malloc(sizeof(*ipt));
- if (ipt == NULL){
+ if (VIR_ALLOC(ipt) < 0) {
virXenError(NULL, VIR_ERR_NO_MEMORY, __FUNCTION__, 0);
return(-1);
}
@@ -2053,13 +2051,13 @@
virXenError(NULL, VIR_ERR_XEN_CALL, " ioctl ", IOCTL_PRIVCMD_HYPERCALL);
close(fd);
in_init = 0;
- free(ipt);
+ VIR_FREE(ipt);
return(-1);
done:
close(fd);
in_init = 0;
- free(ipt);
+ VIR_FREE(ipt);
return(0);
}
@@ -2647,7 +2645,7 @@
ret = virGetDomain(conn, name, XEN_GETDOMAININFO_UUID(dominfo));
if (ret)
ret->id = id;
- free(name);
+ VIR_FREE(name);
return ret;
}
@@ -2714,7 +2712,7 @@
ret = virGetDomain(conn, name, uuid);
if (ret)
ret->id = id;
- free(name);
+ VIR_FREE(name);
return ret;
}
#endif
diff -r ff6b92c70738 src/xen_unified.c
--- a/src/xen_unified.c Fri May 30 10:36:42 2008 -0400
+++ b/src/xen_unified.c Fri May 30 10:55:44 2008 -0400
@@ -40,6 +40,7 @@
#include "xm_internal.h"
#include "xml.h"
#include "util.h"
+#include "memory.h"
#define DEBUG(fmt,...) VIR_DEBUG(__FILE__, fmt,__VA_ARGS__)
#define DEBUG0(msg) VIR_DEBUG(__FILE__, "%s", msg)
@@ -172,15 +173,12 @@
if (xenUnifiedNodeGetInfo(dom->conn, &nodeinfo) < 0)
return(NULL);
- cpulist = calloc(nb_cpu, sizeof(*cpulist));
- if (cpulist == NULL)
+ if (VIR_ALLOC_N(cpulist, nb_cpu) < 0)
goto done;
- cpuinfo = malloc(sizeof(*cpuinfo) * nb_vcpu);
- if (cpuinfo == NULL)
+ if (VIR_ALLOC_N(cpuinfo, nb_vcpu) < 0)
goto done;
cpumaplen = VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo));
- cpumap = (unsigned char *) calloc(nb_vcpu, cpumaplen);
- if (cpumap == NULL)
+ if (VIR_ALLOC_N(cpumap, nb_vcpu * cpumaplen) < 0)
goto done;
if ((ncpus = xenUnifiedDomainGetVcpus(dom, cpuinfo, nb_vcpu,
@@ -202,9 +200,9 @@
}
done:
- free(cpulist);
- free(cpumap);
- free(cpuinfo);
+ VIR_FREE(cpulist);
+ VIR_FREE(cpumap);
+ VIR_FREE(cpuinfo);
return(res);
}
@@ -262,8 +260,7 @@
return VIR_DRV_OPEN_DECLINED;
/* Allocate per-connection private data. */
- priv = calloc (1, sizeof *priv);
- if (!priv) {
+ if (VIR_ALLOC(priv) < 0) {
xenUnifiedError (NULL, VIR_ERR_NO_MEMORY, "allocating private data");
return VIR_DRV_OPEN_ERROR;
}
@@ -342,7 +339,7 @@
DEBUG0("Failed to activate a mandatory sub-driver");
for (i = 0 ; i < XEN_UNIFIED_NR_DRIVERS ; i++)
if (priv->opened[i]) drivers[i]->close(conn);
- free(priv);
+ VIR_FREE(priv);
return VIR_DRV_OPEN_ERROR;
}
@@ -961,7 +958,7 @@
char *cpus, *res;
cpus = xenDomainUsedCpus(dom);
res = xenDaemonDomainDumpXML(dom, flags, cpus);
- free(cpus);
+ VIR_FREE(cpus);
return(res);
}
if (priv->opened[XEN_UNIFIED_PROXY_OFFSET])
diff -r ff6b92c70738 src/xend_internal.c
--- a/src/xend_internal.c Fri May 30 10:36:42 2008 -0400
+++ b/src/xend_internal.c Fri May 30 10:55:44 2008 -0400
@@ -24,7 +24,6 @@
#include <stdbool.h>
#include <math.h>
#include <stdarg.h>
-#include <malloc.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
diff -r ff6b92c70738 src/xmlrpc.c
--- a/src/xmlrpc.c Fri May 30 10:36:42 2008 -0400
+++ b/src/xmlrpc.c Fri May 30 10:55:44 2008 -0400
@@ -12,6 +12,7 @@
#include "xmlrpc.h"
#include "internal.h"
+#include "memory.h"
#include <libxml/nanohttp.h>
@@ -47,9 +48,8 @@
static xmlRpcValuePtr xmlRpcValueNew(xmlRpcValueType type)
{
- xmlRpcValuePtr ret = malloc(sizeof(*ret));
-
- if (!ret)
+ xmlRpcValuePtr ret = NULL;
+ if (VIR_ALLOC(ret) < 0)
xmlRpcError(VIR_ERR_NO_MEMORY, _("allocate value"), sizeof(*ret));
else
ret->kind = type;
@@ -115,7 +115,7 @@
if (ret && value)
ret->value.integer = atoi(value);
- free(value);
+ VIR_FREE(value);
return ret;
}
@@ -130,7 +130,7 @@
ret->value.boolean = true;
else
ret->value.boolean = false;
- free(value);
+ VIR_FREE(value);
return ret;
}
@@ -141,7 +141,7 @@
if (ret && value)
ret->value.real = atof(value);
- free(value);
+ VIR_FREE(value);
return ret;
}
@@ -158,11 +158,10 @@
for (cur = xmlFirstElement(node); cur; cur = xmlNextElement(cur))
n_elements += 1;
- elems = malloc(n_elements * sizeof(*elems));
- if (!elems) {
+ if (VIR_ALLOC_N(elems, n_elements) < 0) {
xmlRpcError(VIR_ERR_NO_MEMORY, _("allocate value array"),
n_elements * sizeof(*elems));
- free(ret);
+ VIR_FREE(ret);
return NULL;
}
n_elements = 0;
@@ -179,10 +178,10 @@
static xmlRpcValueDictElementPtr xmlRpcValueUnmarshalDictElement(xmlNodePtr node)
{
- xmlRpcValueDictElementPtr ret = malloc(sizeof(*ret));
+ xmlRpcValueDictElementPtr ret;
xmlNodePtr cur;
- if (!ret) {
+ if (VIR_ALLOC(ret) < 0) {
xmlRpcError(VIR_ERR_NO_MEMORY, _("allocate dict"), sizeof(*ret));
return NULL;
}
@@ -195,10 +194,10 @@
ret->value = xmlRpcValueUnmarshal(cur);
} else {
xmlRpcError(VIR_ERR_XML_ERROR, _("unexpected dict node"), 0);
- free(ret->name);
+ VIR_FREE(ret->name);
if (ret->value)
xmlRpcValueFree(ret->value);
- free(ret);
+ VIR_FREE(ret);
return NULL;
}
}
@@ -283,26 +282,26 @@
case XML_RPC_ARRAY:
for (i = 0; i < value->value.array.n_elements; i++)
xmlRpcValueFree(value->value.array.elements[i]);
- free(value->value.array.elements);
+ VIR_FREE(value->value.array.elements);
break;
case XML_RPC_STRUCT:
next = value->value.dict.root;
while (next) {
cur = next;
next = next->next;
- free(cur->name);
+ VIR_FREE(cur->name);
xmlRpcValueFree(cur->value);
- free(cur);
+ VIR_FREE(cur);
}
break;
case XML_RPC_STRING:
- free(value->value.string);
+ VIR_FREE(value->value.string);
break;
default:
break;
}
- free(value);
+ VIR_FREE(value);
}
void xmlRpcValueMarshal(xmlRpcValuePtr value, virBufferPtr buf, int indent)
@@ -436,15 +435,14 @@
}
len = xmlNanoHTTPContentLength(cxt);
- response = malloc(len + 1);
- if (response == NULL) {
+ if (VIR_ALLOC_N(response, len + 1) < 0) {
xmlRpcError(VIR_ERR_NO_MEMORY, _("allocate response"), len);
goto error;
}
ret = xmlNanoHTTPRead(cxt, response, len);
if (ret != len) {
errno = EINVAL;
- free(response);
+ VIR_FREE(response);
response = NULL;
xmlRpcError(VIR_ERR_POST_FAILED, _("read response"), 0);
}
@@ -455,7 +453,7 @@
serrno = errno;
if (cxt) {
xmlNanoHTTPClose(cxt);
- free(contentType);
+ VIR_FREE(contentType);
}
errno = serrno;
@@ -477,7 +475,7 @@
if (value->value.array.elements[i]->kind == XML_RPC_STRING)
size += strlen(value->value.array.elements[i]->value.string) + 1;
- if (!(ptr = malloc(size))) {
+ if (VIR_ALLOC_N(ptr, size) < 0) {
xmlRpcError(VIR_ERR_NO_MEMORY, _("allocate string array"), size);
return NULL;
}
@@ -507,7 +505,7 @@
int i;
*argc = strlen(fmt);
- if (!(argv = malloc(sizeof(*argv) * *argc))) {
+ if (VIR_ALLOC_N(argv, *argc) < 0) {
xmlRpcError(VIR_ERR_NO_MEMORY, _("read response"), sizeof(*argv) * *argc);
return NULL;
}
@@ -552,7 +550,7 @@
for (i = 0; i < argc; i++)
xmlRpcValueFree(argv[i]);
- free(argv);
+ VIR_FREE(argv);
}
int xmlRpcCall(xmlRpcContextPtr context, const char *method,
@@ -589,7 +587,7 @@
content = virBufferContentAndReset(&buf);
ret = xmlRpcCallRaw(context->uri, content);
- free(content);
+ VIR_FREE(content);
if (!ret)
return -1;
@@ -597,7 +595,7 @@
xml = xmlReadDoc((const xmlChar *)ret, "response.xml", NULL,
XML_PARSE_NOENT | XML_PARSE_NONET |
XML_PARSE_NOERROR | XML_PARSE_NOWARNING);
- free(ret);
+ VIR_FREE(ret);
if (xml == NULL) {
errno = EINVAL;
@@ -659,13 +657,14 @@
xmlRpcContextPtr xmlRpcContextNew(const char *uri)
{
- xmlRpcContextPtr ret = malloc(sizeof(*ret));
+ xmlRpcContextPtr ret = NULL;
- if (ret) {
+ if (VIR_ALLOC(ret) < 0) {
+ xmlRpcError(VIR_ERR_NO_MEMORY, _("allocate new context"), sizeof(*ret));
+ } else {
ret->uri = strdup(uri);
ret->faultMessage = NULL;
- } else
- xmlRpcError(VIR_ERR_NO_MEMORY, _("allocate new context"), sizeof(*ret));
+ }
return ret;
}
@@ -673,9 +672,9 @@
void xmlRpcContextFree(xmlRpcContextPtr context)
{
if (context) {
- free(context->uri);
- free(context->faultMessage);
- free(context);
+ VIR_FREE(context->uri);
+ VIR_FREE(context->faultMessage);
+ VIR_FREE(context);
}
}
--
|: Red Hat, Engineering, Boston -o- http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
3
5
[libvirt] [PATCH] Add error message when the invalid XML file is defined.
by Hiroyuki Kaguchi 03 Jun '08
by Hiroyuki Kaguchi 03 Jun '08
03 Jun '08
Hi,
When cpuset that is the attribute of vcpu tag of the XML file is the invalid
string, "virsh define" succeeds.
(Ex. <vcpu cpuset='aaa'>4</vcpu>
<vcpu cpuset=' '>4</vcpu>
<vcpu cpuset=',,,'>4</vcpu> )
The patch changes policy that the definition is failed and shows error message.
Thanks,
Signed-off-by: Hiroyuki Kaguchi <fj7025cf(a)aa.jp.fujitsu.com>
Index: src/xm_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/xm_internal.c,v
retrieving revision 1.79
diff -u -p -r1.79 xm_internal.c
--- src/xm_internal.c 29 May 2008 19:20:23 -0000 1.79
+++ src/xm_internal.c 30 May 2008 05:27:35 -0000
@@ -2004,20 +2004,15 @@ virConfPtr xenXMParseXMLToConfig(virConn
char *ranges;
ranges = virConvertCpuSet(conn, cpus, 0);
- if (ranges != NULL) {
- VIR_FREE(cpus);
- if (xenXMConfigSetString(conf, "cpus", ranges) < 0) {
- VIR_FREE(ranges);
- goto error;
- }
+ VIR_FREE(cpus);
+ if (ranges == NULL) {
+ goto error;
+ }
+ if (xenXMConfigSetString(conf, "cpus", ranges) < 0) {
VIR_FREE(ranges);
- } else {
- if (xenXMConfigSetString(conf, "cpus", cpus) < 0) {
- VIR_FREE(cpus);
- goto error;
- }
- VIR_FREE(cpus);
+ goto error;
}
+ VIR_FREE(ranges);
}
obj = xmlXPathEval(BAD_CAST "string(/domain/os/type)", ctxt);
2
1
02 Jun '08
THis patch switches over the remote daemon to use the memory allocation
APIs. This required exporting the 4 apis in the .so. I discovered along
the way that none of the remote RPC dispatcher impls checked for malloc
failure, so I've had to add that in too.
qemud/event.c | 49 +++--------
qemud/mdns.c | 53 ++++++------
qemud/qemud.c | 43 +++++-----
qemud/remote.c | 200 ++++++++++++++++++++++++++++++------------------
src/libvirt_sym.version | 5 +
src/memory.c | 8 -
src/memory.h | 16 +--
7 files changed, 207 insertions(+), 167 deletions(-)
Regards,
Daniel
diff -r 06acc2c5c1fb qemud/event.c
--- a/qemud/event.c Thu May 29 16:05:55 2008 -0400
+++ b/qemud/event.c Fri May 30 10:36:42 2008 -0400
@@ -31,6 +31,7 @@
#include "qemud.h"
#include "event.h"
+#include "memory.h"
#define EVENT_DEBUG(fmt, ...) qemudDebug("EVENT: " fmt, __VA_ARGS__)
@@ -82,16 +83,11 @@
int virEventAddHandleImpl(int fd, int events, virEventHandleCallback cb, void *opaque) {
EVENT_DEBUG("Add handle %d %d %p %p", fd, events, cb, opaque);
if (eventLoop.handlesCount == eventLoop.handlesAlloc) {
- struct virEventHandle *tmp;
EVENT_DEBUG("Used %d handle slots, adding %d more",
eventLoop.handlesAlloc, EVENT_ALLOC_EXTENT);
- tmp = realloc(eventLoop.handles,
- sizeof(struct virEventHandle) *
- (eventLoop.handlesAlloc + EVENT_ALLOC_EXTENT));
- if (!tmp) {
+ if (VIR_REALLOC_N(eventLoop.handles,
+ (eventLoop.handlesAlloc + EVENT_ALLOC_EXTENT)) < 0)
return -1;
- }
- eventLoop.handles = tmp;
eventLoop.handlesAlloc += EVENT_ALLOC_EXTENT;
}
@@ -152,16 +148,11 @@
}
if (eventLoop.timeoutsCount == eventLoop.timeoutsAlloc) {
- struct virEventTimeout *tmp;
EVENT_DEBUG("Used %d timeout slots, adding %d more",
eventLoop.timeoutsAlloc, EVENT_ALLOC_EXTENT);
- tmp = realloc(eventLoop.timeouts,
- sizeof(struct virEventTimeout) *
- (eventLoop.timeoutsAlloc + EVENT_ALLOC_EXTENT));
- if (!tmp) {
+ if (VIR_REALLOC_N(eventLoop.timeouts,
+ (eventLoop.timeoutsAlloc + EVENT_ALLOC_EXTENT)) < 0)
return -1;
- }
- eventLoop.timeouts = tmp;
eventLoop.timeoutsAlloc += EVENT_ALLOC_EXTENT;
}
@@ -281,7 +272,7 @@
}
*retfds = NULL;
/* Setup the poll file handle data structs */
- if (!(fds = malloc(sizeof(*fds) * nfds)))
+ if (VIR_ALLOC_N(fds, nfds) < 0)
return -1;
for (i = 0, nfds = 0 ; i < eventLoop.handlesCount ; i++) {
@@ -398,16 +389,11 @@
/* Release some memory if we've got a big chunk free */
if ((eventLoop.timeoutsAlloc - EVENT_ALLOC_EXTENT) > eventLoop.timeoutsCount) {
- struct virEventTimeout *tmp;
EVENT_DEBUG("Releasing %d out of %d timeout slots used, releasing %d",
eventLoop.timeoutsCount, eventLoop.timeoutsAlloc, EVENT_ALLOC_EXTENT);
- tmp = realloc(eventLoop.timeouts,
- sizeof(struct virEventTimeout) *
- (eventLoop.timeoutsAlloc - EVENT_ALLOC_EXTENT));
- if (!tmp) {
+ if (VIR_REALLOC_N(eventLoop.timeouts,
+ (eventLoop.timeoutsAlloc - EVENT_ALLOC_EXTENT)) < 0)
return -1;
- }
- eventLoop.timeouts = tmp;
eventLoop.timeoutsAlloc -= EVENT_ALLOC_EXTENT;
}
return 0;
@@ -439,16 +425,11 @@
/* Release some memory if we've got a big chunk free */
if ((eventLoop.handlesAlloc - EVENT_ALLOC_EXTENT) > eventLoop.handlesCount) {
- struct virEventHandle *tmp;
EVENT_DEBUG("Releasing %d out of %d handles slots used, releasing %d",
eventLoop.handlesCount, eventLoop.handlesAlloc, EVENT_ALLOC_EXTENT);
- tmp = realloc(eventLoop.handles,
- sizeof(struct virEventHandle) *
- (eventLoop.handlesAlloc - EVENT_ALLOC_EXTENT));
- if (!tmp) {
+ if (VIR_REALLOC_N(eventLoop.handles,
+ (eventLoop.handlesAlloc - EVENT_ALLOC_EXTENT)) < 0)
return -1;
- }
- eventLoop.handles = tmp;
eventLoop.handlesAlloc -= EVENT_ALLOC_EXTENT;
}
return 0;
@@ -466,7 +447,7 @@
return -1;
if (virEventCalculateTimeout(&timeout) < 0) {
- free(fds);
+ VIR_FREE(fds);
return -1;
}
@@ -478,20 +459,20 @@
if (errno == EINTR) {
goto retry;
}
- free(fds);
+ VIR_FREE(fds);
return -1;
}
if (virEventDispatchTimeouts() < 0) {
- free(fds);
+ VIR_FREE(fds);
return -1;
}
if (ret > 0 &&
virEventDispatchHandles(fds) < 0) {
- free(fds);
+ VIR_FREE(fds);
return -1;
}
- free(fds);
+ VIR_FREE(fds);
if (virEventCleanupTimeouts() < 0)
return -1;
diff -r 06acc2c5c1fb qemud/mdns.c
--- a/qemud/mdns.c Thu May 29 16:05:55 2008 -0400
+++ b/qemud/mdns.c Fri May 30 10:36:42 2008 -0400
@@ -42,6 +42,7 @@
#include "mdns.h"
#include "event.h"
#include "remote_internal.h"
+#include "memory.h"
#define AVAHI_DEBUG(fmt, ...) qemudDebug("AVAHI: " fmt, __VA_ARGS__)
@@ -99,7 +100,7 @@
/* A service name collision happened. Let's pick a new name */
n = avahi_alternative_service_name(group->name);
- free(group->name);
+ VIR_FREE(group->name);
group->name = n;
AVAHI_DEBUG("Group name collision, renaming service to '%s'", group->name);
@@ -237,8 +238,8 @@
static AvahiWatch *libvirtd_mdns_watch_new(const AvahiPoll *api ATTRIBUTE_UNUSED,
int fd, AvahiWatchEvent event, AvahiWatchCallback cb, void *userdata) {
- AvahiWatch *w = malloc(sizeof(*w));
- if (!w)
+ AvahiWatch *w;
+ if (VIR_ALLOC(w) < 0)
return NULL;
w->fd = fd;
@@ -248,7 +249,7 @@
AVAHI_DEBUG("New handle %p FD %d Event %d", w, w->fd, event);
if (virEventAddHandleImpl(fd, event, libvirtd_mdns_watch_dispatch, w) < 0) {
- free(w);
+ VIR_FREE(w);
return NULL;
}
@@ -271,7 +272,7 @@
{
AVAHI_DEBUG("Free handle %p %d", w, w->fd);
virEventRemoveHandleImpl(w->fd);
- free(w);
+ VIR_FREE(w);
}
static void libvirtd_mdns_timeout_dispatch(int timer ATTRIBUTE_UNUSED, void *opaque)
@@ -287,15 +288,15 @@
AvahiTimeoutCallback cb,
void *userdata)
{
- AvahiTimeout *t = malloc(sizeof(*t));
+ AvahiTimeout *t;
struct timeval now;
long long nowms, thenms, timeout;
AVAHI_DEBUG("Add timeout %p TV %p", t, tv);
- if (!t)
+ if (VIR_ALLOC(t) < 0)
return NULL;
if (gettimeofday(&now, NULL) < 0) {
- free(t);
+ VIR_FREE(t);
return NULL;
}
@@ -317,7 +318,7 @@
t->userdata = userdata;
if (t->timer < 0) {
- free(t);
+ VIR_FREE(t);
return NULL;
}
@@ -330,7 +331,7 @@
long long nowms, thenms, timeout;
AVAHI_DEBUG("Update timeout %p TV %p", t, tv);
if (gettimeofday(&now, NULL) < 0) {
- free(t);
+ VIR_FREE(t);
return;
}
@@ -351,14 +352,14 @@
{
AVAHI_DEBUG("Free timeout %p", t);
virEventRemoveTimeoutImpl(t->timer);
- free(t);
+ VIR_FREE(t);
}
static AvahiPoll *libvirtd_create_poll(void)
{
- AvahiPoll *p = malloc(sizeof(*p));
- if (!p)
+ AvahiPoll *p;
+ if (VIR_ALLOC(p) < 0)
return NULL;
p->userdata = NULL;
@@ -377,14 +378,13 @@
struct libvirtd_mdns *libvirtd_mdns_new(void)
{
- struct libvirtd_mdns *mdns = malloc(sizeof(*mdns));
- if (!mdns)
+ struct libvirtd_mdns *mdns;
+ if (VIR_ALLOC(mdns) < 0)
return NULL;
- memset(mdns, 0, sizeof(*mdns));
/* Allocate main loop object */
if (!(mdns->poller = libvirtd_create_poll())) {
- free(mdns);
+ VIR_FREE(mdns);
return NULL;
}
@@ -406,15 +406,14 @@
}
struct libvirtd_mdns_group *libvirtd_mdns_add_group(struct libvirtd_mdns *mdns, const char *name) {
- struct libvirtd_mdns_group *group = malloc(sizeof(*group));
+ struct libvirtd_mdns_group *group;
AVAHI_DEBUG("Adding group '%s'", name);
- if (!group)
+ if (VIR_ALLOC(group) < 0)
return NULL;
- memset(group, 0, sizeof(*group));
if (!(group->name = strdup(name))) {
- free(group);
+ VIR_FREE(group);
return NULL;
}
group->mdns = mdns;
@@ -428,12 +427,12 @@
while (tmp) {
if (tmp == group) {
- free(group->name);
+ VIR_FREE(group->name);
if (prev)
prev->next = group->next;
else
group->mdns->group = group->next;
- free(group);
+ VIR_FREE(group);
return;
}
prev = tmp;
@@ -442,15 +441,15 @@
}
struct libvirtd_mdns_entry *libvirtd_mdns_add_entry(struct libvirtd_mdns_group *group, const char *type, int port) {
- struct libvirtd_mdns_entry *entry = malloc(sizeof(*entry));
+ struct libvirtd_mdns_entry *entry;
AVAHI_DEBUG("Adding entry %s %d to group %s", type, port, group->name);
- if (!entry)
+ if (VIR_ALLOC(entry) < 0)
return NULL;
entry->port = port;
if (!(entry->type = strdup(type))) {
- free(entry);
+ VIR_FREE(entry);
return NULL;
}
entry->next = group->entry;
@@ -463,7 +462,7 @@
while (tmp) {
if (tmp == entry) {
- free(entry->type);
+ VIR_FREE(entry->type);
if (prev)
prev->next = entry->next;
else
diff -r 06acc2c5c1fb qemud/qemud.c
--- a/qemud/qemud.c Thu May 29 16:05:55 2008 -0400
+++ b/qemud/qemud.c Fri May 30 10:36:42 2008 -0400
@@ -56,6 +56,7 @@
#include "remote_internal.h"
#include "conf.h"
#include "event.h"
+#include "memory.h"
#ifdef HAVE_AVAHI
#include "mdns.h"
#endif
@@ -466,12 +467,12 @@
static int qemudListenUnix(struct qemud_server *server,
const char *path, int readonly, int auth) {
- struct qemud_socket *sock = calloc(1, sizeof(*sock));
+ struct qemud_socket *sock;
struct sockaddr_un addr;
mode_t oldmask;
gid_t oldgrp;
- if (!sock) {
+ if (VIR_ALLOC(sock) < 0) {
qemudLog(QEMUD_ERR,
"%s", _("Failed to allocate memory for struct qemud_socket"));
return -1;
@@ -611,12 +612,10 @@
struct sockaddr_storage sa;
socklen_t salen = sizeof(sa);
- sock = calloc (1, sizeof *sock);
-
- if (!sock) {
+ if (VIR_ALLOC(sock) < 0) {
qemudLog (QEMUD_ERR,
_("remoteListenTCP: calloc: %s"), strerror (errno));
- return -1;
+ goto cleanup;
}
sock->readonly = 0;
@@ -629,7 +628,7 @@
sock->auth = auth;
if (getsockname(sock->fd, (struct sockaddr *)(&sa), &salen) < 0)
- return -1;
+ goto cleanup;
if (sa.ss_family == AF_INET)
sock->port = htons(((struct sockaddr_in*)&sa)->sin_port);
@@ -642,12 +641,12 @@
if (qemudSetCloseExec(sock->fd) < 0 ||
qemudSetNonBlock(sock->fd) < 0)
- return -1;
+ goto cleanup;
if (listen (sock->fd, 30) < 0) {
qemudLog (QEMUD_ERR,
_("remoteListenTCP: listen: %s"), strerror (errno));
- return -1;
+ goto cleanup;
}
if (virEventAddHandleImpl(sock->fd,
@@ -655,12 +654,17 @@
qemudDispatchServerEvent,
server) < 0) {
qemudLog(QEMUD_ERR, "%s", _("Failed to add server event callback"));
- return -1;
+ goto cleanup;
}
}
return 0;
+
+cleanup:
+ for (i = 0; i < nfds; ++i)
+ close(fds[0]);
+ return -1;
}
static int qemudInitPaths(struct qemud_server *server,
@@ -712,7 +716,7 @@
static struct qemud_server *qemudInitialize(int sigread) {
struct qemud_server *server;
- if (!(server = calloc(1, sizeof(*server)))) {
+ if (VIR_ALLOC(server) < 0) {
qemudLog(QEMUD_ERR, "%s", _("Failed to allocate struct qemud_server"));
return NULL;
}
@@ -1092,8 +1096,7 @@
return -1;
}
- client = calloc(1, sizeof(*client));
- if (client == NULL)
+ if (VIR_ALLOC(client) < 0)
goto cleanup;
client->magic = QEMUD_CLIENT_MAGIC;
client->fd = fd;
@@ -1733,8 +1736,7 @@
switch (p->type) {
case VIR_CONF_STRING:
- list = malloc (2 * sizeof (*list));
- if (list == NULL) {
+ if (VIR_ALLOC_N(list, 2) < 0) {
qemudLog (QEMUD_ERR,
_("failed to allocate memory for %s config list"), key);
return -1;
@@ -1745,7 +1747,7 @@
qemudLog (QEMUD_ERR,
_("failed to allocate memory for %s config list value"),
key);
- free (list);
+ VIR_FREE(list);
return -1;
}
break;
@@ -1755,8 +1757,7 @@
virConfValuePtr pp;
for (pp = p->list; pp; pp = pp->next)
len++;
- list = calloc (1+len, sizeof (*list));
- if (list == NULL) {
+ if (VIR_ALLOC_N(list, 1+len) < 0) {
qemudLog (QEMUD_ERR,
_("failed to allocate memory for %s config list"), key);
return -1;
@@ -1766,15 +1767,15 @@
qemudLog (QEMUD_ERR, _("remoteReadConfigFile: %s: %s:"
" must be a string or list of strings\n"),
filename, key);
- free (list);
+ VIR_FREE(list);
return -1;
}
list[i] = strdup (pp->str);
if (list[i] == NULL) {
int j;
for (j = 0 ; j < i ; j++)
- free (list[j]);
- free (list);
+ VIR_FREE(list[j]);
+ VIR_FREE(list);
qemudLog (QEMUD_ERR, _("failed to allocate memory"
" for %s config list value"), key);
return -1;
diff -r 06acc2c5c1fb qemud/remote.c
--- a/qemud/remote.c Thu May 29 16:05:55 2008 -0400
+++ b/qemud/remote.c Fri May 30 10:36:42 2008 -0400
@@ -50,6 +50,7 @@
#include "internal.h"
#include "qemud.h"
+#include "memory.h"
#define DEBUG 0
@@ -609,14 +610,19 @@
}
/* Allocate return buffer. */
- ret->freeMems.freeMems_val = calloc (args->maxCells, sizeof (*(ret->freeMems.freeMems_val)));
+ if (VIR_ALLOC_N(ret->freeMems.freeMems_val, args->maxCells) < 0) {
+ remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, NULL);
+ return -2;
+ }
ret->freeMems.freeMems_len = virNodeGetCellsFreeMemory(client->conn,
(unsigned long long *)ret->freeMems.freeMems_val,
args->startCell,
args->maxCells);
- if (ret->freeMems.freeMems_len == 0)
+ if (ret->freeMems.freeMems_len == 0) {
+ VIR_FREE(ret->freeMems.freeMems_val);
return -1;
+ }
return 0;
}
@@ -688,15 +694,14 @@
remoteDispatchError (client, req, "%s", _("nparams too large"));
return -2;
}
- params = malloc (sizeof (*params) * nparams);
- if (params == NULL) {
- remoteDispatchError (client, req, "%s", _("out of memory allocating array"));
+ if (VIR_ALLOC_N(params, nparams) < 0) {
+ remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, NULL);
return -2;
}
dom = get_nonnull_domain (client->conn, args->dom);
if (dom == NULL) {
- free (params);
+ VIR_FREE(params);
remoteDispatchError (client, req, "%s", _("domain not found"));
return -2;
}
@@ -704,32 +709,21 @@
r = virDomainGetSchedulerParameters (dom, params, &nparams);
if (r == -1) {
virDomainFree(dom);
- free (params);
+ VIR_FREE(params);
return -1;
}
/* Serialise the scheduler parameters. */
ret->params.params_len = nparams;
- ret->params.params_val = malloc (sizeof (*(ret->params.params_val))
- * nparams);
- if (ret->params.params_val == NULL) {
- virDomainFree(dom);
- free (params);
- remoteDispatchError (client, req,
- "%s", _("out of memory allocating return array"));
- return -2;
- }
+ if (VIR_ALLOC_N(ret->params.params_val, nparams) < 0)
+ goto oom;
for (i = 0; i < nparams; ++i) {
// remoteDispatchClientRequest will free this:
ret->params.params_val[i].field = strdup (params[i].field);
- if (ret->params.params_val[i].field == NULL) {
- virDomainFree(dom);
- free (params);
- remoteDispatchError (client, req,
- "%s", _("out of memory allocating return array"));
- return -2;
- }
+ if (ret->params.params_val[i].field == NULL)
+ goto oom;
+
ret->params.params_val[i].value.type = params[i].type;
switch (params[i].type) {
case VIR_DOMAIN_SCHED_FIELD_INT:
@@ -745,16 +739,23 @@
case VIR_DOMAIN_SCHED_FIELD_BOOLEAN:
ret->params.params_val[i].value.remote_sched_param_value_u.b = params[i].value.b; break;
default:
- virDomainFree(dom);
- free (params);
remoteDispatchError (client, req, "%s", _("unknown type"));
- return -2;
+ goto cleanup;
}
}
virDomainFree(dom);
- free (params);
+ VIR_FREE(params);
return 0;
+
+oom:
+ remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, NULL);
+cleanup:
+ virDomainFree(dom);
+ for (i = 0 ; i < nparams ; i++)
+ VIR_FREE(ret->params.params_val[i].field);
+ VIR_FREE(params);
+ return -2;
}
static int
@@ -775,9 +776,8 @@
remoteDispatchError (client, req, "%s", _("nparams too large"));
return -2;
}
- params = malloc (sizeof (*params) * nparams);
- if (params == NULL) {
- remoteDispatchError (client, req, "%s", _("out of memory allocating array"));
+ if (VIR_ALLOC_N(params, nparams)) {
+ remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, NULL);
return -2;
}
@@ -805,14 +805,14 @@
dom = get_nonnull_domain (client->conn, args->dom);
if (dom == NULL) {
- free (params);
+ VIR_FREE(params);
remoteDispatchError (client, req, "%s", _("domain not found"));
return -2;
}
r = virDomainSetSchedulerParameters (dom, params, nparams);
virDomainFree(dom);
- free (params);
+ VIR_FREE(params);
if (r == -1) return -1;
return 0;
@@ -1190,9 +1190,9 @@
remote_domain_get_vcpus_args *args,
remote_domain_get_vcpus_ret *ret)
{
- virDomainPtr dom;
- virVcpuInfoPtr info;
- unsigned char *cpumaps;
+ virDomainPtr dom = NULL;
+ virVcpuInfoPtr info = NULL;
+ unsigned char *cpumaps = NULL;
int info_len, i;
CHECK_CONN(client);
@@ -1215,20 +1215,25 @@
}
/* Allocate buffers to take the results. */
- info = calloc (args->maxinfo, sizeof (*info));
- cpumaps = calloc (args->maxinfo * args->maplen, sizeof (*cpumaps));
+ if (VIR_ALLOC_N(info, args->maxinfo) < 0)
+ goto oom;
+ if (VIR_ALLOC_N(cpumaps, args->maxinfo) < 0)
+ goto oom;
info_len = virDomainGetVcpus (dom,
info, args->maxinfo,
cpumaps, args->maplen);
if (info_len == -1) {
+ VIR_FREE(info);
+ VIR_FREE(cpumaps);
virDomainFree(dom);
return -1;
}
/* Allocate the return buffer for info. */
ret->info.info_len = info_len;
- ret->info.info_val = calloc (info_len, sizeof (*(ret->info.info_val)));
+ if (VIR_ALLOC_N(ret->info.info_val, info_len) < 0)
+ goto oom;
for (i = 0; i < info_len; ++i) {
ret->info.info_val[i].number = info[i].number;
@@ -1244,8 +1249,16 @@
ret->cpumaps.cpumaps_len = args->maxinfo * args->maplen;
ret->cpumaps.cpumaps_val = (char *) cpumaps;
+ VIR_FREE(info);
virDomainFree(dom);
return 0;
+
+oom:
+ VIR_FREE(info);
+ VIR_FREE(cpumaps);
+ virDomainFree(dom);
+ remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, NULL);
+ return -2;
}
static int
@@ -1267,13 +1280,16 @@
dname = args->dname == NULL ? NULL : *args->dname;
/* Wacky world of XDR ... */
- uri_out = calloc (1, sizeof (*uri_out));
+ if (VIR_ALLOC(uri_out) < 0) {
+ remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, NULL);
+ return -2;
+ }
r = __virDomainMigratePrepare (client->conn, &cookie, &cookielen,
uri_in, uri_out,
args->flags, dname, args->resource);
if (r == -1) {
- free(uri_out);
+ VIR_FREE(uri_out);
return -1;
}
@@ -1284,7 +1300,7 @@
ret->cookie.cookie_val = cookie;
if (*uri_out == NULL) {
ret->uri_out = NULL;
- free(uri_out);
+ VIR_FREE(uri_out);
} else {
ret->uri_out = uri_out;
}
@@ -1361,12 +1377,18 @@
}
/* Allocate return buffer. */
- ret->names.names_val = calloc (args->maxnames, sizeof (*(ret->names.names_val)));
+ if (VIR_ALLOC_N(ret->names.names_val, args->maxnames) < 0) {
+ remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, NULL);
+ return -2;
+ }
ret->names.names_len =
virConnectListDefinedDomains (client->conn,
ret->names.names_val, args->maxnames);
- if (ret->names.names_len == -1) return -1;
+ if (ret->names.names_len == -1) {
+ VIR_FREE(ret->names.names_val);
+ return -1;
+ }
return 0;
}
@@ -1769,12 +1791,18 @@
}
/* Allocate return buffer. */
- ret->names.names_val = calloc (args->maxnames, sizeof (*(ret->names.names_val)));
+ if (VIR_ALLOC_N(ret->names.names_val, args->maxnames) < 0) {
+ remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, NULL);
+ return -2;
+ }
ret->names.names_len =
virConnectListDefinedNetworks (client->conn,
ret->names.names_val, args->maxnames);
- if (ret->names.names_len == -1) return -1;
+ if (ret->names.names_len == -1) {
+ VIR_FREE(ret->names.names_val);
+ return -1;
+ }
return 0;
}
@@ -1795,11 +1823,17 @@
}
/* Allocate return buffer. */
- ret->ids.ids_val = calloc (args->maxids, sizeof (*(ret->ids.ids_val)));
+ if (VIR_ALLOC_N(ret->ids.ids_val, args->maxids) < 0) {
+ remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, NULL);
+ return -2;
+ }
ret->ids.ids_len = virConnectListDomains (client->conn,
ret->ids.ids_val, args->maxids);
- if (ret->ids.ids_len == -1) return -1;
+ if (ret->ids.ids_len == -1) {
+ VIR_FREE(ret->ids.ids_val);
+ return -1;
+ }
return 0;
}
@@ -1820,12 +1854,18 @@
}
/* Allocate return buffer. */
- ret->names.names_val = calloc (args->maxnames, sizeof (*(ret->names.names_val)));
+ if (VIR_ALLOC_N(ret->names.names_val, args->maxnames) < 0) {
+ remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, NULL);
+ return -2;
+ }
ret->names.names_len =
virConnectListNetworks (client->conn,
ret->names.names_val, args->maxnames);
- if (ret->names.names_len == -1) return -1;
+ if (ret->names.names_len == -1) {
+ VIR_FREE(ret->names.names_len);
+ return -1;
+ }
return 0;
}
@@ -2128,8 +2168,8 @@
remote_auth_list_ret *ret)
{
ret->types.types_len = 1;
- if ((ret->types.types_val = calloc (ret->types.types_len, sizeof (*(ret->types.types_val)))) == NULL) {
- remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, "auth types");
+ if (VIR_ALLOC_N(ret->types.types_val, ret->types.types_len) < 0) {
+ remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, NULL);
return -2;
}
ret->types.types_val[0] = client->auth;
@@ -2158,9 +2198,8 @@
return NULL;
}
- addr = malloc(strlen(host) + 1 + strlen(port) + 1);
- if (!addr) {
- remoteDispatchError(client, req, "%s", _("cannot allocate address"));
+ if (VIR_ALLOC_N(addr, strlen(host) + 1 + strlen(port) + 1) < 0) {
+ remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, NULL);
return NULL;
}
@@ -2216,11 +2255,11 @@
if (getpeername(client->fd, (struct sockaddr*)&sa, &salen) < 0) {
remoteDispatchError(client, req, _("failed to get peer address %d (%s)"),
errno, strerror(errno));
- free(localAddr);
+ VIR_FREE(localAddr);
return -2;
}
if ((remoteAddr = addrToString(client, req, &sa, salen)) == NULL) {
- free(localAddr);
+ VIR_FREE(localAddr);
return -2;
}
@@ -2232,8 +2271,8 @@
NULL, /* XXX Callbacks */
SASL_SUCCESS_DATA,
&client->saslconn);
- free(localAddr);
- free(remoteAddr);
+ VIR_FREE(localAddr);
+ VIR_FREE(remoteAddr);
if (err != SASL_OK) {
qemudLog(QEMUD_ERR, _("sasl context setup failed %d (%s)"),
err, sasl_errstring(err, NULL, NULL));
@@ -2477,10 +2516,8 @@
/* NB, distinction of NULL vs "" is *critical* in SASL */
if (serverout) {
- ret->data.data_val = malloc(serveroutlen);
- if (!ret->data.data_val) {
- remoteDispatchError (client, req,
- "%s", _("out of memory allocating array"));
+ if (VIR_ALLOC_N(ret->data.data_val, serveroutlen) < 0) {
+ remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, NULL);
return -2;
}
memcpy(ret->data.data_val, serverout, serveroutlen);
@@ -2558,10 +2595,8 @@
/* NB, distinction of NULL vs "" is *critical* in SASL */
if (serverout) {
- ret->data.data_val = malloc(serveroutlen);
- if (!ret->data.data_val) {
- remoteDispatchError (client, req,
- "%s", _("out of memory allocating array"));
+ if (VIR_ALLOC_N(ret->data.data_val, serveroutlen) < 0) {
+ remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, NULL);
return -2;
}
memcpy(ret->data.data_val, serverout, serveroutlen);
@@ -2778,12 +2813,18 @@
}
/* Allocate return buffer. */
- ret->names.names_val = calloc (args->maxnames, sizeof (char *));
+ if (VIR_ALLOC_N(ret->names.names_val, args->maxnames) < 0) {
+ remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, NULL);
+ return -2;
+ }
ret->names.names_len =
virConnectListDefinedStoragePools (client->conn,
- ret->names.names_val, args->maxnames);
- if (ret->names.names_len == -1) return -1;
+ ret->names.names_val, args->maxnames);
+ if (ret->names.names_len == -1) {
+ VIR_FREE(ret->names.names_val);
+ return -1;
+ }
return 0;
}
@@ -2804,12 +2845,18 @@
}
/* Allocate return buffer. */
- ret->names.names_val = calloc (args->maxnames, sizeof (char *));
+ if (VIR_ALLOC_N(ret->names.names_val, args->maxnames) < 0) {
+ remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, NULL);
+ return -2;
+ }
ret->names.names_len =
virConnectListStoragePools (client->conn,
ret->names.names_val, args->maxnames);
- if (ret->names.names_len == -1) return -1;
+ if (ret->names.names_len == -1) {
+ VIR_FREE(ret->names.names_val);
+ return -1;
+ }
return 0;
}
@@ -3213,13 +3260,20 @@
}
/* Allocate return buffer. */
- ret->names.names_val = calloc (args->maxnames, sizeof (char *));
+ if (VIR_ALLOC_N(ret->names.names_val, args->maxnames) < 0) {
+ virStoragePoolFree(pool);
+ remoteDispatchSendError(client, req, VIR_ERR_NO_MEMORY, NULL);
+ return -2;
+ }
ret->names.names_len =
virStoragePoolListVolumes (pool,
ret->names.names_val, args->maxnames);
virStoragePoolFree(pool);
- if (ret->names.names_len == -1) return -1;
+ if (ret->names.names_len == -1) {
+ VIR_FREE(ret->names.names_val);
+ return -1;
+ }
return 0;
}
diff -r 06acc2c5c1fb src/libvirt_sym.version
--- a/src/libvirt_sym.version Thu May 29 16:05:55 2008 -0400
+++ b/src/libvirt_sym.version Fri May 30 10:36:42 2008 -0400
@@ -190,5 +190,10 @@
__virMacAddrCompare;
+ __virAlloc;
+ __virAllocN;
+ __virReallocN;
+ __virFree;
+
local: *;
};
diff -r 06acc2c5c1fb src/memory.c
--- a/src/memory.c Thu May 29 16:05:55 2008 -0400
+++ b/src/memory.c Fri May 30 10:36:42 2008 -0400
@@ -104,7 +104,7 @@
*
* Returns -1 on failure to allocate, zero on success
*/
-int virAlloc(void *ptrptr, size_t size)
+int __virAlloc(void *ptrptr, size_t size)
{
#if TEST_OOM
if (virAllocTestFail()) {
@@ -137,7 +137,7 @@
*
* Returns -1 on failure to allocate, zero on success
*/
-int virAllocN(void *ptrptr, size_t size, size_t count)
+int __virAllocN(void *ptrptr, size_t size, size_t count)
{
#if TEST_OOM
if (virAllocTestFail()) {
@@ -171,7 +171,7 @@
*
* Returns -1 on failure to allocate, zero on success
*/
-int virReallocN(void *ptrptr, size_t size, size_t count)
+int __virReallocN(void *ptrptr, size_t size, size_t count)
{
void *tmp;
#if TEST_OOM
@@ -203,7 +203,7 @@
* the 'ptrptr' variable. After release, 'ptrptr' will be
* updated to point to NULL.
*/
-void virFree(void *ptrptr)
+void __virFree(void *ptrptr)
{
free(*(void**)ptrptr);
*(void**)ptrptr = NULL;
diff -r 06acc2c5c1fb src/memory.h
--- a/src/memory.h Thu May 29 16:05:55 2008 -0400
+++ b/src/memory.h Fri May 30 10:36:42 2008 -0400
@@ -26,10 +26,10 @@
#include "internal.h"
/* Don't call these directly - use the macros below */
-int virAlloc(void *ptrptr, size_t size) ATTRIBUTE_RETURN_CHECK;
-int virAllocN(void *ptrptr, size_t size, size_t count) ATTRIBUTE_RETURN_CHECK;
-int virReallocN(void *ptrptr, size_t size, size_t count) ATTRIBUTE_RETURN_CHECK;
-void virFree(void *ptrptr);
+int __virAlloc(void *ptrptr, size_t size) ATTRIBUTE_RETURN_CHECK;
+int __virAllocN(void *ptrptr, size_t size, size_t count) ATTRIBUTE_RETURN_CHECK;
+int __virReallocN(void *ptrptr, size_t size, size_t count) ATTRIBUTE_RETURN_CHECK;
+void __virFree(void *ptrptr);
/**
* VIR_ALLOC:
@@ -41,7 +41,7 @@
*
* Returns -1 on failure, 0 on success
*/
-#define VIR_ALLOC(ptr) virAlloc(&(ptr), sizeof(*(ptr)))
+#define VIR_ALLOC(ptr) __virAlloc(&(ptr), sizeof(*(ptr)))
/**
* VIR_ALLOC_N:
@@ -54,7 +54,7 @@
*
* Returns -1 on failure, 0 on success
*/
-#define VIR_ALLOC_N(ptr, count) virAllocN(&(ptr), sizeof(*(ptr)), (count))
+#define VIR_ALLOC_N(ptr, count) __virAllocN(&(ptr), sizeof(*(ptr)), (count))
/**
* VIR_REALLOC_N:
@@ -67,7 +67,7 @@
*
* Returns -1 on failure, 0 on success
*/
-#define VIR_REALLOC_N(ptr, count) virReallocN(&(ptr), sizeof(*(ptr)), (count))
+#define VIR_REALLOC_N(ptr, count) __virReallocN(&(ptr), sizeof(*(ptr)), (count))
/**
* VIR_FREE:
@@ -76,7 +76,7 @@
* Free the memory stored in 'ptr' and update to point
* to NULL.
*/
-#define VIR_FREE(ptr) virFree(&(ptr));
+#define VIR_FREE(ptr) __virFree(&(ptr))
#if TEST_OOM
--
|: Red Hat, Engineering, Boston -o- http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
2
2
02 Jun '08
http://www.redhat.com/archives/libvir-list/2008-May/msg00065.html
> It should really show the autostart
> status when display a 'virsh domiinfo'
I make a patch to show the autostart
status when display a 'virsh dominfo'.
*** autostart status = enable ***
# virsh dominfo guest_dom
Id: -
Name: guest_dom
UUID: 08b6f537-87f5-9617-1d66-cadd223fd4b6
OS Type: linux
State: shut off
CPU(s): 1
Max memory: 262144 kB
Used memory: 262144 kB
Auto Start: enable
^^^^^^^^^^^^^^^^^^^^^^
*** autostart status = disable ***
# virsh dominfo guest_dom
Id: -
Name: guest_dom
UUID: 08b6f537-87f5-9617-1d66-cadd223fd4b6
OS Type: linux
State: shut off
CPU(s): 1
Max memory: 262144 kB
Used memory: 262144 kB
Auto Start: disable
^^^^^^^^^^^^^^^^^^^^^^^
Thanks,
Shigeki Sakamoto.
Index: virsh.c
===================================================================
RCS file: /data/cvs/libvirt/src/virsh.c,v
retrieving revision 1.153
diff -u -p -r1.153 virsh.c
--- virsh.c 23 May 2008 08:24:44 -0000 1.153
+++ virsh.c 26 May 2008 05:59:54 -0000
@@ -1492,7 +1492,7 @@ cmdDominfo(vshControl * ctl, vshCmd * cm
{
virDomainInfo info;
virDomainPtr dom;
- int ret = TRUE;
+ int ret = TRUE, autostart;
unsigned int id;
char *str, uuid[VIR_UUID_STRING_BUFLEN];
@@ -1545,6 +1545,11 @@ cmdDominfo(vshControl * ctl, vshCmd * cm
ret = FALSE;
}
+ if (!virDomainGetAutostart(dom, &autostart)) {
+ vshPrint(ctl, "%-15s %-15s\n", _("Auto Start:"),
+ autostart ? "enable" : "disable" );
+ }
+
virDomainFree(dom);
return ret;
}
5
12
This patch will use a file in the lxc configuration directory to store the tty
forwarding process pid. The pid is stored after the process is fork()'d. It's
loaded during startup when the config for a running container is loaded. The
file is deleted when the domain is undefined. This should avoid "losing" the
tty pid over a libvirtd restart.
--
Best Regards,
Dave Leskovec
IBM Linux Technology Center
Open Virtualization
4
6
[libvirt] [PATCH 3/4] lxc: validate container process during load config
by Dave Leskovec 31 May '08
by Dave Leskovec 31 May '08
31 May '08
This patch adds a check that validates that the container process pid still
exists. This should catch cases where the container exits while libvirtd is down.
--
Best Regards,
Dave Leskovec
IBM Linux Technology Center
Open Virtualization
3
5
[libvirt] [Fwd: Re: [Xen-API] Retrieving XEN Server available and XEN memory]
by Stefan de Konink 31 May '08
by Stefan de Konink 31 May '08
31 May '08
Can we use this for libvirt too? (Free memory for Xen)
Stefan
1
0
[libvirt] AW: AW: [et-mgmt-tools] ocaml-libvirt-0.4.0.1: Can't connect to Xen-Host
by Feichtinger Günter 30 May '08
by Feichtinger Günter 30 May '08
30 May '08
> Von: et-mgmt-tools-bounces(a)redhat.com
> [mailto:et-mgmt-tools-bounces@redhat.com] Im Auftrag von Atsushi SAKAI
> Gesendet: Freitag, 30. Mai 2008 09:42
> An: Fedora/Linux Management Tools
> Betreff: Re: AW: [et-mgmt-tools] ocaml-libvirt-0.4.0.1: Can't
> connect to Xen-Host
>
> Hi, Guenter
>
> Please see following page.
> http://libvirt.org/remote.html
> The section of "Generating TLS certificates"
> answers your question.
Is there any possibility to use it without certificates?
>
> P.S.
> Now I realized.
> ocaml-libvirt should be discussed on libvirt ML.
> https://www.redhat.com/mailman/listinfo/libvir-list
Okay, I change to the libvirt ML...
Thanks,
Guenter
>
> Thanks
> Atsushi SAKAI
>
>
> Feichtinger G
>
> >
> > > Von: et-mgmt-tools-bounces(a)redhat.com
> > > [mailto:et-mgmt-tools-bounces@redhat.com] Im Auftrag von Atsushi
> > > SAKAI
> > > Gesendet: Freitag, 30. Mai 2008 07:16
> > > An: Fedora/Linux Management Tools
> > > Betreff: Re: [et-mgmt-tools] ocaml-libvirt-0.4.0.1: Can't
> connect to
> > > Xen- Host
> > >
> > > Hello,
> > >
> > > You should put on x509 files to that path.
> >
> > I'm sorry, I don't know what x509 files means.
> >
> > Thanks,
> > Guenter
> >
> > >
> > > Thanks
> > > Atsushi SAKAI
> > >
> > > Feichtinger G
> > >
> > > > Hello Richard,
> > > >
> > > > I intstalled the ocaml-libvirt-0.4.0.1.exe on MS- Vista
> > > without problems.
> > > > Also the virt-ctrl.exe starts without problems.
> > > > But when I try to connect to a Xen-Host I get the messages:
> > > > libvir: Remote error : Cannot access CA certificate
> > > > 'C:/msys/1.0/local/etc/pki/C
> > > > A/cacert.pem': No such file or directory (2)
> > > >
> > > > Please be so kind and help.
> > > >
> > > >
> > > > Regard,
> > > > G
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > * From: "Richard W.M. Jones" <rjones redhat com>
> > > > * To: Fedora/Linux Management Tools <et-mgmt-tools
> redhat com>
> > > > * Subject: [et-mgmt-tools] Fwd: OCaml bindings -
> > > Windows installer
> > > > * Date: Tue, 08 Jan 2008 11:18:39 +0000
> > > >
> > > > Might interest some people on this list ...
> > > >
> > > > --- Begin Message ---
> > > >
> > > > * From: "Richard W.M. Jones" <rjones redhat com>
> > > > * To: libvir-list <libvir-list redhat com>
> > > > * Subject: [Libvir] OCaml bindings - Windows installer
> > > > * Date: Tue, 08 Jan 2008 11:15:19 +0000
> > > >
> > > > This is a Windows installer for the OCaml libvirt
> > > bindings and programs:
> > > >
> > > > http://libvirt.org/sources/ocaml/ocaml-libvirt-0.4.0.1.exe
> > > >
> > > > If someone has a 'virgin' Windows system and could test
> > > that the above installer works, particularly for Windows
> < Vista and
> > > for Windows which has not had any GTK/MinGW development tools
> > > installed. About 90% of the size of the installer is down
> to the GTK
> > > DLLs and configuration files which need to be carried along to
> > > support the GTK graphical program (Virt Control). It's
> possible that
> > > I haven't placed the GTK files in exactly the right place, so
> > > instead it is using my own GTK development environment.
> > > >
> > > > Screenshots showing the installer in action:
> > > >
> > > > http://annexia.org/tmp/wininstaller-1-desktop.png
> > > >
> > > > Desktop, nothing installed, showing the installer icon.
> > > >
> > > > http://annexia.org/tmp/wininstaller-2-packages.png
> > > >
> > > > List of required, recommended and optional subpackages.
> > > >
> > > > http://annexia.org/tmp/wininstaller-3-instpath.png
> > > >
> > > > Select the installation path.
> > > >
> > > > http://annexia.org/tmp/wininstaller-4-installdone.png
> > > >
> > > > Install complete. Notice the desktop icons, ...
> > > >
> > > > http://annexia.org/tmp/wininstaller-5-menu.png
> > > >
> > > > ... and the menu entries and uninstaller program.
> > > >
> > > > http://annexia.org/tmp/wininstaller-6-virtctrl.png
> > > >
> > > > Running Virt Control.
> > > >
> > > > http://annexia.org/tmp/wininstaller-7-uninstall.png
> > > >
> > > > After uninstall. Notice that the desktop icons have gone.
> > > >
> > > >
> > > > The installer uses NSIS (the Nullsoft Scriptable
> > > Install System, http://nsis.sf.net/) and is reasonably well
> > > integrated into the autoconf / make build system. In
> particular if
> > > you are compiling under Windows and NSIS is installed,
> then a simple
> > > './configure --with-nsis; make wininstaller' will build a Windows
> > > installer.
> > > >
> > > > This is something to look at if libvirt wants/needs a
> > > Windows installer.
> > > >
> > > > Rich.
> > > >
> > > > --
> > > > Emerging Technologies, Red Hat -
> http://et.redhat.com/~rjones/
> > > > Registered Address: Red Hat UK Ltd, Amberley Place,
> > > 107-111 Peascod
> > > > Street, Windsor, Berkshire, SL4 1TE, United Kingdom.
> > > Registered in
> > > > England and Wales under Company Registration No. 03798903
> > > >
> > > > Attachment: smime.p7s
> > > > Description: S/MIME Cryptographic Signature
> > > >
> > > > --
> > > > Libvir-list mailing list
> > > > Libvir-list redhat com
> > > > https://www.redhat.com/mailman/listinfo/libvir-list
> > > >
> > > >
> > > > --- End Message ---
> > > >
> > > >
> > > >
> > > >
> > > > _______________________________________________
> > > > et-mgmt-tools mailing list
> > > > et-mgmt-tools(a)redhat.com
> > > > https://www.redhat.com/mailman/listinfo/et-mgmt-tools
> > >
> > >
> > > _______________________________________________
> > > et-mgmt-tools mailing list
> > > et-mgmt-tools(a)redhat.com
> > > https://www.redhat.com/mailman/listinfo/et-mgmt-tools
> > >
> >
> > _______________________________________________
> > et-mgmt-tools mailing list
> > et-mgmt-tools(a)redhat.com
> > https://www.redhat.com/mailman/listinfo/et-mgmt-tools
>
>
> _______________________________________________
> et-mgmt-tools mailing list
> et-mgmt-tools(a)redhat.com
> https://www.redhat.com/mailman/listinfo/et-mgmt-tools
>
2
4
30 May '08
This patch ignores ECHILD from waitpid(). This can happen if libvirtd was
restarted and the container processes are no longer the children of libvirtd.
--
Best Regards,
Dave Leskovec
IBM Linux Technology Center
Open Virtualization
2
1
This patch adds a check of the tty forwarding process pid before kill()'ing it
when destroying a domain. If the pid value stored in the the vm structure is
invalid, sending a SIGKILL may be very bad if the value in question is something
like -1 (which just happens to be it's initial value).
--
Best Regards,
Dave Leskovec
IBM Linux Technology Center
Open Virtualization
2
1
This set of patches fixes a few items that occur as a result of a restart of
libvirtd when containers are running. While this may not be a common situation,
the consequences of some of these (particularly losing the tty forwarding
process pid and later trying to kill it) can be quite severe.
--
Best Regards,
Dave Leskovec
IBM Linux Technology Center
Open Virtualization
1
0
Hi, Rich
Fix trailing blanks.
http://builder.virt-manager.org/module-libvirt--devel.html
Thanks
Atsushi SAKAI
3
3
[libvirt] PATCH: Fix python binding for listing storage pools/volumes
by Daniel P. Berrange 28 May '08
by Daniel P. Berrange 28 May '08
28 May '08
The python binding for the APIs to list storage pools and volumes has a
hand written C layer, but an auto-generated python layer. The latter was
auto-generating incorrectly, so this patch overrides its API contract
making the generator work correctly.
Dan.
Index: libvirt-python-api.xml
===================================================================
RCS file: /data/cvs/libvirt/python/libvirt-python-api.xml,v
retrieving revision 1.12
diff -u -r1.12 libvirt-python-api.xml
--- libvirt-python-api.xml 14 Mar 2008 11:08:03 -0000 1.12
+++ libvirt-python-api.xml 23 May 2008 15:15:55 -0000
@@ -110,5 +110,20 @@
<arg name='domain' type='virDomainPtr' info='pointer to domain object'/>
<arg name='params' type='virSchedParameterPtr' info='pointer to scheduler parameter objects'/>
</function>
+ <function name='virConnectListStoragePools' file='python'>
+ <info>list the storage pools, stores the pointers to the names in @names</info>
+ <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/>
+ <return type='str *' info='the list of Names of None in case of error'/>
+ </function>
+ <function name='virConnectListDefinedStoragePools' file='python'>
+ <info>list the defined storage pool, stores the pointers to the names in @names</info>
+ <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/>
+ <return type='str *' info='the list of Names of None in case of error'/>
+ </function>
+ <function name='virStoragePoolListVolumes' file='python'>
+ <info>list the storage volumes, stores the pointers to the names in @names</info>
+ <arg name='pool' type='virStoragePoolPtr' info='pointer to the storage pool'/>
+ <return type='str *' info='the list of Names of None in case of error'/>
+ </function>
</symbols>
</api>
--
|: Red Hat, Engineering, Boston -o- http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
2
3
28 May '08
This patch converts a large amount of the XML parsing/generating code in
the Xen and QEMU drivers over to using the new memory APIs, so we can get
OOM checking of it. In the process I've discovered and fixed a number of
double-free's, and leaks
src/conf.c | 5 -
src/conf.h | 18 ++--
src/qemu_conf.c | 134 +++++++++++++++---------------
src/qemu_driver.c | 114 ++++++++++++-------------
src/test.c | 94 ++++++++++-----------
src/util.c | 11 --
src/xend_internal.c | 127 ++++++++++++++--------------
src/xm_internal.c | 229 +++++++++++++++++++++++++++-------------------------
src/xml.c | 100 +++++++++++-----------
tests/virshtest.c | 23 ++---
10 files changed, 434 insertions(+), 421 deletions(-)
Dan.
diff -r 2069e1bf9132 src/conf.c
--- a/src/conf.c Thu May 22 14:22:39 2008 -0400
+++ b/src/conf.c Thu May 22 17:39:03 2008 -0400
@@ -105,7 +105,6 @@
* Structures allocations and deallocations *
* *
************************************************************************/
-static void virConfFreeValue(virConfValuePtr val);
/**
* virConfFreeList:
@@ -132,8 +131,8 @@
*
* Free a value
*/
-static void
-virConfFreeValue(virConfValuePtr val)
+void
+__virConfFreeValue(virConfValuePtr val)
{
if (val == NULL)
return;
diff -r 2069e1bf9132 src/conf.h
--- a/src/conf.h Thu May 22 14:22:39 2008 -0400
+++ b/src/conf.h Thu May 22 17:39:03 2008 -0400
@@ -70,6 +70,7 @@
virConfPtr __virConfReadMem (const char *memory,
int len);
int __virConfFree (virConfPtr conf);
+void __virConfFreeValue (virConfValuePtr val);
virConfValuePtr __virConfGetValue (virConfPtr conf,
const char *setting);
@@ -82,14 +83,15 @@
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
}
diff -r 2069e1bf9132 src/qemu_conf.c
--- a/src/qemu_conf.c Thu May 22 14:22:39 2008 -0400
+++ b/src/qemu_conf.c Thu May 22 17:39:03 2008 -0400
@@ -122,7 +122,7 @@
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"));
@@ -220,42 +220,42 @@
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);
}
@@ -1418,8 +1418,8 @@
}
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"));
@@ -1427,7 +1427,7 @@
}
if (qemudParseCharXML(conn, chr, i, obj->nodesetval->nodeTab[i]) < 0) {
- free(chr);
+ VIR_FREE(chr);
goto cleanup;
}
if (ndevs)
@@ -1620,7 +1620,7 @@
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;
@@ -1660,8 +1660,7 @@
"%s", _("invalid domain type attribute"));
goto error;
}
- free(prop);
- prop = NULL;
+ VIR_FREE(prop);
/* Extract domain name */
@@ -2033,14 +2032,14 @@
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++;
@@ -2083,8 +2082,8 @@
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"));
@@ -2092,7 +2091,7 @@
}
if (qemudParseCharXML(conn, chr, 0, obj->nodesetval->nodeTab[0]) < 0) {
- free(chr);
+ VIR_FREE(chr);
goto error;
}
def->nserials = 1;
@@ -2108,14 +2107,14 @@
(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++;
@@ -2136,20 +2135,20 @@
(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++;
@@ -2171,17 +2170,17 @@
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;
}
@@ -2194,7 +2193,7 @@
check = check->next;
}
if (collision) {
- free(sound);
+ VIR_FREE(sound);
continue;
}
@@ -2223,8 +2222,7 @@
}
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;
@@ -2242,7 +2240,7 @@
return def;
error:
- free(prop);
+ VIR_FREE(prop);
xmlXPathFreeObject(obj);
xmlXPathFreeContext(ctxt);
qemudFreeVMDef(def);
@@ -2264,7 +2262,6 @@
char *retval = NULL;
int err;
int tapfd = -1;
- int *tapfds;
if (net->type == QEMUD_NET_NETWORK) {
if (!(network = qemudFindNetworkByName(driver, net->dst.network.name))) {
@@ -2321,10 +2318,9 @@
if (!(retval = strdup(tapfdstr)))
goto no_memory;
- if (!(tapfds = realloc(vm->tapfds, sizeof(*tapfds) * (vm->ntapfds+2))))
- goto no_memory;
-
- vm->tapfds = tapfds;
+ if (VIR_ALLOC_N(vm->tapfds, vm->ntapfds+2) < 0)
+ goto no_memory;
+
vm->tapfds[vm->ntapfds++] = tapfd;
vm->tapfds[vm->ntapfds] = -1;
@@ -2334,7 +2330,7 @@
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;
@@ -2831,14 +2827,14 @@
/* 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;
@@ -2870,14 +2866,14 @@
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;
}
@@ -2925,7 +2921,7 @@
if (fd != -1)
close(fd);
- free(xml);
+ VIR_FREE(xml);
return ret;
}
@@ -2937,13 +2933,18 @@
{
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);
@@ -2976,7 +2977,7 @@
error:
if (xml) xmlFreeDoc(xml);
- free(dev);
+ VIR_FREE(dev);
return NULL;
}
@@ -3024,7 +3025,7 @@
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;
@@ -3152,7 +3153,7 @@
cleanup:
- free(xml);
+ VIR_FREE(xml);
return ret;
}
@@ -3161,17 +3162,17 @@
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,
@@ -3224,7 +3225,7 @@
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;
@@ -3244,7 +3245,7 @@
def->ranges = range;
def->nranges++;
} else {
- free(range);
+ VIR_FREE(range);
}
xmlFree(start);
@@ -3315,7 +3316,7 @@
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;
@@ -3489,7 +3490,7 @@
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;
@@ -3700,7 +3701,7 @@
else
qemudLoadNetworkConfig(driver, entry->d_name, path, xml, autostartLink);
- free(xml);
+ VIR_FREE(xml);
}
closedir(dir);
@@ -3836,7 +3837,7 @@
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))) {
@@ -3873,7 +3874,7 @@
goto cleanup;
}
virBufferVSprintf(&buf, " <vcpu cpuset='%s'>%d</vcpu>\n", cpumask, def->vcpus);
- free(cpumask);
+ VIR_FREE(cpumask);
}
if (def->os.bootloader[0])
@@ -4113,7 +4114,8 @@
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;
}
@@ -4124,6 +4126,7 @@
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");
@@ -4188,7 +4191,8 @@
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;
}
diff -r 2069e1bf9132 src/qemu_driver.c
--- a/src/qemu_driver.c Thu May 22 14:22:39 2008 -0400
+++ b/src/qemu_driver.c Thu May 22 17:39:03 2008 -0400
@@ -179,9 +179,8 @@
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;
@@ -229,8 +228,7 @@
base) == -1)
goto out_of_memory;
- free(base);
- base = NULL;
+ VIR_FREE(base);
if ((qemu_driver->caps = qemudCapsInit()) == NULL)
goto out_of_memory;
@@ -256,9 +254,8 @@
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;
}
@@ -361,19 +358,18 @@
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;
}
@@ -702,13 +698,13 @@
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
@@ -757,7 +753,7 @@
"%s", _("resume operation failed"));
return -1;
}
- free(info);
+ VIR_FREE(info);
return 0;
}
@@ -906,16 +902,15 @@
}
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;
}
@@ -1006,8 +1001,7 @@
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) {
@@ -1059,7 +1053,7 @@
(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 { \
@@ -1127,8 +1121,8 @@
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"));
@@ -1156,8 +1150,8 @@
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;
}
@@ -1626,7 +1620,6 @@
for (;;) {
char data[1024];
int got = read(vm->monitor, data, sizeof(data));
- char *b;
if (got == 0)
goto error;
@@ -1637,10 +1630,9 @@
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;
@@ -1674,7 +1666,7 @@
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;
}
@@ -2018,7 +2010,7 @@
}
vm->state = VIR_DOMAIN_PAUSED;
qemudDebug("Reply %s", info);
- free(info);
+ VIR_FREE(info);
return 0;
}
@@ -2046,7 +2038,7 @@
}
vm->state = VIR_DOMAIN_RUNNING;
qemudDebug("Reply %s", info);
- free(info);
+ VIR_FREE(info);
return 0;
}
@@ -2230,7 +2222,7 @@
}
}
- 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++) {
@@ -2339,7 +2331,7 @@
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;
}
@@ -2347,7 +2339,7 @@
qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
"%s", _("failed to write save header"));
close(fd);
- free(xml);
+ VIR_FREE(xml);
return -1;
}
@@ -2355,12 +2347,12 @@
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);
@@ -2374,7 +2366,7 @@
"\"", 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);
@@ -2382,12 +2374,12 @@
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);
@@ -2622,7 +2614,7 @@
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);
@@ -2633,7 +2625,7 @@
qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_FAILED,
"%s", _("failed to read XML"));
close(fd);
- free(xml);
+ VIR_FREE(xml);
return -1;
}
@@ -2642,10 +2634,10 @@
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);
@@ -2688,7 +2680,7 @@
"%s", _("failed to resume domain"));
return -1;
}
- free(info);
+ VIR_FREE(info);
vm->state = VIR_DOMAIN_RUNNING;
}
@@ -2730,7 +2722,7 @@
cleanup:
for (i = 0 ; i < got ; i++)
- free(names[i]);
+ VIR_FREE(names[i]);
return -1;
}
@@ -2830,10 +2822,10 @@
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,
@@ -2844,11 +2836,11 @@
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;
@@ -2881,7 +2873,7 @@
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;
}
@@ -2896,16 +2888,16 @@
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;
}
@@ -3243,7 +3235,7 @@
cleanup:
for (i = 0 ; i < got ; i++)
- free(names[i]);
+ VIR_FREE(names[i]);
return -1;
}
@@ -3271,7 +3263,7 @@
cleanup:
for (i = 0 ; i < got ; i++)
- free(names[i]);
+ VIR_FREE(names[i]);
return -1;
}
diff -r 2069e1bf9132 src/test.c
--- a/src/test.c Thu May 22 14:22:39 2008 -0400
+++ b/src/test.c Thu May 22 17:39:03 2008 -0400
@@ -45,6 +45,7 @@
#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
*/
@@ -275,7 +276,7 @@
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);
@@ -309,30 +310,30 @@
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++) {
@@ -348,7 +349,7 @@
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)
@@ -371,7 +372,7 @@
error:
xmlXPathFreeContext(ctxt);
- free(name);
+ VIR_FREE(name);
return (-1);
}
@@ -464,7 +465,7 @@
testError(conn, NULL, NULL, VIR_ERR_XML_ERROR, _("network uuid"));
goto error;
}
- free(str);
+ VIR_FREE(str);
forward = virXPathBoolean("count(/network/forward) != 0", ctxt);
@@ -512,10 +513,10 @@
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;
}
@@ -524,32 +525,32 @@
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);
}
@@ -601,8 +602,8 @@
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;
}
@@ -677,7 +678,9 @@
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);
@@ -697,8 +700,8 @@
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;
}
@@ -794,7 +797,7 @@
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);
@@ -815,21 +818,21 @@
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;
}
@@ -840,21 +843,21 @@
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;
}
}
@@ -866,13 +869,13 @@
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;
}
@@ -945,7 +948,7 @@
static int testClose(virConnectPtr conn)
{
GET_CONNECTION(conn, -1);
- free (privconn);
+ VIR_FREE (privconn);
conn->privateData = conn;
return 0;
}
@@ -1361,11 +1364,11 @@
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"));
@@ -1419,8 +1422,7 @@
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);
@@ -1435,7 +1437,7 @@
close(fd);
domid = privconn->nextDomID++;
ret = testLoadDomainFromDoc(conn, domid, xml);
- free(xml);
+ VIR_FREE(xml);
return ret < 0 ? -1 : 0;
}
diff -r 2069e1bf9132 src/util.c
--- a/src/util.c Thu May 22 14:22:39 2008 -0400
+++ b/src/util.c Thu May 22 17:39:03 2008 -0400
@@ -48,7 +48,7 @@
#include "event.h"
#include "buf.h"
#include "util.h"
-
+#include "memory.h"
#include "util-lib.c"
#ifndef MIN
@@ -303,19 +303,14 @@
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); */
@@ -359,7 +354,7 @@
}
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;
diff -r 2069e1bf9132 src/xend_internal.c
--- a/src/xend_internal.c Thu May 22 14:22:39 2008 -0400
+++ b/src/xend_internal.c Thu May 22 17:39:03 2008 -0400
@@ -44,6 +44,7 @@
#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>
@@ -630,7 +631,7 @@
content = virBufferContentAndReset(&buf);
ret = http2unix(xend, xend_post(xend, path, content, error, n_error));
- free(content);
+ VIR_FREE(content);
return ret;
}
@@ -825,14 +826,15 @@
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 ' ':
@@ -909,6 +911,7 @@
char *sound_string_to_xml(const char *sound) {
virBuffer buf = VIR_BUFFER_INITIALIZER;
+ char *tmp;
while (sound) {
int modelsize, valid, collision = 0;
@@ -925,15 +928,16 @@
if (STREQ(model, "all")) {
int i;
if (virBufferError(&buf)) {
- free(model);
- goto error;
- }
- free(virBufferContentAndReset(&buf));
+ VIR_FREE(model);
+ goto error;
+ }
+ 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;
}
}
@@ -944,7 +948,7 @@
virBufferVSprintf(&buf, " <sound model='%s'/>\n", model);
sound = (model_end ? ++model_end : NULL);
- free(model);
+ VIR_FREE(model);
}
if (virBufferError(&buf))
@@ -952,7 +956,8 @@
return virBufferContentAndReset(&buf);
error:
- free(virBufferContentAndReset(&buf));
+ tmp = virBufferContentAndReset(&buf);
+ VIR_FREE(tmp);
return NULL;
}
@@ -1092,8 +1097,7 @@
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;
@@ -1149,7 +1153,7 @@
ret = xend_op(xend, "", "op", "create", "config", ptr, NULL);
serrno = errno;
- free(ptr);
+ VIR_FREE(ptr);
errno = serrno;
return ret;
@@ -1250,10 +1254,8 @@
error:
sexpr_free(root);
- if (domname && *domname) {
- free(*domname);
- *domname = NULL;
- }
+ if (domname)
+ VIR_FREE(*domname);
return (-1);
}
@@ -1694,11 +1696,11 @@
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;
}
@@ -1723,7 +1725,7 @@
{
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;
@@ -1906,8 +1908,7 @@
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;
@@ -1925,8 +1926,7 @@
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;
@@ -2004,8 +2004,8 @@
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");
@@ -2191,7 +2191,7 @@
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")) {
@@ -2200,7 +2200,7 @@
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."));
@@ -2221,7 +2221,8 @@
return virBufferContentAndReset(&buf);
error:
- free(virBufferContentAndReset(&buf));
+ val = virBufferContentAndReset(&buf);
+ VIR_FREE(val);
return (NULL);
}
@@ -2379,11 +2380,9 @@
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;
@@ -2423,21 +2422,21 @@
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);
}
@@ -3269,7 +3268,7 @@
}
error:
- sexpr_free(root);
+ sexpr_free(root);
return(ret);
}
@@ -3302,7 +3301,7 @@
}
error:
- sexpr_free(root);
+ sexpr_free(root);
return(ret);
}
#endif /* ! PROXY */
@@ -3331,11 +3330,11 @@
if (ret == NULL) return NULL;
ret->id = id;
- free(name);
+ VIR_FREE(name);
return (ret);
error:
- free(name);
+ VIR_FREE(name);
return (NULL);
}
@@ -3543,7 +3542,7 @@
}
tmp++;
}
- free(names);
+ VIR_FREE(names);
} else { /* New approach for xen >= 3.0.4 */
char *domname = NULL;
char uuidstr[VIR_UUID_STRING_BUFLEN];
@@ -3569,7 +3568,7 @@
if (ret == NULL) return NULL;
ret->id = id;
- free(name);
+ VIR_FREE(name);
return (ret);
}
@@ -3610,14 +3609,14 @@
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;
}
@@ -3633,7 +3632,7 @@
if ((ret = xenDaemonDomainResume(dom)) < 0)
goto error;
- free(name);
+ VIR_FREE(name);
return (dom);
@@ -3643,7 +3642,7 @@
xenDaemonDomainDestroy(dom);
virUnrefDomain(dom);
}
- free(name);
+ VIR_FREE(name);
return (NULL);
}
@@ -3683,7 +3682,7 @@
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);
@@ -3702,7 +3701,7 @@
ret = xend_op(domain->conn, domain->name, "op", "device_configure",
"config", conf, "dev", ref, NULL);
}
- free(sexpr);
+ VIR_FREE(sexpr);
return ret;
}
@@ -3810,7 +3809,7 @@
// 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)) {
@@ -3996,7 +3995,7 @@
"port", port,
"resource", "0", /* required, xend ignores it */
NULL);
- free (hostname);
+ VIR_FREE (hostname);
DEBUG0("migration done");
@@ -4028,14 +4027,14 @@
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;
@@ -4048,7 +4047,7 @@
return (dom);
error:
- free(name);
+ VIR_FREE(name);
return (NULL);
}
int xenDaemonDomainCreate(virDomainPtr domain)
@@ -4318,7 +4317,7 @@
error:
sexpr_free(root);
- free(sched_type);
+ VIR_FREE(sched_type);
return (ret);
}
@@ -4430,7 +4429,7 @@
error:
sexpr_free(root);
- free(sched_type);
+ VIR_FREE(sched_type);
return (ret);
}
diff -r 2069e1bf9132 src/xm_internal.c
--- a/src/xm_internal.c Thu May 22 14:22:39 2008 -0400
+++ b/src/xm_internal.c Thu May 22 17:39:03 2008 -0400
@@ -54,6 +54,7 @@
#include "buf.h"
#include "uuid.h"
#include "util.h"
+#include "memory.h"
static int xenXMConfigSetString(virConfPtr conf, const char *setting,
const char *str);
@@ -241,16 +242,14 @@
/* 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)
@@ -262,10 +261,8 @@
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);
@@ -274,7 +271,7 @@
value->type = VIR_CONF_STRING;
value->str = strdup(uuidstr);
if (!value->str) {
- free(value);
+ VIR_FREE(value);
return (-1);
}
@@ -289,7 +286,7 @@
static void xenXMConfigFree(void *payload, const char *key ATTRIBUTE_UNUSED) {
xenXMConfCachePtr entry = (xenXMConfCachePtr)payload;
virConfFree(entry->conf);
- free(entry);
+ VIR_FREE(entry);
}
@@ -411,7 +408,7 @@
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;
}
@@ -424,7 +421,7 @@
if (!newborn) {
virHashRemoveEntry(configCache, path, NULL);
}
- free(entry);
+ VIR_FREE(entry);
continue;
}
@@ -433,7 +430,7 @@
if (!newborn) {
virHashRemoveEntry(configCache, path, NULL);
}
- free(entry);
+ VIR_FREE(entry);
xenXMError (conn, VIR_ERR_INTERNAL_ERROR,
_("xenXMConfigCacheRefresh: name"));
goto cleanup;
@@ -444,7 +441,7 @@
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;
@@ -458,7 +455,7 @@
if (virHashAddEntry(nameConfigMap, domname, entry->filename) < 0) {
virHashRemoveEntry(configCache, ent->d_name, NULL);
virConfFree(entry->conf);
- free(entry);
+ VIR_FREE(entry);
}
}
}
@@ -674,7 +671,7 @@
ranges = virConvertCpuSet(conn, str, 0);
if (ranges != NULL) {
virBufferVSprintf(&buf, " cpuset='%s'", ranges);
- free(ranges);
+ VIR_FREE(ranges);
} else
virBufferVSprintf(&buf, " cpuset='%s'", str);
}
@@ -1064,7 +1061,7 @@
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."));
@@ -1085,7 +1082,8 @@
return virBufferContentAndReset(&buf);
error:
- free(virBufferContentAndReset(&buf));
+ str = virBufferContentAndReset(&buf);
+ VIR_FREE(str);
return NULL;
}
@@ -1140,7 +1138,7 @@
if (!(entry = virHashLookup(configCache, filename)))
return (-1);
- if (!(value = malloc(sizeof(*value))))
+ if (VIR_ALLOC(value) < 0)
return (-1);
value->type = VIR_CONF_LONG;
@@ -1182,7 +1180,7 @@
if (!(entry = virHashLookup(configCache, filename)))
return (-1);
- if (!(value = malloc(sizeof(*value))))
+ if (VIR_ALLOC(value) < 0)
return (-1);
value->type = VIR_CONF_LONG;
@@ -1255,7 +1253,7 @@
if (!(entry = virHashLookup(configCache, filename)))
return (-1);
- if (!(value = malloc(sizeof(*value))))
+ if (VIR_ALLOC(value) < 0)
return (-1);
value->type = VIR_CONF_LONG;
@@ -1359,8 +1357,8 @@
ret = 0;
cleanup:
- free(mapstr);
- free(ranges);
+ VIR_FREE(mapstr);
+ VIR_FREE(ranges);
return (ret);
}
@@ -1494,13 +1492,13 @@
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);
}
@@ -1531,7 +1529,7 @@
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;
@@ -1546,13 +1544,13 @@
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;
}
@@ -1635,7 +1633,8 @@
ret = 0;
error:
- xmlXPathFreeObject(obj);
+ if (obj)
+ xmlXPathFreeObject(obj);
return ret;
}
@@ -1755,7 +1754,7 @@
buflen += 2; /* mode */
- if (!(buf = malloc(buflen)))
+ if (VIR_ALLOC_N(buf, buflen) < 0)
goto cleanup;
if(source) {
@@ -1884,7 +1883,7 @@
if (ip)
buflen += 4 + strlen((const char*)ip);
- if (!(buf = malloc(buflen)))
+ if (VIR_ALLOC_N(buf, buflen) < 0)
goto cleanup;
strcpy(buf, "mac=");
@@ -1918,7 +1917,7 @@
}
cleanup:
- free(bridge);
+ VIR_FREE(bridge);
xmlFree(mac);
xmlFree(source);
xmlFree(script);
@@ -2007,18 +2006,18 @@
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);
}
}
@@ -2027,6 +2026,7 @@
(obj->stringval != NULL) && STREQ((char*)obj->stringval, "hvm"))
hvm = 1;
xmlXPathFreeObject(obj);
+ obj = NULL;
priv = (xenUnifiedPrivatePtr) conn->privateData;
@@ -2051,6 +2051,7 @@
boot = "d";
}
xmlXPathFreeObject(obj);
+ obj = NULL;
if (xenXMConfigSetString(conf, "boot", boot) < 0)
goto error;
@@ -2073,6 +2074,7 @@
clockLocal = 1;
}
xmlXPathFreeObject(obj);
+ obj = NULL;
if (xenXMConfigSetInt(conf, "localtime", clockLocal) < 0)
goto error;
@@ -2160,7 +2162,7 @@
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;
}
@@ -2192,40 +2194,49 @@
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;
}
@@ -2246,7 +2257,7 @@
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;
}
@@ -2255,11 +2266,14 @@
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;
}
@@ -2278,7 +2292,7 @@
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;
}
@@ -2287,10 +2301,13 @@
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;
}
@@ -2344,10 +2361,10 @@
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);
}
}
@@ -2463,7 +2480,7 @@
goto error;
}
- if (!(entry = calloc(1, sizeof(*entry)))) {
+ if (VIR_ALLOC(entry) < 0) {
xenXMError(conn, VIR_ERR_NO_MEMORY, _("config"));
goto error;
}
@@ -2505,7 +2522,7 @@
return (ret);
error:
- free(entry);
+ VIR_FREE(entry);
if (conf)
virConfFree(conf);
return (NULL);
@@ -2712,7 +2729,7 @@
ret = 0;
cleanup:
- free(domxml);
+ VIR_FREE(domxml);
xmlXPathFreeObject(obj);
xmlXPathFreeContext(ctxt);
if (doc)
@@ -2803,11 +2820,11 @@
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;
@@ -2817,7 +2834,7 @@
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;
@@ -2828,7 +2845,7 @@
prev->next = list_val;
} else {
/* configure */
- free(list_val->str);
+ VIR_FREE(list_val->str);
list_val->str = dev;
}
@@ -2836,9 +2853,9 @@
goto cleanup;
cleanup:
- free(type);
- free(source);
- free(target);
+ VIR_FREE(type);
+ VIR_FREE(source);
+ VIR_FREE(target);
return (ret);
}
@@ -2912,7 +2929,7 @@
if (virMacAddrCompare (dommac, (const char *) mac) == 0) {
if (autoassign) {
- free(mac);
+ VIR_FREE(mac);
mac = NULL;
if (!(mac = (xmlChar *)xenXMAutoAssignMac()))
goto cleanup;
@@ -2929,11 +2946,11 @@
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;
@@ -2948,28 +2965,28 @@
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;
@@ -2989,7 +3006,7 @@
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;
@@ -3000,7 +3017,7 @@
prev->next = list_val;
} else {
/* configure */
- free(list_val->str);
+ VIR_FREE(list_val->str);
list_val->str = dev;
}
@@ -3012,9 +3029,9 @@
xmlFree(attr_node);
xmlFree(text_node);
cleanup:
- free(type);
- free(source);
- free(mac);
+ VIR_FREE(type);
+ VIR_FREE(source);
+ VIR_FREE(mac);
return (ret);
}
@@ -3031,7 +3048,7 @@
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"
@@ -3198,13 +3215,13 @@
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
@@ -3223,9 +3240,9 @@
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);
}
diff -r 2069e1bf9132 src/xml.c
--- a/src/xml.c Thu May 22 14:22:39 2008 -0400
+++ b/src/xml.c Thu May 22 17:39:03 2008 -0400
@@ -28,6 +28,7 @@
#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 */
@@ -276,19 +277,18 @@
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);
}
@@ -311,7 +311,7 @@
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;
@@ -334,7 +334,7 @@
if (!is_sound_model_valid(model)) {
virXMLError(conn, VIR_ERR_XML_ERROR,
_("unknown sound model type"), 0);
- free(model);
+ VIR_FREE(model);
goto error;
}
@@ -347,21 +347,21 @@
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 */
@@ -592,11 +592,11 @@
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));
@@ -1028,7 +1028,7 @@
fdfile = xmlGetProp(cur, BAD_CAST "file");
if (fdfile != NULL) {
virBufferVSprintf(buf, "(fda '%s')", fdfile);
- free(fdfile);
+ VIR_FREE(fdfile);
}
}
@@ -1042,7 +1042,7 @@
fdfile = xmlGetProp(cur, BAD_CAST "file");
if (fdfile != NULL) {
virBufferVSprintf(buf, "(fdb '%s')", fdfile);
- free(fdfile);
+ VIR_FREE(fdfile);
}
}
@@ -1120,7 +1120,7 @@
}
xmlFree(bus);
}
- free(nodes);
+ VIR_FREE(nodes);
nodes = NULL;
}
@@ -1159,19 +1159,19 @@
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);
}
@@ -1533,7 +1533,7 @@
}
virNetworkFree(network);
virBufferVSprintf(buf, "(bridge '%s')", bridge);
- free(bridge);
+ VIR_FREE(bridge);
}
}
if (script != NULL)
@@ -1580,7 +1580,7 @@
{
xmlDocPtr xml = NULL;
xmlNodePtr node;
- char *nam = NULL;
+ char *nam = NULL, *tmp;
virBuffer buf = VIR_BUFFER_INITIALIZER;
xmlChar *prop;
xmlParserCtxtPtr pctxt;
@@ -1677,30 +1677,29 @@
* 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);
- }
+ 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);
}
- free(cpuset);
- if (res < 0)
- goto error;
- } else {
- virXMLError(conn, VIR_ERR_NO_MEMORY, xmldesc, 0);
}
+ 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);
@@ -1711,7 +1710,7 @@
* 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)");
@@ -1728,25 +1727,25 @@
* 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) {
@@ -1812,11 +1811,11 @@
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);
@@ -1827,12 +1826,12 @@
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,
@@ -1844,11 +1843,11 @@
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);
}
}
@@ -1862,7 +1861,7 @@
if (name != NULL)
*name = nam;
else
- free(nam);
+ VIR_FREE(nam);
if (virBufferError(&buf)) {
virXMLError(conn, VIR_ERR_NO_MEMORY, _("allocate buffer"), 0);
@@ -1872,7 +1871,7 @@
return virBufferContentAndReset(&buf);
error:
- free(nam);
+ VIR_FREE(nam);
if (name != NULL)
*name = NULL;
xmlXPathFreeContext(ctxt);
@@ -1880,7 +1879,8 @@
xmlFreeDoc(xml);
if (pctxt != NULL)
xmlFreeParserCtxt(pctxt);
- free(virBufferContentAndReset(&buf));
+ tmp = virBufferContentAndReset(&buf);
+ VIR_FREE(tmp);
return (NULL);
}
diff -r 2069e1bf9132 tests/virshtest.c
--- a/tests/virshtest.c Thu May 22 14:22:39 2008 -0400
+++ b/tests/virshtest.c Thu May 22 17:39:04 2008 -0400
@@ -9,7 +9,7 @@
#include "testutils.h"
static char *progname;
-static char *abs_top_srcdir;
+static char *abs_srcdir;
#define MAX_FILE 4096
static int testFilterLine(char *buffer,
@@ -36,7 +36,7 @@
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;
@@ -271,24 +271,25 @@
-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)",
@@ -355,5 +356,7 @@
1, testCompareDomstateByName, NULL) != 0)
ret = -1;
- exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
+ return(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
+
+VIRT_TEST_MAIN(mymain)
--
|: Red Hat, Engineering, Boston -o- http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
3
2
28 May '08
This patch coverts the virBuffer code over to using our internal memory
allocation wrappers. It then fixes a bug in xend_internal.c where it
was failing to check for allocation failure, although this was technically
completely harmless, since the virBuffer routines already protected
against this specific scenario.
src/buf.c | 16 ++++++----------
src/xend_internal.c | 4 ++++
2 files changed, 10 insertions(+), 10 deletions(-)
Dan
diff -r 797f37ce08c2 src/buf.c
--- a/src/buf.c Wed May 21 22:22:48 2008 -0400
+++ b/src/buf.c Thu May 22 11:42:32 2008 -0400
@@ -21,6 +21,7 @@
#define __VIR_BUFFER_C__
#include "buf.h"
+#include "memory.h"
/* If adding more fields, ensure to edit buf.h to match
@@ -42,8 +43,7 @@
static void
virBufferNoMemory(const virBufferPtr buf)
{
- free(buf->content);
- buf->content = NULL;
+ VIR_FREE(buf->content);
buf->size = 0;
buf->use = 0;
buf->error = 1;
@@ -62,7 +62,6 @@
virBufferGrow(virBufferPtr buf, unsigned int len)
{
int size;
- char *newbuf;
if (buf->error)
return -1;
@@ -72,12 +71,10 @@
size = buf->use + len + 1000;
- newbuf = realloc(buf->content, size);
- if (newbuf == NULL) {
+ if (VIR_REALLOC_N(buf->content, size) < 0) {
virBufferNoMemory(buf);
return -1;
}
- buf->content = newbuf;
buf->size = size;
return 0;
}
@@ -271,8 +268,7 @@
return;
len = strlen(str);
- escaped = malloc(5 * len + 1);
- if (escaped == NULL) {
+ if (VIR_ALLOC_N(escaped, 5 * len + 1) < 0) {
virBufferNoMemory(buf);
return;
}
@@ -316,14 +312,14 @@
buf->content[buf->use] = 0;
grow_size = (count > 1000) ? count : 1000;
if (virBufferGrow(buf, grow_size) < 0) {
- free(escaped);
+ VIR_FREE(escaped);
return;
}
size = buf->size - buf->use - 1;
}
buf->use += count;
buf->content[buf->use] = '\0';
- free(escaped);
+ VIR_FREE(escaped);
}
/**
diff -r 797f37ce08c2 src/xend_internal.c
--- a/src/xend_internal.c Wed May 21 22:22:48 2008 -0400
+++ b/src/xend_internal.c Thu May 22 11:42:32 2008 -0400
@@ -924,6 +924,10 @@
// and build with all available models
if (STREQ(model, "all")) {
int i;
+ if (virBufferError(&buf)) {
+ free(model);
+ goto error;
+ }
free(virBufferContentAndReset(&buf));
for (i=0; i < sizeof(sound_models)/sizeof(*sound_models); ++i)
--
|: Red Hat, Engineering, Boston -o- http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
3
2
28 May '08
This is a pair of patches which deprecate the conn, dom and net fields
in the virterror structure.
Programs which use these fields will get a warning (if compiled under
gcc anyway):
foo.c:123: warning: 'dom' is deprecated (declared at /usr/include/libvirt/virterror.h:81)
The fields themselves are still present and still set, so the ABI
isn't changed.
Now the patch is quite a lot more involved than you might think for
such a simple change. Part of the problem is that we want to allow
libvirt itself to modify these fields without generating a warning.
Therefore the first part of the patch has to refactor all code within
libvirt which includes "libvirt.h" or "virterror.h" (the public
headers) so that instead this code just includes "internal.h".
"internal.h" already includes the public headers. This allows
"internal.h" to undefine the deprecation macro.
Of course nothing is quite so simple. We have two "internal.h" files,
so I renamed the one in the qemud directory to "qemud.h".
I also added something in the HACKING file, stating how *.c files
within libvirt should include header files.
The second part of the patch actually adds the deprecation to the
fields in virterror, and hence is small and simple.
Rich.
--
Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones
virt-p2v converts physical machines to virtual machines. Boot with a
live CD or over the network (PXE) and turn machines into Xen guests.
http://et.redhat.com/~rjones/virt-p2v
5
11
[libvirt] PATCH: 0/4: Add out-of-memory validation to the testsuite
by Daniel P. Berrange 28 May '08
by Daniel P. Berrange 28 May '08
28 May '08
The following series of patches add infrastructure neccessary to let us test
OOM handling for any libvirt code using our malloc wrappers. Currently only
a few places use this, but as this series will show, it already lets us find
several bugs. As we convert more code away from malloc to VIR_MALLOC we'll
get ever improved coverage. Not testing with malloc() directly also means
we avoid having to debug code in libraries we link to. Although obviously
it'd be nice if they had correct OOM handling, that's their job to debug
not ours...
Regards,
Daniel.
--
|: Red Hat, Engineering, Boston -o- http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
3
12
Hi,
I am investigating libvirt to find out whether adding a hypervisor support is possible. I went through libvirt.c and found that all the operations are done through the struct virConnect. But virConnect is not exposed to public. So, if I want to add a minimum support for VMWare and Hyper-V hypervisors, is it possible? If it is possible, how should I proceed.
Thanks,
Amudhan.
2
1
This fixes the sole remaining leak exposed by "make check" vs. valgrind.
Actually it fixes two leaks, but the duplicate sound string one
isn't triggered by the tests.
>From 495abbe5adcb27187f4831a67f0821d62f36602e Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Thu, 22 May 2008 21:34:19 +0200
Subject: [PATCH] plug two sound-related leaks
* src/qemu_conf.c (qemudFreeVMDef): Also free def->sounds.
(qemudParseXML): Avoid leak also for duplicate sound string.
---
src/qemu_conf.c | 10 +++++++++-
1 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/src/qemu_conf.c b/src/qemu_conf.c
index 15bf253..5c20023 100644
--- a/src/qemu_conf.c
+++ b/src/qemu_conf.c
@@ -215,6 +215,7 @@ void qemudFreeVMDef(struct qemud_vm_def *def) {
struct qemud_vm_input_def *input = def->inputs;
struct qemud_vm_chr_def *serial = def->serials;
struct qemud_vm_chr_def *parallel = def->parallels;
+ struct qemud_vm_sound_def *sound = def->sounds;
while (disk) {
struct qemud_vm_disk_def *prev = disk;
@@ -241,6 +242,11 @@ void qemudFreeVMDef(struct qemud_vm_def *def) {
parallel = parallel->next;
free(prev);
}
+ while (sound) {
+ struct qemud_vm_sound_def *prev = sound;
+ sound = sound->next;
+ free(prev);
+ }
xmlFree(def->keymap);
free(def);
}
@@ -2187,8 +2193,10 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
}
check = check->next;
}
- if (collision)
+ if (collision) {
+ free(sound);
continue;
+ }
def->nsounds++;
sound->next = NULL;
--
1.5.5.1.249.g26848
2
2
Thanks & Regards
--Ajish
2
1