---
src/conf/capabilities.c | 30 +++++--------
src/conf/cpu_conf.c | 19 ++++----
src/conf/domain_conf.c | 105 ++++++++++++++------------------------------
src/conf/domain_event.c | 39 ++++++++--------
src/conf/node_device_conf.c | 29 ++++++------
src/conf/nwfilter_conf.c | 17 ++-----
src/conf/nwfilter_params.c | 30 ++++---------
src/conf/snapshot_conf.c | 11 ++---
src/conf/storage_conf.c | 13 ++----
src/conf/virchrdev.c | 12 ++---
10 files changed, 107 insertions(+), 198 deletions(-)
diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index 5340b63..fa05ad0 100644
--- a/src/conf/capabilities.c
+++ b/src/conf/capabilities.c
@@ -31,7 +31,7 @@
#include "viruuid.h"
#include "cpu_conf.h"
#include "virerror.h"
-
+#include "virstring.h"
#define VIR_FROM_THIS VIR_FROM_CAPABILITIES
@@ -228,7 +228,7 @@ virCapabilitiesAddHostFeature(virCapsPtr caps,
caps->host.nfeatures, 1) < 0)
return -1;
- if ((caps->host.features[caps->host.nfeatures] = strdup(name)) == NULL)
+ if (VIR_STRDUP(caps->host.features[caps->host.nfeatures], name) < 0)
return -1;
caps->host.nfeatures++;
@@ -250,7 +250,7 @@ virCapabilitiesAddHostMigrateTransport(virCapsPtr caps,
caps->host.nmigrateTrans, 1) < 0)
return -1;
- if ((caps->host.migrateTrans[caps->host.nmigrateTrans] = strdup(name)) ==
NULL)
+ if (VIR_STRDUP(caps->host.migrateTrans[caps->host.nmigrateTrans], name) <
0)
return -1;
caps->host.nmigrateTrans++;
@@ -334,7 +334,7 @@ virCapabilitiesAllocMachines(const char *const *names, int nnames)
for (i = 0; i < nnames; i++) {
if (VIR_ALLOC(machines[i]) < 0 ||
- !(machines[i]->name = strdup(names[i]))) {
+ VIR_STRDUP(machines[i]->name, names[i]) < 0) {
virCapabilitiesFreeMachines(machines, nnames);
return NULL;
}
@@ -392,17 +392,14 @@ virCapabilitiesAddGuest(virCapsPtr caps,
if (VIR_ALLOC(guest) < 0)
goto no_memory;
- if ((guest->ostype = strdup(ostype)) == NULL)
+ if (VIR_STRDUP(guest->ostype, ostype) < 0)
goto no_memory;
guest->arch.id = arch;
guest->arch.wordsize = virArchGetWordSize(arch);
- if (emulator &&
- (guest->arch.defaultInfo.emulator = strdup(emulator)) == NULL)
- goto no_memory;
- if (loader &&
- (guest->arch.defaultInfo.loader = strdup(loader)) == NULL)
+ if ((emulator && VIR_STRDUP(guest->arch.defaultInfo.emulator, emulator)
< 0) ||
+ (loader && VIR_STRDUP(guest->arch.defaultInfo.loader, loader) <
0))
goto no_memory;
if (VIR_RESIZE_N(caps->guests, caps->nguests_max,
@@ -448,14 +445,9 @@ virCapabilitiesAddGuestDomain(virCapsGuestPtr guest,
if (VIR_ALLOC(dom) < 0)
goto no_memory;
- if ((dom->type = strdup(hvtype)) == NULL)
- goto no_memory;
-
- if (emulator &&
- (dom->info.emulator = strdup(emulator)) == NULL)
- goto no_memory;
- if (loader &&
- (dom->info.loader = strdup(loader)) == NULL)
+ if (VIR_STRDUP(dom->type, hvtype) < 0 ||
+ (emulator && VIR_STRDUP(dom->info.emulator, emulator) < 0) ||
+ (loader && VIR_STRDUP(dom->info.loader, loader) < 0))
goto no_memory;
if (VIR_RESIZE_N(guest->arch.domains, guest->arch.ndomains_max,
@@ -497,7 +489,7 @@ virCapabilitiesAddGuestFeature(virCapsGuestPtr guest,
if (VIR_ALLOC(feature) < 0)
goto no_memory;
- if ((feature->name = strdup(name)) == NULL)
+ if (VIR_STRDUP(feature->name, name) < 0)
goto no_memory;
feature->defaultOn = defaultOn;
feature->toggle = toggle;
diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c
index 6aaee75..8bd51fe 100644
--- a/src/conf/cpu_conf.c
+++ b/src/conf/cpu_conf.c
@@ -99,10 +99,10 @@ virCPUDefCopyModel(virCPUDefPtr dst,
{
unsigned int i;
- if ((src->model && !(dst->model = strdup(src->model)))
- || (src->vendor && !(dst->vendor = strdup(src->vendor)))
- || (src->vendor_id && !(dst->vendor_id =
strdup(src->vendor_id)))
- || VIR_ALLOC_N(dst->features, src->nfeatures) < 0)
+ if ((src->model && VIR_STRDUP(dst->model, src->model) < 0) ||
+ (src->vendor && VIR_STRDUP(dst->vendor, src->vendor) < 0) ||
+ (src->vendor_id && VIR_STRDUP(dst->vendor_id, src->vendor_id)
< 0) ||
+ VIR_ALLOC_N(dst->features, src->nfeatures) < 0)
goto no_memory;
dst->nfeatures_max = dst->nfeatures = src->nfeatures;
@@ -118,7 +118,7 @@ virCPUDefCopyModel(virCPUDefPtr dst,
dst->features[i].policy = src->features[i].policy;
}
- if (!(dst->features[i].name = strdup(src->features[i].name)))
+ if (VIR_STRDUP(dst->features[i].name, src->features[i].name) < 0)
goto no_memory;
}
@@ -167,8 +167,8 @@ virCPUDefCopy(const virCPUDefPtr cpu)
if (!copy->cells[i].cpumask)
goto no_memory;
- if (!(copy->cells[i].cpustr = strdup(cpu->cells[i].cpustr)))
- goto no_memory;
+ if (VIR_STRDUP(copy->cells[i].cpustr, cpu->cells[i].cpustr) < 0)
+ goto error;
}
copy->cells_cpus = cpu->cells_cpus;
}
@@ -694,8 +694,8 @@ virCPUDefAddFeature(virCPUDefPtr def,
if (def->type == VIR_CPU_TYPE_HOST)
policy = -1;
- if (!(def->features[def->nfeatures].name = strdup(name)))
- goto no_memory;
+ if (VIR_STRDUP(def->features[def->nfeatures].name, name) < 0)
+ goto error;
def->features[def->nfeatures].policy = policy;
def->nfeatures++;
@@ -704,6 +704,7 @@ virCPUDefAddFeature(virCPUDefPtr def,
no_memory:
virReportOOMError();
+error:
return -1;
}
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index fe97c02..7e1b530 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1352,59 +1352,42 @@ virDomainChrSourceDefCopy(virDomainChrSourceDefPtr dest,
case VIR_DOMAIN_CHR_TYPE_FILE:
case VIR_DOMAIN_CHR_TYPE_PIPE:
if (src->data.file.path &&
- !(dest->data.file.path = strdup(src->data.file.path))) {
- virReportOOMError();
+ VIR_STRDUP(dest->data.file.path, src->data.file.path) < 0)
return -1;
- }
break;
case VIR_DOMAIN_CHR_TYPE_UDP:
if (src->data.udp.bindHost &&
- !(dest->data.udp.bindHost = strdup(src->data.udp.bindHost))) {
- virReportOOMError();
+ VIR_STRDUP(dest->data.udp.bindHost, src->data.udp.bindHost) < 0)
return -1;
- }
if (src->data.udp.bindService &&
- !(dest->data.udp.bindService = strdup(src->data.udp.bindService))) {
- virReportOOMError();
+ VIR_STRDUP(dest->data.udp.bindService, src->data.udp.bindService) <
0)
return -1;
- }
if (src->data.udp.connectHost &&
- !(dest->data.udp.connectHost = strdup(src->data.udp.connectHost))) {
- virReportOOMError();
+ VIR_STRDUP(dest->data.udp.connectHost, src->data.udp.connectHost) <
0)
return -1;
- }
-
if (src->data.udp.connectService &&
- !(dest->data.udp.connectService =
strdup(src->data.udp.connectService))) {
- virReportOOMError();
+ VIR_STRDUP(dest->data.udp.connectService, src->data.udp.connectService)
< 0)
return -1;
- }
break;
case VIR_DOMAIN_CHR_TYPE_TCP:
if (src->data.tcp.host &&
- !(dest->data.tcp.host = strdup(src->data.tcp.host))) {
- virReportOOMError();
+ VIR_STRDUP(dest->data.tcp.host, src->data.tcp.host) < 0)
return -1;
- }
if (src->data.tcp.service &&
- !(dest->data.tcp.service = strdup(src->data.tcp.service))) {
- virReportOOMError();
+ VIR_STRDUP(dest->data.tcp.service, src->data.tcp.service) < 0)
return -1;
- }
break;
case VIR_DOMAIN_CHR_TYPE_UNIX:
if (src->data.nix.path &&
- !(dest->data.nix.path = strdup(src->data.nix.path))) {
- virReportOOMError();
+ VIR_STRDUP(dest->data.nix.path, src->data.nix.path) < 0)
return -1;
- }
break;
}
@@ -2378,14 +2361,9 @@ virDomainDeviceInfoCopy(virDomainDeviceInfoPtr dst,
dst->alias = NULL;
dst->romfile = NULL;
- if (src->alias && !(dst->alias = strdup(src->alias))) {
- virReportOOMError();
+ if ((src->alias && VIR_STRDUP(dst->alias, src->alias) < 0) ||
+ (src->romfile && VIR_STRDUP(dst->romfile, src->romfile) <
0))
return -1;
- }
- if (src->romfile && !(dst->romfile = strdup(src->romfile))) {
- virReportOOMError();
- return -1;
- }
return 0;
}
@@ -4124,11 +4102,8 @@ virSecurityLabelDefsParseXML(virDomainDefPtr def,
/* Copy model from host. */
VIR_DEBUG("Found seclabel without a model, using '%s'",
host->secModels[0].model);
- def->seclabels[0]->model = strdup(host->secModels[0].model);
- if (!def->seclabels[0]->model) {
- virReportOOMError();
+ if (VIR_STRDUP(def->seclabels[0]->model, host->secModels[0].model)
< 0)
goto error;
- }
} else {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing security model in domain seclabel"));
@@ -5741,10 +5716,8 @@ virDomainActualNetDefParseXML(xmlNodePtr node,
addrtype = virXPathString("string(./source/address/@type)", ctxt);
/* if not explicitly stated, source/vendor implies usb device */
if (!addrtype && virXPathNode("./source/vendor", ctxt)
&&
- (addrtype = strdup("usb")) == NULL) {
- virReportOOMError();
+ VIR_STRDUP(addrtype, "usb") < 0)
goto error;
- }
hostdev->mode = VIR_DOMAIN_HOSTDEV_MODE_SUBSYS;
if (virDomainHostdevDefParseXMLSubsys(node, ctxt, addrtype,
hostdev, flags) < 0) {
@@ -6133,7 +6106,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
addrtype = virXPathString("string(./source/address/@type)", ctxt);
/* if not explicitly stated, source/vendor implies usb device */
if (!addrtype && virXPathNode("./source/vendor", ctxt)
&&
- ((addrtype = strdup("usb")) == NULL)) {
+ VIR_STRDUP(addrtype, "usb") < 0) {
virReportOOMError();
goto error;
}
@@ -7004,10 +6977,8 @@ virDomainTPMDefParseXML(const xmlNodePtr node,
switch (def->type) {
case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
path = virXPathString("string(./backend/device/@path)", ctxt);
- if (!path && !(path = strdup(VIR_DOMAIN_TPM_DEFAULT_DEVICE))) {
- virReportOOMError();
+ if (!path && VIR_STRDUP(path, VIR_DOMAIN_TPM_DEFAULT_DEVICE) < 0)
goto error;
- }
def->data.passthrough.source.data.file.path = path;
def->data.passthrough.source.type = VIR_DOMAIN_CHR_TYPE_DEV;
path = NULL;
@@ -8730,10 +8701,8 @@ virDomainRedirFilterUsbVersionHelper(const char *version,
unsigned int minor;
unsigned int hex;
- if (!(version_copy = strdup(version))) {
- virReportOOMError();
+ if (VIR_STRDUP(version_copy, version) < 0)
return -1;
- }
len = strlen(version_copy);
/*
@@ -9679,9 +9648,7 @@ virDomainDefGetDefaultEmulator(virDomainDefPtr def,
return NULL;
}
- if (!(retemu = strdup(emulator)))
- virReportOOMError();
-
+ ignore_value(VIR_STRDUP(retemu, emulator));
return retemu;
}
@@ -10782,10 +10749,8 @@ virDomainDefParseXML(xmlDocPtr xml,
def->os.type = virXPathString("string(./os/type[1])", ctxt);
if (!def->os.type) {
if (def->os.bootloader) {
- def->os.type = strdup("xen");
- if (!def->os.type) {
- goto no_memory;
- }
+ if (VIR_STRDUP(def->os.type, "xen") < 0)
+ goto error;
} else {
virReportError(VIR_ERR_OS_TYPE,
"%s", _("no OS type"));
@@ -10800,9 +10765,8 @@ virDomainDefParseXML(xmlDocPtr xml,
if (STREQ(def->os.type, "linux") &&
def->virtType == VIR_DOMAIN_VIRT_XEN) {
VIR_FREE(def->os.type);
- if (!(def->os.type = strdup("xen"))) {
- goto no_memory;
- }
+ if (VIR_STRDUP(def->os.type, "xen") < 0)
+ goto error;
}
if (!virCapabilitiesSupportsGuestOSType(caps, def->os.type)) {
@@ -10857,8 +10821,8 @@ virDomainDefParseXML(xmlDocPtr xml,
def->os.arch,
virDomainVirtTypeToString(def->virtType));
if (defaultMachine != NULL) {
- if (!(def->os.machine = strdup(defaultMachine))) {
- goto no_memory;
+ if (VIR_STRDUP(def->os.machine, defaultMachine) < 0) {
+ goto error;
}
}
}
@@ -10889,8 +10853,9 @@ virDomainDefParseXML(xmlDocPtr xml,
_("No data supplied for <initarg>
element"));
goto error;
}
- if (!(def->os.initargv[i] = strdup((const
char*)nodes[i]->children->content)))
- goto no_memory;
+ if (VIR_STRDUP(def->os.initargv[i],
+ (const char*) nodes[i]->children->content) < 0)
+ goto error;
}
def->os.initargv[n] = NULL;
VIR_FREE(nodes);
@@ -16490,7 +16455,7 @@ virDomainObjListCopyInactiveNames(void *payload,
virObjectLock(obj);
if (!virDomainObjIsActive(obj) && data->numnames < data->maxnames)
{
- if (!(data->names[data->numnames] = strdup(obj->def->name)))
+ if (VIR_STRDUP(data->names[data->numnames], obj->def->name) < 0)
data->oom = 1;
else
data->numnames++;
@@ -17043,12 +17008,9 @@ virDomainGraphicsListenSetAddress(virDomainGraphicsDefPtr def,
return 0;
}
- listenInfo->address = (len == -1) ? strdup(address) : strndup(address, len);
- if (!listenInfo->address) {
- virReportOOMError();
+ if ((len == -1 && VIR_STRDUP(listenInfo->address, address) < 0) ||
+ (len != -1 && VIR_STRNDUP(listenInfo->address, address, len) < 0))
return -1;
- }
-
return 0;
}
@@ -17085,12 +17047,9 @@ virDomainGraphicsListenSetNetwork(virDomainGraphicsDefPtr def,
return 0;
}
- listenInfo->network = (len == -1) ? strdup(network) : strndup(network, len);
- if (!listenInfo->network) {
- virReportOOMError();
+ if ((len == -1 && VIR_STRDUP(listenInfo->network, network) < 0) ||
+ (len != -1 && VIR_STRNDUP(listenInfo->network, network, len) < 0))
return -1;
- }
-
return 0;
}
@@ -17425,7 +17384,7 @@ virDomainDefGenSecurityLabelDef(const char *model)
virSecurityLabelDefPtr seclabel = NULL;
if (VIR_ALLOC(seclabel) < 0 ||
- (model && !(seclabel->model = strdup(model)))) {
+ (model && VIR_STRDUP(seclabel->model, model) < 0)) {
virReportOOMError();
virSecurityLabelDefFree(seclabel);
seclabel = NULL;
@@ -17440,7 +17399,7 @@ virDomainDiskDefGenSecurityLabelDef(const char *model)
virSecurityDeviceLabelDefPtr seclabel = NULL;
if (VIR_ALLOC(seclabel) < 0 ||
- (model && !(seclabel->model = strdup(model)))) {
+ (model && VIR_STRDUP(seclabel->model, model) < 0)) {
virReportOOMError();
virSecurityDeviceLabelDefFree(seclabel);
seclabel = NULL;
diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index 825012a..ae55b82 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -28,6 +28,7 @@
#include "datatypes.h"
#include "viralloc.h"
#include "virerror.h"
+#include "virstring.h"
#define VIR_FROM_THIS VIR_FROM_NONE
@@ -385,8 +386,8 @@ virDomainEventCallbackListAddID(virConnectPtr conn,
if (dom) {
if (VIR_ALLOC(event->dom) < 0)
goto no_memory;
- if (!(event->dom->name = strdup(dom->name)))
- goto no_memory;
+ if (VIR_STRDUP(event->dom->name, dom->name) < 0)
+ goto error;
memcpy(event->dom->uuid, dom->uuid, VIR_UUID_BUFLEN);
event->dom->id = dom->id;
}
@@ -416,7 +417,7 @@ virDomainEventCallbackListAddID(virConnectPtr conn,
no_memory:
virReportOOMError();
-
+error:
if (event) {
if (event->dom)
VIR_FREE(event->dom->name);
@@ -668,8 +669,7 @@ static virDomainEventPtr virDomainEventNewInternal(int eventID,
}
event->eventID = eventID;
- if (!(event->dom.name = strdup(name))) {
- virReportOOMError();
+ if (VIR_STRDUP(event->dom.name, name) < 0) {
VIR_FREE(event);
return NULL;
}
@@ -791,9 +791,9 @@ static virDomainEventPtr virDomainEventIOErrorNewFromDomImpl(int
event,
if (ev) {
ev->data.ioError.action = action;
- if (!(ev->data.ioError.srcPath = strdup(srcPath)) ||
- !(ev->data.ioError.devAlias = strdup(devAlias)) ||
- (reason && !(ev->data.ioError.reason = strdup(reason)))) {
+ if (VIR_STRDUP(ev->data.ioError.srcPath, srcPath) < 0 ||
+ VIR_STRDUP(ev->data.ioError.devAlias, devAlias) < 0 ||
+ (reason && VIR_STRDUP(ev->data.ioError.reason, reason) < 0)) {
virDomainEventFree(ev);
ev = NULL;
}
@@ -815,9 +815,9 @@ static virDomainEventPtr virDomainEventIOErrorNewFromObjImpl(int
event,
if (ev) {
ev->data.ioError.action = action;
- if (!(ev->data.ioError.srcPath = strdup(srcPath)) ||
- !(ev->data.ioError.devAlias = strdup(devAlias)) ||
- (reason && !(ev->data.ioError.reason = strdup(reason)))) {
+ if (VIR_STRDUP(ev->data.ioError.srcPath, srcPath) < 0 ||
+ VIR_STRDUP(ev->data.ioError.devAlias, devAlias) < 0 ||
+ (reason && VIR_STRDUP(ev->data.ioError.reason, reason) < 0)) {
virDomainEventFree(ev);
ev = NULL;
}
@@ -882,7 +882,7 @@ virDomainEventPtr virDomainEventGraphicsNewFromDom(virDomainPtr dom,
if (ev) {
ev->data.graphics.phase = phase;
- if (!(ev->data.graphics.authScheme = strdup(authScheme))) {
+ if (VIR_STRDUP(ev->data.graphics.authScheme, authScheme) < 0) {
virDomainEventFree(ev);
return NULL;
}
@@ -907,7 +907,7 @@ virDomainEventPtr virDomainEventGraphicsNewFromObj(virDomainObjPtr
obj,
if (ev) {
ev->data.graphics.phase = phase;
- if (!(ev->data.graphics.authScheme = strdup(authScheme))) {
+ if (VIR_STRDUP(ev->data.graphics.authScheme, authScheme) < 0) {
virDomainEventFree(ev);
return NULL;
}
@@ -928,8 +928,7 @@ virDomainEventBlockJobNew(int id, const char *name, unsigned char
*uuid,
id, name, uuid);
if (ev) {
- if (!(ev->data.blockJob.path = strdup(path))) {
- virReportOOMError();
+ if (VIR_STRDUP(ev->data.blockJob.path, path) < 0) {
virDomainEventFree(ev);
return NULL;
}
@@ -987,15 +986,15 @@ virDomainEventDiskChangeNew(int id, const char *name,
id, name, uuid);
if (ev) {
- if (!(ev->data.diskChange.devAlias = strdup(devAlias)))
+ if (VIR_STRDUP(ev->data.diskChange.devAlias, devAlias) < 0)
goto error;
if (oldSrcPath &&
- !(ev->data.diskChange.oldSrcPath = strdup(oldSrcPath)))
+ VIR_STRDUP(ev->data.diskChange.oldSrcPath, oldSrcPath) < 0)
goto error;
if (newSrcPath &&
- !(ev->data.diskChange.newSrcPath = strdup(newSrcPath)))
+ VIR_STRDUP(ev->data.diskChange.newSrcPath, newSrcPath) < 0)
goto error;
ev->data.diskChange.reason = reason;
@@ -1004,7 +1003,6 @@ virDomainEventDiskChangeNew(int id, const char *name,
return ev;
error:
- virReportOOMError();
virDomainEventFree(ev);
return NULL;
}
@@ -1042,7 +1040,7 @@ virDomainEventTrayChangeNew(int id, const char *name,
id, name, uuid);
if (ev) {
- if (!(ev->data.trayChange.devAlias = strdup(devAlias)))
+ if (VIR_STRDUP(ev->data.trayChange.devAlias, devAlias) < 0)
goto error;
ev->data.trayChange.reason = reason;
@@ -1051,7 +1049,6 @@ virDomainEventTrayChangeNew(int id, const char *name,
return ev;
error:
- virReportOOMError();
virDomainEventFree(ev);
return NULL;
}
diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
index f9303c1..40b886b 100644
--- a/src/conf/node_device_conf.c
+++ b/src/conf/node_device_conf.c
@@ -29,7 +29,7 @@
#include "virerror.h"
#include "datatypes.h"
#include "viralloc.h"
-
+#include "virstring.h"
#include "node_device_conf.h"
#include "virxml.h"
#include "virbuffer.h"
@@ -1164,12 +1164,8 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt,
goto error;
}
} else {
- def->name = strdup("new device");
-
- if (!def->name) {
- virReportOOMError();
+ if (VIR_STRDUP(def->name, "new device") < 0)
goto error;
- }
}
/* Extract device parent, if any */
@@ -1284,14 +1280,19 @@ virNodeDeviceGetWWNs(virNodeDeviceDefPtr def,
char **wwpn)
{
virNodeDevCapsDefPtr cap = NULL;
- int ret = 0;
+ int ret = -1;
cap = def->caps;
while (cap != NULL) {
if (cap->type == VIR_NODE_DEV_CAP_SCSI_HOST &&
cap->data.scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST) {
- *wwnn = strdup(cap->data.scsi_host.wwnn);
- *wwpn = strdup(cap->data.scsi_host.wwpn);
+ if (VIR_STRDUP(*wwnn, cap->data.scsi_host.wwnn) < 0 ||
+ VIR_STRDUP(*wwpn, cap->data.scsi_host.wwpn) < 0) {
+ /* Free the other one, if allocated... */
+ VIR_FREE(*wwnn);
+ VIR_FREE(*wwpn);
+ goto cleanup;
+ }
break;
}
@@ -1301,15 +1302,11 @@ virNodeDeviceGetWWNs(virNodeDeviceDefPtr def,
if (cap == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("Device is not a fibre channel
HBA"));
- ret = -1;
- } else if (*wwnn == NULL || *wwpn == NULL) {
- /* Free the other one, if allocated... */
- VIR_FREE(*wwnn);
- VIR_FREE(*wwpn);
- ret = -1;
- virReportOOMError();
+ goto cleanup;
}
+ ret = 0;
+cleanup:
return ret;
}
diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c
index 08222de..c0d32ea 100644
--- a/src/conf/nwfilter_conf.c
+++ b/src/conf/nwfilter_conf.c
@@ -400,12 +400,8 @@ virNWFilterRuleDefAddString(virNWFilterRuleDefPtr nwf,
return NULL;
}
- nwf->strings[nwf->nstrings] = strndup(string, maxstrlen);
-
- if (!nwf->strings[nwf->nstrings]) {
- virReportOOMError();
+ if (VIR_STRNDUP(nwf->strings[nwf->nstrings], string, maxstrlen) < 0)
return NULL;
- }
nwf->nstrings++;
@@ -2556,12 +2552,9 @@ virNWFilterDefParseXML(xmlXPathContextPtr ctxt) {
}
chain = NULL;
} else {
- ret->chainsuffix = strdup(virNWFilterChainSuffixTypeToString(
- VIR_NWFILTER_CHAINSUFFIX_ROOT));
- if (ret->chainsuffix == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(ret->chainsuffix,
+ virNWFilterChainSuffixTypeToString(VIR_NWFILTER_CHAINSUFFIX_ROOT))
< 0)
goto cleanup;
- }
}
uuid = virXPathString("string(./uuid)", ctxt);
@@ -3094,9 +3087,7 @@ virNWFilterObjLoad(virConnectPtr conn,
}
VIR_FREE(nwfilter->configFile); /* for driver reload */
- nwfilter->configFile = strdup(path);
- if (nwfilter->configFile == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(nwfilter->configFile, path) < 0) {
virNWFilterDefFree(def);
return NULL;
}
diff --git a/src/conf/nwfilter_params.c b/src/conf/nwfilter_params.c
index 2509c0d..75f5cdf 100644
--- a/src/conf/nwfilter_params.c
+++ b/src/conf/nwfilter_params.c
@@ -80,8 +80,7 @@ virNWFilterVarValueCopy(const virNWFilterVarValuePtr val)
switch (res->valType) {
case NWFILTER_VALUE_TYPE_SIMPLE:
if (val->u.simple.value) {
- res->u.simple.value = strdup(val->u.simple.value);
- if (!res->u.simple.value)
+ if (VIR_STRDUP(res->u.simple.value, val->u.simple.value) < 0)
goto err_exit;
}
break;
@@ -90,8 +89,7 @@ virNWFilterVarValueCopy(const virNWFilterVarValuePtr val)
goto err_exit;
res->u.array.nValues = val->u.array.nValues;
for (i = 0; i < val->u.array.nValues; i++) {
- str = strdup(val->u.array.values[i]);
- if (!str)
+ if (VIR_STRDUP(str, val->u.array.values[i]) < 0)
goto err_exit;
res->u.array.values[i] = str;
}
@@ -133,12 +131,10 @@ virNWFilterVarValueCreateSimple(char *value)
virNWFilterVarValuePtr
virNWFilterVarValueCreateSimpleCopyValue(const char *value)
{
- char *val = strdup(value);
+ char *val;
- if (!val) {
- virReportOOMError();
+ if (VIR_STRDUP(val, value) < 0)
return NULL;
- }
return virNWFilterVarValueCreateSimple(val);
}
@@ -654,17 +650,15 @@ virNWFilterHashTablePut(virNWFilterHashTablePtr table,
{
if (!virHashLookup(table->hashTable, name)) {
if (copyName) {
- name = strdup(name);
- if (!name) {
- virReportOOMError();
+ char *newName;
+ if (VIR_STRDUP(newName, name) < 0)
return -1;
- }
if (VIR_REALLOC_N(table->names, table->nNames + 1) < 0) {
VIR_FREE(name);
return -1;
}
- table->names[table->nNames++] = (char *)name;
+ table->names[table->nNames++] = newName;
}
if (virHashAddEntry(table->hashTable, name, val) < 0) {
@@ -1006,11 +1000,8 @@ virNWFilterVarAccessParse(const char *varAccess)
if (input[idx] == '\0') {
/* in the form 'IP', which is equivalent to IP[@0] */
- dest->varName = strndup(input, idx);
- if (!dest->varName) {
- virReportOOMError();
+ if (VIR_STRNDUP(dest->varName, input, idx) < 0)
goto err_exit;
- }
dest->accessType = VIR_NWFILTER_VAR_ACCESS_ITERATOR;
dest->u.iterId = 0;
return dest;
@@ -1023,11 +1014,8 @@ virNWFilterVarAccessParse(const char *varAccess)
varNameLen = idx;
- dest->varName = strndup(input, varNameLen);
- if (!dest->varName) {
- virReportOOMError();
+ if (VIR_STRNDUP(dest->varName, input, varNameLen) < 0)
goto err_exit;
- }
input += idx + 1;
virSkipSpaces(&input);
diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c
index 5b54a28..c6b97d6 100644
--- a/src/conf/snapshot_conf.c
+++ b/src/conf/snapshot_conf.c
@@ -463,10 +463,8 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def,
}
if (STRNEQ(disk->name, def->dom->disks[idx]->dst)) {
VIR_FREE(disk->name);
- if (!(disk->name = strdup(def->dom->disks[idx]->dst))) {
- virReportOOMError();
+ if (VIR_STRDUP(disk->name, def->dom->disks[idx]->dst) < 0)
goto cleanup;
- }
}
}
@@ -485,10 +483,8 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def,
if (inuse)
continue;
disk = &def->disks[ndisks++];
- if (!(disk->name = strdup(def->dom->disks[i]->dst))) {
- virReportOOMError();
+ if (VIR_STRDUP(disk->name, def->dom->disks[i]->dst) < 0)
goto cleanup;
- }
disk->index = i;
disk->snapshot = def->dom->disks[i]->snapshot;
if (!disk->snapshot)
@@ -768,9 +764,8 @@ static void virDomainSnapshotObjListCopyNames(void *payload,
return;
if (data->names && data->count < data->maxnames &&
- !(data->names[data->count] = strdup(obj->def->name))) {
+ VIR_STRDUP(data->names[data->count], obj->def->name) < 0) {
data->error = true;
- virReportOOMError();
return;
}
data->count++;
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 9f2012e..61a1fed 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -878,11 +878,8 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) {
if (options->flags & VIR_STORAGE_POOL_SOURCE_NAME) {
if (ret->source.name == NULL) {
/* source name defaults to pool name */
- ret->source.name = strdup(ret->name);
- if (ret->source.name == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(ret->source.name, ret->name) < 0)
goto cleanup;
- }
}
}
@@ -1679,16 +1676,12 @@ virStoragePoolObjLoad(virStoragePoolObjListPtr pools,
}
VIR_FREE(pool->configFile); /* for driver reload */
- pool->configFile = strdup(path);
- if (pool->configFile == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(pool->configFile, path) < 0) {
virStoragePoolDefFree(def);
return NULL;
}
VIR_FREE(pool->autostartLink); /* for driver reload */
- pool->autostartLink = strdup(autostartLink);
- if (pool->autostartLink == NULL) {
- virReportOOMError();
+ if (VIR_STRDUP(pool->autostartLink, autostartLink) < 0) {
virStoragePoolDefFree(def);
return NULL;
}
diff --git a/src/conf/virchrdev.c b/src/conf/virchrdev.c
index 025d4a8..d15d861 100644
--- a/src/conf/virchrdev.c
+++ b/src/conf/virchrdev.c
@@ -52,7 +52,7 @@ typedef struct _virChrdevStreamInfo virChrdevStreamInfo;
typedef virChrdevStreamInfo *virChrdevStreamInfoPtr;
struct _virChrdevStreamInfo {
virChrdevsPtr devs;
- const char *path;
+ char *path;
};
#ifdef VIR_CHRDEV_LOCK_FILE_PATH
@@ -73,10 +73,8 @@ static char *virChrdevLockFilePath(const char *dev)
char *filename;
char *p;
- if (!(devCopy = strdup(dev))) {
- virReportOOMError();
+ if (VIR_STRDUP(devCopy, dev) < 0)
goto cleanup;
- }
/* skip the leading "/dev/" */
filename = STRSKIP(devCopy, "/dev");
@@ -341,7 +339,7 @@ int virChrdevOpen(virChrdevsPtr devs,
{
virChrdevStreamInfoPtr cbdata = NULL;
virStreamPtr savedStream;
- const char *path;
+ char *path;
int ret;
switch (source->type) {
@@ -401,10 +399,8 @@ int virChrdevOpen(virChrdevsPtr devs,
goto error;
cbdata->devs = devs;
- if (!(cbdata->path = strdup(path))) {
- virReportOOMError();
+ if (VIR_STRDUP(cbdata->path, path) < 0)
goto error;
- }
/* open the character device */
switch (source->type) {
--
1.8.1.5