[PATCH v2 04/37] Adapt to VIR_STRDUP in src/conf/*

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 src/conf/capabilities.c     | 26 ++++++++----------
 src/conf/cpu_conf.c         | 12 ++++-----
 src/conf/domain_conf.c      | 64 ++++++++++++++++++++-------------------------
 src/conf/domain_event.c     | 31 +++++++++++-----------
 src/conf/node_device_conf.c | 28 +++++++++-----------
 src/conf/nwfilter_conf.c    | 18 +++++--------
 src/conf/nwfilter_params.c  | 22 +++++++---------
 src/conf/snapshot_conf.c    |  6 ++---
 src/conf/storage_conf.c     |  9 +++----
 src/conf/virchrdev.c        |  6 ++---
 10 files changed, 98 insertions(+), 124 deletions(-)

diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index 5340b63..4b4b670 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,15 @@ 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)
+    if (emulator && VIR_STRDUP(guest->arch.defaultInfo.emulator, emulator) < 0)
         goto no_memory;
-    if (loader &&
-        (guest->arch.defaultInfo.loader = strdup(loader)) == NULL)
+    if (loader && VIR_STRDUP(guest->arch.defaultInfo.loader, loader) < 0)
         goto no_memory;
 
     if (VIR_RESIZE_N(caps->guests, caps->nguests_max,
@@ -448,14 +446,12 @@ virCapabilitiesAddGuestDomain(virCapsGuestPtr guest,
     if (VIR_ALLOC(dom) < 0)
         goto no_memory;
 
-    if ((dom->type = strdup(hvtype)) == NULL)
+    if (VIR_STRDUP(dom->type, hvtype) < 0)
         goto no_memory;
 
-    if (emulator &&
-        (dom->info.emulator = strdup(emulator)) == NULL)
+    if (emulator && VIR_STRDUP(dom->info.emulator, emulator) < 0)
         goto no_memory;
-    if (loader &&
-        (dom->info.loader = strdup(loader)) == NULL)
+    if (loader && VIR_STRDUP(dom->info.loader, loader) < 0)
         goto no_memory;
 
     if (VIR_RESIZE_N(guest->arch.domains, guest->arch.ndomains_max,
@@ -497,7 +493,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..7a50d76 100644
--- a/src/conf/cpu_conf.c
+++ b/src/conf/cpu_conf.c
@@ -99,9 +99,9 @@ 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)))
+    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,7 +167,7 @@ virCPUDefCopy(const virCPUDefPtr cpu)
             if (!copy->cells[i].cpumask)
                 goto no_memory;
 
-            if (!(copy->cells[i].cpustr = strdup(cpu->cells[i].cpustr)))
+            if (VIR_STRDUP(copy->cells[i].cpustr, cpu->cells[i].cpustr) < 0)
                 goto no_memory;
         }
         copy->cells_cpus = cpu->cells_cpus;
@@ -694,7 +694,7 @@ virCPUDefAddFeature(virCPUDefPtr def,
     if (def->type == VIR_CPU_TYPE_HOST)
         policy = -1;
 
-    if (!(def->features[def->nfeatures].name = strdup(name)))
+    if (VIR_STRDUP(def->features[def->nfeatures].name, name) < 0)
         goto no_memory;
 
     def->features[def->nfeatures].policy = policy;
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 51cb1fa..db854d3 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1352,7 +1352,7 @@ 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))) {
+            VIR_STRDUP(dest->data.file.path, src->data.file.path) < 0) {
             virReportOOMError();
             return -1;
         }
@@ -1360,26 +1360,26 @@ virDomainChrSourceDefCopy(virDomainChrSourceDefPtr dest,
 
     case VIR_DOMAIN_CHR_TYPE_UDP:
         if (src->data.udp.bindHost &&
-            !(dest->data.udp.bindHost = strdup(src->data.udp.bindHost))) {
+            VIR_STRDUP(dest->data.udp.bindHost, src->data.udp.bindHost) < 0) {
             virReportOOMError();
             return -1;
         }
 
         if (src->data.udp.bindService &&
-            !(dest->data.udp.bindService = strdup(src->data.udp.bindService))) {
+            VIR_STRDUP(dest->data.udp.bindService, src->data.udp.bindService) < 0) {
             virReportOOMError();
             return -1;
         }
 
         if (src->data.udp.connectHost &&
-            !(dest->data.udp.connectHost = strdup(src->data.udp.connectHost))) {
+            VIR_STRDUP(dest->data.udp.connectHost, src->data.udp.connectHost) < 0) {
             virReportOOMError();
             return -1;
         }
 
 
         if (src->data.udp.connectService &&
-            !(dest->data.udp.connectService = strdup(src->data.udp.connectService))) {
+            VIR_STRDUP(dest->data.udp.connectService, src->data.udp.connectService) < 0) {
             virReportOOMError();
             return -1;
         }
@@ -1387,13 +1387,13 @@ virDomainChrSourceDefCopy(virDomainChrSourceDefPtr dest,
 
     case VIR_DOMAIN_CHR_TYPE_TCP:
         if (src->data.tcp.host &&
-            !(dest->data.tcp.host = strdup(src->data.tcp.host))) {
+            VIR_STRDUP(dest->data.tcp.host, src->data.tcp.host) < 0) {
             virReportOOMError();
             return -1;
         }
 
         if (src->data.tcp.service &&
-            !(dest->data.tcp.service = strdup(src->data.tcp.service))) {
+            VIR_STRDUP(dest->data.tcp.service, src->data.tcp.service) < 0) {
             virReportOOMError();
             return -1;
         }
@@ -1401,7 +1401,7 @@ virDomainChrSourceDefCopy(virDomainChrSourceDefPtr dest,
 
     case VIR_DOMAIN_CHR_TYPE_UNIX:
         if (src->data.nix.path &&
-            !(dest->data.nix.path = strdup(src->data.nix.path))) {
+            VIR_STRDUP(dest->data.nix.path, src->data.nix.path) < 0) {
             virReportOOMError();
             return -1;
         }
@@ -2378,11 +2378,11 @@ virDomainDeviceInfoCopy(virDomainDeviceInfoPtr dst,
     dst->alias = NULL;
     dst->romfile = NULL;
 
-    if (src->alias && !(dst->alias = strdup(src->alias))) {
+    if (src->alias && VIR_STRDUP(dst->alias, src->alias) < 0) {
         virReportOOMError();
         return -1;
     }
-    if (src->romfile && !(dst->romfile = strdup(src->romfile))) {
+    if (src->romfile && VIR_STRDUP(dst->romfile, src->romfile) < 0) {
         virReportOOMError();
         return -1;
     }
@@ -4124,8 +4124,7 @@ 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) {
+            if (VIR_STRDUP(def->seclabels[0]->model, host->secModels[0].model) < 0) {
                 virReportOOMError();
                 goto error;
             }
@@ -5741,7 +5740,7 @@ 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) {
+            VIR_STRDUP(addrtype, "usb") < 0) {
             virReportOOMError();
             goto error;
         }
@@ -6133,7 +6132,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;
         }
@@ -7006,7 +7005,7 @@ 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))) {
+        if (!path && VIR_STRDUP(path, VIR_DOMAIN_TPM_DEFAULT_DEVICE) < 0) {
             virReportOOMError();
             goto error;
         }
@@ -8732,7 +8731,7 @@ virDomainRedirFilterUsbVersionHelper(const char *version,
     unsigned int minor;
     unsigned int hex;
 
-    if (!(version_copy = strdup(version))) {
+    if (VIR_STRDUP(version_copy, version) < 0) {
         virReportOOMError();
         return -1;
     }
@@ -9681,7 +9680,7 @@ virDomainDefGetDefaultEmulator(virDomainDefPtr def,
         return NULL;
     }
 
-    if (!(retemu = strdup(emulator)))
+    if (VIR_STRDUP(retemu, emulator) < 0)
         virReportOOMError();
 
     return retemu;
@@ -10784,10 +10783,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) {
+            if (VIR_STRDUP(def->os.type, "xen") < 0)
                 goto no_memory;
-            }
         } else {
             virReportError(VIR_ERR_OS_TYPE,
                            "%s", _("no OS type"));
@@ -10802,9 +10799,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"))) {
+        if (VIR_STRDUP(def->os.type, "xen") < 0)
             goto no_memory;
-        }
     }
 
     if (!virCapabilitiesSupportsGuestOSType(caps, def->os.type)) {
@@ -10858,11 +10854,9 @@ virDomainDefParseXML(xmlDocPtr xml,
                                                                         def->os.type,
                                                                         def->os.arch,
                                                                         virDomainVirtTypeToString(def->virtType));
-        if (defaultMachine != NULL) {
-            if (!(def->os.machine = strdup(defaultMachine))) {
-                goto no_memory;
-            }
-        }
+        if (defaultMachine &&
+            VIR_STRDUP(def->os.machine, defaultMachine) < 0)
+            goto no_memory;
     }
 
     /*
@@ -10891,7 +10885,7 @@ virDomainDefParseXML(xmlDocPtr xml,
                                _("No data supplied for <initarg> element"));
                 goto error;
             }
-            if (!(def->os.initargv[i] = strdup((const char*)nodes[i]->children->content)))
+            if (VIR_STRDUP(def->os.initargv[i], (const char*)nodes[i]->children->content) < 0)
                 goto no_memory;
         }
         def->os.initargv[n] = NULL;
@@ -16492,7 +16486,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++;
@@ -17045,8 +17039,8 @@ virDomainGraphicsListenSetAddress(virDomainGraphicsDefPtr def,
         return 0;
     }
 
-    listenInfo->address = (len == -1) ? strdup(address) : strndup(address, len);
-    if (!listenInfo->address) {
+    if ((len == -1 && VIR_STRDUP(listenInfo->address, address) < 0) ||
+        (len != -1 && VIR_STRNDUP(listenInfo->address, address, len) < 0)) {
         virReportOOMError();
         return -1;
     }
@@ -17087,8 +17081,8 @@ virDomainGraphicsListenSetNetwork(virDomainGraphicsDefPtr def,
         return 0;
     }
 
-    listenInfo->network = (len == -1) ? strdup(network) : strndup(network, len);
-    if (!listenInfo->network) {
+    if ((len == -1 && VIR_STRDUP(listenInfo->network, network) < 0) ||
+        (len != -1 && VIR_STRNDUP(listenInfo->network, network, len) < 0)) {
         virReportOOMError();
         return -1;
     }
@@ -17427,7 +17421,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;
@@ -17442,7 +17436,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..b5f5c92 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,7 +386,7 @@ virDomainEventCallbackListAddID(virConnectPtr conn,
     if (dom) {
         if (VIR_ALLOC(event->dom) < 0)
             goto no_memory;
-        if (!(event->dom->name = strdup(dom->name)))
+        if (VIR_STRDUP(event->dom->name, dom->name) < 0)
             goto no_memory;
         memcpy(event->dom->uuid, dom->uuid, VIR_UUID_BUFLEN);
         event->dom->id = dom->id;
@@ -668,7 +669,7 @@ static virDomainEventPtr virDomainEventNewInternal(int eventID,
     }
 
     event->eventID = eventID;
-    if (!(event->dom.name = strdup(name))) {
+    if (VIR_STRDUP(event->dom.name, name) < 0) {
         virReportOOMError();
         VIR_FREE(event);
         return NULL;
@@ -791,9 +792,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 +816,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 +883,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 +908,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,7 +929,7 @@ virDomainEventBlockJobNew(int id, const char *name, unsigned char *uuid,
                                   id, name, uuid);
 
     if (ev) {
-        if (!(ev->data.blockJob.path = strdup(path))) {
+        if (VIR_STRDUP(ev->data.blockJob.path, path) < 0) {
             virReportOOMError();
             virDomainEventFree(ev);
             return NULL;
@@ -987,15 +988,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;
@@ -1042,7 +1043,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;
diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
index f9303c1..346a2a0 100644
--- a/src/conf/node_device_conf.c
+++ b/src/conf/node_device_conf.c
@@ -35,6 +35,7 @@
 #include "virbuffer.h"
 #include "viruuid.h"
 #include "virrandom.h"
+#include "virstring.h"
 
 #define VIR_FROM_THIS VIR_FROM_NODEDEV
 
@@ -1163,13 +1164,9 @@ virNodeDeviceDefParseXML(xmlXPathContextPtr ctxt,
             virReportError(VIR_ERR_NO_NAME, NULL);
             goto error;
         }
-    } else {
-        def->name = strdup("new device");
-
-        if (!def->name) {
-            virReportOOMError();
-            goto error;
-        }
+    } else if (VIR_STRDUP(def->name, "new device") < 0) {
+        virReportOOMError();
+        goto error;
     }
 
     /* Extract device parent, if any */
@@ -1290,8 +1287,14 @@ virNodeDeviceGetWWNs(virNodeDeviceDefPtr def,
     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_FREE(*wwpn);
+                ret = -1;
+            }
+            if (VIR_STRDUP(*wwpn, cap->data.scsi_host.wwpn) < 0){
+                VIR_FREE(*wwnn);
+                ret = -1;
+            }
             break;
         }
 
@@ -1302,14 +1305,7 @@ virNodeDeviceGetWWNs(virNodeDeviceDefPtr def,
         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();
     }
-
     return ret;
 }
 
diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c
index 08222de..686a63f 100644
--- a/src/conf/nwfilter_conf.c
+++ b/src/conf/nwfilter_conf.c
@@ -400,9 +400,7 @@ virNWFilterRuleDefAddString(virNWFilterRuleDefPtr nwf,
         return NULL;
     }
 
-    nwf->strings[nwf->nstrings] = strndup(string, maxstrlen);
-
-    if (!nwf->strings[nwf->nstrings]) {
+    if (VIR_STRNDUP(nwf->strings[nwf->nstrings], string, maxstrlen) < 0) {
         virReportOOMError();
         return NULL;
     }
@@ -2555,13 +2553,10 @@ virNWFilterDefParseXML(xmlXPathContextPtr ctxt) {
             }
         }
         chain = NULL;
-    } else {
-        ret->chainsuffix = strdup(virNWFilterChainSuffixTypeToString(
-                                  VIR_NWFILTER_CHAINSUFFIX_ROOT));
-        if (ret->chainsuffix == NULL) {
-            virReportOOMError();
-            goto cleanup;
-        }
+    } else if (VIR_STRDUP(ret->chainsuffix,
+                          virNWFilterChainSuffixTypeToString(VIR_NWFILTER_CHAINSUFFIX_ROOT)) < 0) {
+        virReportOOMError();
+        goto cleanup;
     }
 
     uuid = virXPathString("string(./uuid)", ctxt);
@@ -3094,8 +3089,7 @@ virNWFilterObjLoad(virConnectPtr conn,
     }
 
     VIR_FREE(nwfilter->configFile); /* for driver reload */
-    nwfilter->configFile = strdup(path);
-    if (nwfilter->configFile == NULL) {
+    if (VIR_STRDUP(nwfilter->configFile, path) < 0) {
         virReportOOMError();
         virNWFilterDefFree(def);
         return NULL;
diff --git a/src/conf/nwfilter_params.c b/src/conf/nwfilter_params.c
index 2509c0d..2700945 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,9 +131,9 @@ virNWFilterVarValueCreateSimple(char *value)
 virNWFilterVarValuePtr
 virNWFilterVarValueCreateSimpleCopyValue(const char *value)
 {
-    char *val = strdup(value);
+    char *val;
 
-    if (!val) {
+    if (VIR_STRDUP(val, value) < 0) {
         virReportOOMError();
         return NULL;
     }
@@ -654,8 +652,8 @@ virNWFilterHashTablePut(virNWFilterHashTablePtr table,
 {
     if (!virHashLookup(table->hashTable, name)) {
         if (copyName) {
-            name = strdup(name);
-            if (!name) {
+            char *new_name;
+            if (VIR_STRDUP(new_name, name) < 0) {
                 virReportOOMError();
                 return -1;
             }
@@ -664,7 +662,7 @@ virNWFilterHashTablePut(virNWFilterHashTablePtr table,
                 VIR_FREE(name);
                 return -1;
             }
-            table->names[table->nNames++] = (char *)name;
+            table->names[table->nNames++] = new_name;
         }
 
         if (virHashAddEntry(table->hashTable, name, val) < 0) {
@@ -1006,8 +1004,7 @@ 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) {
+        if (VIR_STRNDUP(dest->varName, input, idx) < 0) {
             virReportOOMError();
             goto err_exit;
         }
@@ -1023,8 +1020,7 @@ virNWFilterVarAccessParse(const char *varAccess)
 
         varNameLen = idx;
 
-        dest->varName = strndup(input, varNameLen);
-        if (!dest->varName) {
+        if (VIR_STRNDUP(dest->varName, input, varNameLen) < 0) {
             virReportOOMError();
             goto err_exit;
         }
diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c
index 5b54a28..8115b9e 100644
--- a/src/conf/snapshot_conf.c
+++ b/src/conf/snapshot_conf.c
@@ -463,7 +463,7 @@ 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))) {
+            if (VIR_STRDUP(disk->name, def->dom->disks[idx]->dst) < 0) {
                 virReportOOMError();
                 goto cleanup;
             }
@@ -485,7 +485,7 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def,
         if (inuse)
             continue;
         disk = &def->disks[ndisks++];
-        if (!(disk->name = strdup(def->dom->disks[i]->dst))) {
+        if (VIR_STRDUP(disk->name, def->dom->disks[i]->dst) < 0) {
             virReportOOMError();
             goto cleanup;
         }
@@ -768,7 +768,7 @@ 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;
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 9f2012e..2a1a9ff 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -878,8 +878,7 @@ 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) {
+            if (VIR_STRDUP(ret->source.name, ret->name) < 0) {
                 virReportOOMError();
                 goto cleanup;
             }
@@ -1679,15 +1678,13 @@ virStoragePoolObjLoad(virStoragePoolObjListPtr pools,
     }
 
     VIR_FREE(pool->configFile);  /* for driver reload */
-    pool->configFile = strdup(path);
-    if (pool->configFile == NULL) {
+    if (VIR_STRDUP(pool->configFile, path) < 0) {
         virReportOOMError();
         virStoragePoolDefFree(def);
         return NULL;
     }
     VIR_FREE(pool->autostartLink); /* for driver reload */
-    pool->autostartLink = strdup(autostartLink);
-    if (pool->autostartLink == NULL) {
+    if (VIR_STRDUP(pool->autostartLink, autostartLink) < 0) {
         virReportOOMError();
         virStoragePoolDefFree(def);
         return NULL;
diff --git a/src/conf/virchrdev.c b/src/conf/virchrdev.c
index 025d4a8..2adf4aa 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,7 +73,7 @@ static char *virChrdevLockFilePath(const char *dev)
     char *filename;
     char *p;
 
-    if (!(devCopy = strdup(dev))) {
+    if (VIR_STRDUP(devCopy, dev) < 0) {
         virReportOOMError();
         goto cleanup;
     }
@@ -401,7 +401,7 @@ int virChrdevOpen(virChrdevsPtr devs,
         goto error;
 
     cbdata->devs = devs;
-    if (!(cbdata->path = strdup(path))) {
+    if (VIR_STRDUP(cbdata->path, path) < 0) {
         virReportOOMError();
         goto error;
     }
-- 
1.8.1.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]