[PATCH v2 16/37] Adapt to VIR_STRDUP in src/parallels/*

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

 



---
 src/parallels/parallels_driver.c  | 34 +++++++++++++++++-----------------
 src/parallels/parallels_network.c | 12 ++++++------
 src/parallels/parallels_storage.c | 38 +++++++++++++++-----------------------
 3 files changed, 38 insertions(+), 46 deletions(-)

diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c
index c29a5ba..fd3e3bc 100644
--- a/src/parallels/parallels_driver.c
+++ b/src/parallels/parallels_driver.c
@@ -186,7 +186,7 @@ parallelsGetSerialInfo(virDomainChrDefPtr chr,
             return -1;
         }
 
-        if (!(chr->source.data.file.path = strdup(tmp)))
+        if (VIR_STRDUP(chr->source.data.file.path, tmp) < 0)
             goto no_memory;
     } else if (virJSONValueObjectHasKey(value, "socket")) {
         chr->source.type = VIR_DOMAIN_CHR_TYPE_UNIX;
@@ -197,7 +197,7 @@ parallelsGetSerialInfo(virDomainChrDefPtr chr,
             return -1;
         }
 
-        if (!(chr->source.data.nix.path = strdup(tmp)))
+        if (VIR_STRDUP(chr->source.data.nix.path, tmp) < 0)
             goto no_memory;
         chr->source.data.nix.listen = false;
     } else if (virJSONValueObjectHasKey(value, "real")) {
@@ -209,7 +209,7 @@ parallelsGetSerialInfo(virDomainChrDefPtr chr,
             return -1;
         }
 
-        if (!(chr->source.data.file.path = strdup(tmp)))
+        if (VIR_STRDUP(chr->source.data.file.path, tmp) < 0)
             goto no_memory;
     } else {
         parallelsParseError();
@@ -318,7 +318,7 @@ parallelsGetHddInfo(virDomainDefPtr def,
             return -1;
         }
 
-        if (!(disk->src = strdup(tmp))) {
+        if (VIR_STRDUP(disk->src, tmp) < 0) {
             virReportOOMError();
             return -1;
         }
@@ -330,7 +330,7 @@ parallelsGetHddInfo(virDomainDefPtr def,
             return -1;
         }
 
-        if (!(disk->src = strdup(tmp))) {
+        if (VIR_STRDUP(disk->src, tmp) < 0) {
             virReportOOMError();
             return -1;
         }
@@ -454,7 +454,7 @@ parallelsGetNetInfo(virDomainNetDefPtr net,
 
     /* use device name, shown by prlctl as target device
      * for identifying network adapter in virDomainDefineXML */
-    if (!(net->ifname = strdup(key))) {
+    if (VIR_STRDUP(net->ifname, key) < 0) {
         virReportOOMError();
         goto error;
     }
@@ -478,7 +478,7 @@ parallelsGetNetInfo(virDomainNetDefPtr net,
             goto error;
         }
 
-        if (!(net->data.network.name = strdup(tmp))) {
+        if (VIR_STRDUP(net->data.network.name, tmp) < 0) {
             virReportOOMError();
             goto error;
         }
@@ -493,7 +493,7 @@ parallelsGetNetInfo(virDomainNetDefPtr net,
             goto error;
         }
 
-        if (!(net->data.network.name = strdup(PARALLELS_ROUTED_NETWORK_NAME))) {
+        if (VIR_STRDUP(net->data.network.name, PARALLELS_ROUTED_NETWORK_NAME) < 0) {
             virReportOOMError();
             goto error;
         }
@@ -641,7 +641,7 @@ parallelsAddVNCInfo(virDomainDefPtr def, virJSONValuePtr jobj_root)
 
     gr->nListens = 1;
 
-    if (!(gr->listens[0].address = strdup(tmp)))
+    if (VIR_STRDUP(gr->listens[0].address, tmp) < 0)
         goto no_memory;
 
     gr->listens[0].type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS;
@@ -686,7 +686,7 @@ parallelsLoadDomain(parallelsConnPtr privconn, virJSONValuePtr jobj)
         parallelsParseError();
         goto cleanup;
     }
-    if (!(def->name = strdup(tmp)))
+    if (VIR_STRDUP(def->name, tmp) < 0)
         goto no_memory;
 
     if (!(tmp = virJSONValueObjectGetString(jobj, "ID"))) {
@@ -704,7 +704,7 @@ parallelsLoadDomain(parallelsConnPtr privconn, virJSONValuePtr jobj)
         parallelsParseError();
         goto cleanup;
     }
-    if (!(def->description = strdup(tmp)))
+    if (VIR_STRDUP(def->description, tmp) < 0)
         goto no_memory;
 
     if (!(jobj2 = virJSONValueObjectGet(jobj, "Hardware"))) {
@@ -771,12 +771,12 @@ parallelsLoadDomain(parallelsConnPtr privconn, virJSONValuePtr jobj)
     }
 
     if (STREQ(tmp, "CT")) {
-        if (!(def->os.type = strdup("exe")))
+        if (VIR_STRDUP(def->os.type, "exe") < 0)
             goto no_memory;
-        if (!(def->os.init = strdup("/sbin/init")))
+        if (VIR_STRDUP(def->os.init, "/sbin/init") < 0)
             goto no_memory;
     } else if (STREQ(tmp, "VM")) {
-        if (!(def->os.type = strdup("hvm")))
+        if (VIR_STRDUP(def->os.type, "hvm") < 0)
             goto no_memory;
     }
 
@@ -792,7 +792,7 @@ parallelsLoadDomain(parallelsConnPtr privconn, virJSONValuePtr jobj)
         parallelsParseError();
         goto cleanup;
     }
-    if (!(pdom->uuid = strdup(tmp)))
+    if (VIR_STRDUP(pdom->uuid, tmp) < 0)
         goto no_memory;
 
     if (!(tmp = virJSONValueObjectGetString(jobj, "Home"))) {
@@ -800,7 +800,7 @@ parallelsLoadDomain(parallelsConnPtr privconn, virJSONValuePtr jobj)
         goto cleanup;
     }
 
-    if (!(pdom->home = strdup(tmp)))
+    if (VIR_STRDUP(pdom->home, tmp) < 0)
         goto no_memory;
 
     if (!(state = virJSONValueObjectGetString(jobj, "State"))) {
@@ -1239,7 +1239,7 @@ parallelsDomainGetOSType(virDomainPtr domain)
         goto cleanup;
     }
 
-    if (!(ret = strdup(privdom->def->os.type)))
+    if (VIR_STRDUP(ret, privdom->def->os.type) < 0)
         virReportOOMError();
 
   cleanup:
diff --git a/src/parallels/parallels_network.c b/src/parallels/parallels_network.c
index 23109d3..29e0e99 100644
--- a/src/parallels/parallels_network.c
+++ b/src/parallels/parallels_network.c
@@ -66,7 +66,7 @@ static int parallelsGetBridgedNetInfo(virNetworkDefPtr def, virJSONValuePtr jobj
         goto cleanup;
     }
 
-    if (!(def->bridge = strdup(last_component(bridgePath)))) {
+    if (VIR_STRDUP(def->bridge, last_component(bridgePath)) < 0) {
         virReportOOMError();
         goto cleanup;
     }
@@ -130,7 +130,7 @@ static int parallelsGetHostOnlyNetInfo(virNetworkDefPtr def, const char *name)
         goto cleanup;
     }
 
-    if (!(def->ips[0].family = strdup("ipv4"))) {
+    if (VIR_STRDUP(def->ips[0].family, "ipv4") < 0) {
         virReportOOMError();
         goto cleanup;
     };
@@ -207,7 +207,7 @@ parallelsLoadNetwork(parallelsConnPtr privconn, virJSONValuePtr jobj)
         goto cleanup;
     }
 
-    if (!(def->name = strdup(tmp)))
+    if (VIR_STRDUP(def->name, tmp) < 0)
         goto no_memory;
 
     /* Network names are unique in Parallels Cloud Server, so we can make
@@ -264,7 +264,7 @@ parallelsAddRoutedNetwork(parallelsConnPtr privconn)
 
     def->forward.type = VIR_NETWORK_FORWARD_ROUTE;
 
-    if (!(def->name = strdup(PARALLELS_ROUTED_NETWORK_NAME)))
+    if (VIR_STRDUP(def->name, PARALLELS_ROUTED_NETWORK_NAME) < 0)
         goto no_memory;
 
     if (virUUIDParse(PARALLELS_ROUTED_NETWORK_UUID, def->uuid) < 0) {
@@ -390,7 +390,7 @@ static int parallelsConnectListNetworks(virConnectPtr conn,
     for (i = 0 ; i < privconn->networks.count && got < nnames ; i++) {
         virNetworkObjLock(privconn->networks.objs[i]);
         if (virNetworkObjIsActive(privconn->networks.objs[i])) {
-            if (!(names[got] = strdup(privconn->networks.objs[i]->def->name))) {
+            if (VIR_STRDUP(names[got], privconn->networks.objs[i]->def->name) < 0) {
                 virNetworkObjUnlock(privconn->networks.objs[i]);
                 virReportOOMError();
                 goto cleanup;
@@ -438,7 +438,7 @@ static int parallelsConnectListDefinedNetworks(virConnectPtr conn,
     for (i = 0 ; i < privconn->networks.count && got < nnames ; i++) {
         virNetworkObjLock(privconn->networks.objs[i]);
         if (!virNetworkObjIsActive(privconn->networks.objs[i])) {
-            if (!(names[got] = strdup(privconn->networks.objs[i]->def->name))) {
+            if (VIR_STRDUP(names[got], privconn->networks.objs[i]->def->name) < 0) {
                 virNetworkObjUnlock(privconn->networks.objs[i]);
                 virReportOOMError();
                 goto cleanup;
diff --git a/src/parallels/parallels_storage.c b/src/parallels/parallels_storage.c
index 4c98e43..97e2206 100644
--- a/src/parallels/parallels_storage.c
+++ b/src/parallels/parallels_storage.c
@@ -136,17 +136,13 @@ static char *parallelsMakePoolName(virConnectPtr conn, const char *path)
         bool found = false;
         int j;
 
-        if (!(name = strdup(path))) {
+        if (VIR_STRDUP(name, path) < 0) {
             virReportOOMError();
             return NULL;
         }
 
-        if (i == 0)
-            name = strdup(path);
-        else
-            ignore_value(virAsprintf(&name, "%s-%u", path, i));
-
-        if (!name) {
+        if ((!i && VIR_STRDUP(name, path) < 0) ||
+            (i && virAsprintf(&name, "%s-%u", path, i) < 0)) {
             virReportOOMError();
             return 0;
         }
@@ -195,7 +191,8 @@ parallelsPoolCreateByPath(virConnectPtr conn, const char *path)
     }
 
     def->type = VIR_STORAGE_POOL_DIR;
-    def->target.path = strdup(path);
+    if (VIR_STRDUP(def->target.path, path) < 0)
+        goto no_memory;
 
     if (!(pool = virStoragePoolObjAssignDef(pools, def)))
         goto error;
@@ -231,8 +228,7 @@ parallelsPoolAddByDomain(virConnectPtr conn, virDomainObjPtr dom)
     virStoragePoolObjPtr pool = NULL;
     int j;
 
-    poolPath = mdir_name(pdom->home);
-    if (!poolPath) {
+    if (VIR_STRDUP(poolPath, mdir_name(pdom->home)) < 0) {
         virReportOOMError();
         return NULL;
     }
@@ -324,7 +320,7 @@ static int parallelsAddDiskVolume(virStoragePoolObjPtr pool,
     if (!(def->target.path = realpath(diskPath, NULL)))
         goto no_memory;
 
-    if (!(def->key = strdup(def->target.path)))
+    if (VIR_STRDUP(def->key, def->target.path) < 0)
         goto no_memory;
 
     if (VIR_REALLOC_N(pool->volumes.objs, pool->volumes.count + 1) < 0)
@@ -425,7 +421,7 @@ static int parallelsLoadPools(virConnectPtr conn)
     char *base = NULL;
     size_t i;
 
-    if ((base = strdup(SYSCONFDIR "/libvirt")) == NULL)
+    if (VIR_STRDUP(base, SYSCONFDIR "/libvirt") < 0)
         goto out_of_memory;
 
     /* Configuration path is /etc/libvirt/parallels-storage/... . */
@@ -540,7 +536,7 @@ parallelsConnectListStoragePools(virConnectPtr conn, char **const names, int nna
     for (i = 0; i < privconn->pools.count && n < nnames; i++) {
         virStoragePoolObjLock(privconn->pools.objs[i]);
         if (virStoragePoolObjIsActive(privconn->pools.objs[i]) &&
-            !(names[n++] = strdup(privconn->pools.objs[i]->def->name))) {
+            VIR_STRDUP(names[n++], privconn->pools.objs[i]->def->name) < 0) {
             virStoragePoolObjUnlock(privconn->pools.objs[i]);
             goto no_memory;
         }
@@ -590,7 +586,7 @@ parallelsConnectListDefinedStoragePools(virConnectPtr conn,
     for (i = 0; i < privconn->pools.count && n < nnames; i++) {
         virStoragePoolObjLock(privconn->pools.objs[i]);
         if (!virStoragePoolObjIsActive(privconn->pools.objs[i]) &&
-            !(names[n++] = strdup(privconn->pools.objs[i]->def->name))) {
+            VIR_STRDUP(names[n++], privconn->pools.objs[i]->def->name) < 0) {
             virStoragePoolObjUnlock(privconn->pools.objs[i]);
             goto no_memory;
         }
@@ -758,8 +754,7 @@ parallelsStoragePoolDefineXML(virConnectPtr conn,
     }
     def = NULL;
 
-    pool->configFile = strdup("\0");
-    if (!pool->configFile) {
+    if (VIR_STRDUP(pool->configFile, "\0") < 0) {
         virReportOOMError();
         goto cleanup;
     }
@@ -1085,7 +1080,7 @@ parallelsStoragePoolListVolumes(virStoragePoolPtr pool,
     }
 
     for (i = 0; i < privpool->volumes.count && n < maxnames; i++) {
-        if ((names[n++] = strdup(privpool->volumes.objs[i]->name)) == NULL) {
+        if (VIR_STRDUP(names[n++], privpool->volumes.objs[i]->name) < 0) {
             virReportOOMError();
             goto error;
         }
@@ -1271,8 +1266,7 @@ parallelsStorageVolDefineXML(virStoragePoolObjPtr pool,
         goto cleanup;
     }
 
-    privvol->key = strdup(privvol->target.path);
-    if (privvol->key == NULL) {
+    if (VIR_STRDUP(privvol->key, privvol->target.path) < 0) {
         virReportOOMError();
         goto cleanup;
     }
@@ -1412,8 +1406,7 @@ parallelsStorageVolCreateXMLFrom(virStoragePoolPtr pool,
         goto cleanup;
     }
 
-    privvol->key = strdup(privvol->target.path);
-    if (privvol->key == NULL) {
+    if (VIR_STRDUP(privvol->key, privvol->target.path) < 0) {
         virReportOOMError();
         goto cleanup;
     }
@@ -1659,8 +1652,7 @@ parallelsStorageVolGetPath(virStorageVolPtr vol)
         goto cleanup;
     }
 
-    ret = strdup(privvol->target.path);
-    if (ret == NULL)
+    if (VIR_STRDUP(ret, privvol->target.path) < 0)
         virReportOOMError();
 
 cleanup:
-- 
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]