* is supposed to pass the ABI name and not the domain
* operating system driver as I had imagined ;)
*/
- char *osType = strdup("hvm");
-
- if (osType == NULL)
- virReportOOMError();
+ char *osType;
+ ignore_value(VIR_STRDUP(osType, "hvm"));
return osType;
}
def->virtType = VIR_DOMAIN_VIRT_VBOX;
def->id = dom->id;
memcpy(def->uuid, dom->uuid, VIR_UUID_BUFLEN);
- def->name = strdup(dom->name);
+ if (VIR_STRDUP(def->name, dom->name) < 0)
+ goto cleanup;
machine->vtbl->GetMemorySize(machine, &memorySize);
def->mem.cur_balloon = memorySize * 1024;
/* Skip cpumasklen, cpumask, onReboot, onPoweroff, onCrash */
- def->os.type = strdup("hvm");
+ if (VIR_STRDUP(def->os.type, "hvm") < 0)
+ goto cleanup;
def->os.arch = virArchFromHost();
if (STREQ(valueTypeUtf8, "sdl")) {
sdlPresent = 1;
- if (valueDisplayUtf8)
- sdlDisplay = strdup(valueDisplayUtf8);
- if (sdlDisplay == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(sdlDisplay, valueDisplayUtf8) < 0) {
/* just don't go to cleanup yet as it is ok to have
* sdlDisplay as NULL and we check it below if it
* exist and then only use it there
if (STREQ(valueTypeUtf8, "gui")) {
guiPresent = 1;
- if (valueDisplayUtf8)
- guiDisplay = strdup(valueDisplayUtf8);
- if (guiDisplay == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(guiDisplay, valueDisplayUtf8) < 0) {
/* just don't go to cleanup yet as it is ok to have
* guiDisplay as NULL and we check it below if it
* exist and then only use it there
if (VIR_ALLOC(def->graphics[def->ngraphics]) >= 0) {
def->graphics[def->ngraphics]->type = VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP;
tmp = getenv("DISPLAY");
- if (tmp != NULL) {
- def->graphics[def->ngraphics]->data.desktop.display = strdup(tmp);
- if (def->graphics[def->ngraphics]->data.desktop.display == NULL) {
- virReportOOMError();
- /* just don't go to cleanup yet as it is ok to have
- * display as NULL
- */
- }
+ if (VIR_STRDUP(def->graphics[def->ngraphics]->data.desktop.display, tmp) < 0) {
+ /* just don't go to cleanup yet as it is ok to have
+ * display as NULL
+ */
}
totalPresent++;
def->ngraphics++;
if (hddType == HardDiskType_Immutable)
def->disks[hddNum]->readonly = true;
- def->disks[hddNum]->src = strdup(hddlocation);
- def->disks[hddNum]->dst = strdup("hda");
+ ignore_value(VIR_STRDUP(def->disks[hddNum]->src, hddlocation));
+ ignore_value(VIR_STRDUP(def->disks[hddNum]->dst, "hda"));
hddNum++;
VBOX_UTF8_FREE(hddlocation);
if (hddType == HardDiskType_Immutable)
def->disks[hddNum]->readonly = true;
- def->disks[hddNum]->src = strdup(hddlocation);
- def->disks[hddNum]->dst = strdup("hdb");
+ ignore_value(VIR_STRDUP(def->disks[hddNum]->src, hddlocation));
+ ignore_value(VIR_STRDUP(def->disks[hddNum]->dst, "hdb"));
hddNum++;
VBOX_UTF8_FREE(hddlocation);
if (hddType == HardDiskType_Immutable)
def->disks[hddNum]->readonly = true;
- def->disks[hddNum]->src = strdup(hddlocation);
- def->disks[hddNum]->dst = strdup("hdd");
- hddNum++;
+ if (VIR_STRDUP_QUIET(def->disks[hddNum]->src, hddlocation) == 0 &&
+ VIR_STRDUP_QUIET(def->disks[hddNum]->dst, "hdd") == 0)
+ hddNum++;
VBOX_UTF8_FREE(hddlocation);
VBOX_UTF16_FREE(hddlocationUtf16);
medium->vtbl->GetLocation(medium, &mediumLocUtf16);
VBOX_UTF16_TO_UTF8(mediumLocUtf16, &mediumLocUtf8);
VBOX_UTF16_FREE(mediumLocUtf16);
- def->disks[diskCount]->src = strdup(mediumLocUtf8);
+ ignore_value(VIR_STRDUP(def->disks[diskCount]->src, mediumLocUtf8));
VBOX_UTF8_FREE(mediumLocUtf8);
if (!(def->disks[diskCount]->src)) {
sharedFolder->vtbl->GetHostPath(sharedFolder, &hostPathUtf16);
VBOX_UTF16_TO_UTF8(hostPathUtf16, &hostPath);
- def->fss[i]->src = strdup(hostPath);
- VBOX_UTF8_FREE(hostPath);
- VBOX_UTF16_FREE(hostPathUtf16);
-
- if (def->fss[i]->src == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(def->fss[i]->src, hostPath) < 0) {
+ VBOX_UTF8_FREE(hostPath);
+ VBOX_UTF16_FREE(hostPathUtf16);
goto sharedFoldersCleanup;
}
+ VBOX_UTF8_FREE(hostPath);
+ VBOX_UTF16_FREE(hostPathUtf16);
sharedFolder->vtbl->GetName(sharedFolder, &nameUtf16);
VBOX_UTF16_TO_UTF8(nameUtf16, &name);
- def->fss[i]->dst = strdup(name);
- VBOX_UTF8_FREE(name);
- VBOX_UTF16_FREE(nameUtf16);
-
- if (def->fss[i]->dst == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(def->fss[i]->dst, name) < 0) {
+ VBOX_UTF8_FREE(name);
+ VBOX_UTF16_FREE(nameUtf16);
goto sharedFoldersCleanup;
}
+ VBOX_UTF8_FREE(name);
+ VBOX_UTF16_FREE(nameUtf16);
sharedFolder->vtbl->GetWritable(sharedFolder, &writable);
def->fss[i]->readonly = !writable;
#endif /* VBOX_API_VERSION >= 4001 */
VBOX_UTF16_TO_UTF8(hostIntUtf16, &hostInt);
- def->nets[netAdpIncCnt]->data.bridge.brname = strdup(hostInt);
+ ignore_value(VIR_STRDUP(def->nets[netAdpIncCnt]->data.bridge.brname, hostInt));
VBOX_UTF8_FREE(hostInt);
VBOX_UTF16_FREE(hostIntUtf16);
adapter->vtbl->GetInternalNetwork(adapter, &intNetUtf16);
VBOX_UTF16_TO_UTF8(intNetUtf16, &intNet);
- def->nets[netAdpIncCnt]->data.internal.name = strdup(intNet);
+ ignore_value(VIR_STRDUP(def->nets[netAdpIncCnt]->data.internal.name, intNet));
VBOX_UTF8_FREE(intNet);
VBOX_UTF16_FREE(intNetUtf16);
#endif /* VBOX_API_VERSION >= 4001 */
VBOX_UTF16_TO_UTF8(hostIntUtf16, &hostInt);
- def->nets[netAdpIncCnt]->data.network.name = strdup(hostInt);
+ ignore_value(VIR_STRDUP(def->nets[netAdpIncCnt]->data.network.name, hostInt));
VBOX_UTF8_FREE(hostInt);
VBOX_UTF16_FREE(hostIntUtf16);
adapter->vtbl->GetAdapterType(adapter, &adapterType);
if (adapterType == NetworkAdapterType_Am79C970A) {
- def->nets[netAdpIncCnt]->model = strdup("Am79C970A");
+ ignore_value(VIR_STRDUP(def->nets[netAdpIncCnt]->model, "Am79C970A"));
} else if (adapterType == NetworkAdapterType_Am79C973) {
- def->nets[netAdpIncCnt]->model = strdup("Am79C973");
+ ignore_value(VIR_STRDUP(def->nets[netAdpIncCnt]->model, "Am79C973"));
} else if (adapterType == NetworkAdapterType_I82540EM) {
- def->nets[netAdpIncCnt]->model = strdup("82540EM");
+ ignore_value(VIR_STRDUP(def->nets[netAdpIncCnt]->model, "82540EM"));
} else if (adapterType == NetworkAdapterType_I82545EM) {
- def->nets[netAdpIncCnt]->model = strdup("82545EM");
+ ignore_value(VIR_STRDUP(def->nets[netAdpIncCnt]->model, "82545EM"));
} else if (adapterType == NetworkAdapterType_I82543GC) {
- def->nets[netAdpIncCnt]->model = strdup("82543GC");
+ ignore_value(VIR_STRDUP(def->nets[netAdpIncCnt]->model, "82543GC"));
#if VBOX_API_VERSION >= 3001
} else if (adapterType == NetworkAdapterType_Virtio) {
- def->nets[netAdpIncCnt]->model = strdup("virtio");
+ ignore_value(VIR_STRDUP(def->nets[netAdpIncCnt]->model, "virtio"));
#endif /* VBOX_API_VERSION >= 3001 */
}
def->disks[def->ndisks - 1]->bus = VIR_DOMAIN_DISK_BUS_IDE;
def->disks[def->ndisks - 1]->type = VIR_DOMAIN_DISK_TYPE_FILE;
def->disks[def->ndisks - 1]->readonly = true;
- def->disks[def->ndisks - 1]->src = strdup(location);
- def->disks[def->ndisks - 1]->dst = strdup("hdc");
+ ignore_value(VIR_STRDUP(def->disks[def->ndisks - 1]->src, location));
+ ignore_value(VIR_STRDUP(def->disks[def->ndisks - 1]->dst, "hdc"));
+ def->ndisks--;
} else {
def->ndisks--;
virReportOOMError();
def->disks[def->ndisks - 1]->bus = VIR_DOMAIN_DISK_BUS_FDC;
def->disks[def->ndisks - 1]->type = VIR_DOMAIN_DISK_TYPE_FILE;
def->disks[def->ndisks - 1]->readonly = false;
- def->disks[def->ndisks - 1]->src = strdup(location);
- def->disks[def->ndisks - 1]->dst = strdup("fda");
+ ignore_value(VIR_STRDUP(def->disks[def->ndisks - 1]->src, location));
+ ignore_value(VIR_STRDUP(def->disks[def->ndisks - 1]->dst, "fda"));
+ def->ndisks--;
} else {
def->ndisks--;
virReportOOMError();
if (pathUtf16) {
VBOX_UTF16_TO_UTF8(pathUtf16, &path);
- def->serials[serialPortIncCount]->source.data.file.path = strdup(path);
+ ignore_value(VIR_STRDUP(def->serials[serialPortIncCount]->source.data.file.path, path));
}
serialPortIncCount++;
parallelPort->vtbl->GetPath(parallelPort, &pathUtf16);
VBOX_UTF16_TO_UTF8(pathUtf16, &path);
- def->parallels[parallelPortIncCount]->source.data.file.path = strdup(path);
+ ignore_value(VIR_STRDUP(def->parallels[parallelPortIncCount]->source.data.file.path, path));
parallelPortIncCount++;
(state > MachineState_LastOnline)) {
machine->vtbl->GetName(machine, &machineNameUtf16);
VBOX_UTF16_TO_UTF8(machineNameUtf16, &machineName);
- names[j] = strdup(machineName);
- VBOX_UTF16_FREE(machineNameUtf16);
- VBOX_UTF8_FREE(machineName);
- if (!names[j]) {
- virReportOOMError();
+ if (VIR_STRDUP(names[j], machineName) < 0) {
+ VBOX_UTF16_FREE(machineNameUtf16);
+ VBOX_UTF8_FREE(machineName);
for (; j >= 0 ; j--)
VIR_FREE(names[j]);
ret = -1;
goto cleanup;
}
+ VBOX_UTF16_FREE(machineNameUtf16);
+ VBOX_UTF8_FREE(machineName);
j++;
ret++;
}
if (STREQ(valueTypeUtf8, "sdl")) {
sdlPresent = 1;
- if (valueDisplayUtf8) {
- sdlDisplay = strdup(valueDisplayUtf8);
- if (sdlDisplay == NULL) {
- virReportOOMError();
- /* just don't go to cleanup yet as it is ok to have
- * sdlDisplay as NULL and we check it below if it
- * exist and then only use it there
- */
- }
+ if (VIR_STRDUP(sdlDisplay, valueDisplayUtf8) < 0) {
+ /* just don't go to cleanup yet as it is ok to have
+ * sdlDisplay as NULL and we check it below if it
+ * exist and then only use it there
+ */
}
}
if (STREQ(valueTypeUtf8, "gui")) {
guiPresent = 1;
- if (valueDisplayUtf8) {
- guiDisplay = strdup(valueDisplayUtf8);
- if (guiDisplay == NULL) {
- virReportOOMError();
- /* just don't go to cleanup yet as it is ok to have
- * guiDisplay as NULL and we check it below if it
- * exist and then only use it there
- */
- }
+ if (VIR_STRDUP(guiDisplay, valueDisplayUtf8) < 0) {
+ /* just don't go to cleanup yet as it is ok to have
+ * guiDisplay as NULL and we check it below if it
+ * exist and then only use it there
+ */
}
}
}
PRInt32 device = 0;
PRUnichar *hddcnameUtf16 = NULL;
- char *hddcname = strdup("IDE");
+ char *hddcname;
+ ignore_value(VIR_STRDUP(hddcname, "IDE"));
VBOX_UTF8_TO_UTF16(hddcname, &hddcnameUtf16);
VIR_FREE(hddcname);
if ((def->graphics[i]->type == VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP) &&
(guiPresent == 0)) {
guiPresent = 1;
- if (def->graphics[i]->data.desktop.display) {
- guiDisplay = strdup(def->graphics[i]->data.desktop.display);
- if (guiDisplay == NULL) {
- virReportOOMError();
- /* just don't go to cleanup yet as it is ok to have
- * guiDisplay as NULL and we check it below if it
- * exist and then only use it there
- */
- }
+ if (VIR_STRDUP(guiDisplay, def->graphics[i]->data.desktop.display) < 0) {
+ /* just don't go to cleanup yet as it is ok to have
+ * guiDisplay as NULL and we check it below if it
+ * exist and then only use it there
+ */
}
}
if ((def->graphics[i]->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL) &&
(sdlPresent == 0)) {
sdlPresent = 1;
- if (def->graphics[i]->data.sdl.display) {
- sdlDisplay = strdup(def->graphics[i]->data.sdl.display);
- if (sdlDisplay == NULL) {
- virReportOOMError();
- /* just don't go to cleanup yet as it is ok to have
- * sdlDisplay as NULL and we check it below if it
- * exist and then only use it there
- */
- }
+ if (VIR_STRDUP(sdlDisplay, def->graphics[i]->data.sdl.display) < 0) {
+ /* just don't go to cleanup yet as it is ok to have
+ * sdlDisplay as NULL and we check it below if it
+ * exist and then only use it there
+ */
}
}
}
{
PRUnichar *hddcnameUtf16 = NULL;
- char *hddcname = strdup("IDE");
+ char *hddcname;
+ ignore_value(VIR_STRDUP(hddcname, "IDE"));
VBOX_UTF8_TO_UTF16(hddcname, &hddcnameUtf16);
VIR_FREE(hddcname);
return ret;
}
- def->os.type = strdup("hvm");
-
- if (def->os.type == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(def->os.type, "hvm") < 0)
goto cleanup;
- }
dev = virDomainDeviceDefParse(xml, def, data->caps, data->xmlopt,
VIR_DOMAIN_XML_INACTIVE);
return ret;
}
- def->os.type = strdup("hvm");
-
- if (def->os.type == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(def->os.type, "hvm") < 0)
goto cleanup;
- }
dev = virDomainDeviceDefParse(xml, def, data->caps, data->xmlopt,
VIR_DOMAIN_XML_INACTIVE);
if (!(snap = vboxDomainSnapshotGet(data, dom, machine, snapshot->name)))
goto cleanup;
- if (VIR_ALLOC(def) < 0
- || !(def->name = strdup(snapshot->name)))
+ if (VIR_ALLOC(def) < 0)
goto no_memory;
+ if (VIR_STRDUP(def->name, snapshot->name) < 0)
+ goto cleanup;
rc = snap->vtbl->GetDescription(snap, &str16);
if (NS_FAILED(rc)) {
if (str16) {
VBOX_UTF16_TO_UTF8(str16, &str8);
VBOX_UTF16_FREE(str16);
- def->description = strdup(str8);
+ if (VIR_STRDUP(def->description, str8) < 0) {
+ VBOX_UTF8_FREE(str8);
+ goto cleanup;
+ }
VBOX_UTF8_FREE(str8);
- if (!def->description)
- goto no_memory;
}
rc = snap->vtbl->GetTimeStamp(snap, ×tamp);
}
VBOX_UTF16_TO_UTF8(str16, &str8);
VBOX_UTF16_FREE(str16);
- def->parent = strdup(str8);
- VBOX_UTF8_FREE(str8);
- if (!def->parent)
+ if (VIR_STRDUP(def->parent, str8) < 0) {
+ VBOX_UTF8_FREE(str8);
goto no_memory;
+ }
+ VBOX_UTF8_FREE(str8);
}
rc = snap->vtbl->GetOnline(snap, &online);
}
VBOX_UTF16_TO_UTF8(nameUtf16, &name);
VBOX_UTF16_FREE(nameUtf16);
- names[i] = strdup(name);
- VBOX_UTF8_FREE(name);
- if (!names[i]) {
+ if (VIR_STRDUP(names[i], name) < 0) {
virReportOOMError();
+ VBOX_UTF8_FREE(name);
goto cleanup;
}
+ VBOX_UTF8_FREE(name);
}
if (count <= nameslen)
VBOX_UTF16_TO_UTF8(nameUtf16, &nameUtf8);
VIR_DEBUG("nnames[%d]: %s", ret, nameUtf8);
- names[ret] = strdup(nameUtf8);
- if (names[ret] == NULL) {
- virReportOOMError();
- } else {
+ if (VIR_STRDUP(names[ret], nameUtf8) == 0)
ret++;
- }
VBOX_UTF8_FREE(nameUtf8);
VBOX_UTF16_FREE(nameUtf16);
VBOX_UTF16_TO_UTF8(nameUtf16, &nameUtf8);
VIR_DEBUG("nnames[%d]: %s", ret, nameUtf8);
- names[ret] = strdup(nameUtf8);
- if (names[ret] == NULL) {
- virReportOOMError();
- } else {
+ if (VIR_STRDUP(names[ret], nameUtf8) == 0)
ret++;
- }
VBOX_UTF8_FREE(nameUtf8);
VBOX_UTF16_FREE(nameUtf16);
networkInterface->vtbl->GetInterfaceType(networkInterface, &interfaceType);
if (interfaceType == HostNetworkInterfaceType_HostOnly) {
- def->name = strdup(network->name);
- if (def->name != NULL) {
+ if (VIR_STRDUP(def->name, network->name) == 0) {
PRUnichar *networkNameUtf16 = NULL;
IDHCPServer *dhcpServer = NULL;
vboxIID vboxnet0IID = VBOX_IID_INITIALIZER;
ipdef->nhosts = 1;
if (VIR_ALLOC_N(ipdef->hosts, ipdef->nhosts) >=0) {
- ipdef->hosts[0].name = strdup(network->name);
- if (ipdef->hosts[0].name == NULL) {
+ if (VIR_STRDUP(ipdef->hosts[0].name, network->name) < 0) {
VIR_FREE(ipdef->hosts);
ipdef->nhosts = 0;
- virReportOOMError();
} else {
PRUnichar *macAddressUtf16 = NULL;
PRUnichar *ipAddressUtf16 = NULL;
char **const names, int nnames) {
int numActive = 0;
- if (nnames == 1) {
- names[numActive] = strdup("default-pool");
- if (names[numActive] == NULL) {
- virReportOOMError();
- } else {
- numActive++;
- }
- }
+ if (nnames == 1 &&
+ VIR_STRDUP(names[numActive], "default-pool") > 0)
+ numActive++;
return numActive;
}
if (nameUtf8) {
VIR_DEBUG("nnames[%d]: %s", numActive, nameUtf8);
- names[numActive] = strdup(nameUtf8);
- if (names[numActive] == NULL) {
- virReportOOMError();
- } else {
+ if (VIR_STRDUP(names[numActive], nameUtf8) > 0)
numActive++;
- }
VBOX_UTF8_FREE(nameUtf8);
}
else
defOk = 0;
- def.name = strdup(vol->name);
- if (!(def.name && defOk))
+ if (VIR_STRDUP(def.name, vol->name) < 0)
defOk = 0;
- def.key = strdup(vol->key);
- if (!(def.key && defOk))
+ if (VIR_STRDUP(def.key, vol->key) < 0)
defOk = 0;
rc = hardDisk->vtbl->GetFormat(hardDisk, &hddFormatUtf16);
VBOX_UTF16_TO_UTF8(hddLocationUtf16, &hddLocationUtf8);
if (hddLocationUtf8) {
- ret = strdup(hddLocationUtf8);
- if (!ret)
- virReportOOMError();
+ ignore_value(VIR_STRDUP(ret, hddLocationUtf8));
VIR_DEBUG("Storage Volume Name: %s", vol->name);
VIR_DEBUG("Storage Volume Path: %s", hddLocationUtf8);
goto endjob;
}
+ if (VIR_STRDUP(ret, "image/png") < 0)
+ goto endjob;
+
if (virFDStreamOpenFile(st, tmp, 0, 0, O_RDONLY) < 0) {
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
_("unable to open stream"));
- goto endjob;
+ VIR_FREE(ret);
}
-
- ret = strdup("image/png");
-
endjob:
VIR_FREE(screenData);
VBOX_RELEASE(display);