[PATCH v2 23/37] Adapt to VIR_STRDUP in src/storage/*

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

 



---
 src/storage/parthelper.c              |  7 ++++---
 src/storage/storage_backend.c         | 16 ++++++----------
 src/storage/storage_backend_disk.c    | 14 +++++++-------
 src/storage/storage_backend_fs.c      | 17 ++++++++---------
 src/storage/storage_backend_iscsi.c   | 14 ++++++--------
 src/storage/storage_backend_logical.c | 24 ++++++++++++------------
 src/storage/storage_backend_mpath.c   |  3 +--
 src/storage/storage_backend_rbd.c     |  3 +--
 src/storage/storage_backend_scsi.c    | 16 +++++++---------
 src/storage/storage_driver.c          | 11 +++++------
 10 files changed, 57 insertions(+), 68 deletions(-)

diff --git a/src/storage/parthelper.c b/src/storage/parthelper.c
index c4af48f..a1fd516 100644
--- a/src/storage/parthelper.c
+++ b/src/storage/parthelper.c
@@ -44,6 +44,9 @@
 #include "virutil.h"
 #include "c-ctype.h"
 #include "configmake.h"
+#include "virstring.h"
+
+#define VIR_FROM_THIS VIR_FROM_NONE
 
 /* we don't need to include the full internal.h just for this */
 #define STREQ(a,b) (strcmp(a,b) == 0)
@@ -86,10 +89,8 @@ int main(int argc, char **argv)
     path = argv[1];
     if (virIsDevMapperDevice(path)) {
         partsep = "p";
-        canonical_path = strdup(path);
-        if (canonical_path == NULL) {
+        if (VIR_STRDUP(canonical_path, path) < 0)
             return 2;
-        }
     } else {
         if (virFileResolveLink(path, &canonical_path) != 0) {
             return 2;
diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index b85a5a9..f14de87 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -486,8 +486,7 @@ virStorageGenerateQcowEncryption(virConnectPtr conn,
         goto cleanup;
 
     def->usage_type = VIR_SECRET_USAGE_TYPE_VOLUME;
-    def->usage.volume = strdup(vol->target.path);
-    if (def->usage.volume == NULL) {
+    if (VIR_STRDUP(def->usage.volume, vol->target.path) < 0) {
         virReportOOMError();
         goto cleanup;
     }
@@ -1261,12 +1260,12 @@ virStorageBackendUpdateVolTargetInfoFD(virStorageVolTargetPtr target,
             target->perms.label = NULL;
         }
     } else {
-        target->perms.label = strdup(filecon);
-        freecon(filecon);
-        if (target->perms.label == NULL) {
+        if (VIR_STRDUP(target->perms.label, filecon) < 0) {
+            freecon(filecon);
             virReportOOMError();
             return -1;
         }
+        freecon(filecon);
     }
 #else
     target->perms.label = NULL;
@@ -1451,9 +1450,7 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool,
      * the original non-stable dev path
      */
 
-    stablepath = strdup(devpath);
-
-    if (stablepath == NULL)
+    if (VIR_STRDUP(stablepath, devpath) < 0)
         virReportOOMError();
 
     return stablepath;
@@ -1556,8 +1553,7 @@ virStorageBackendRunProgRegex(virStoragePoolObjPtr pool,
                 for (j = 0 ; j < nvars[i] ; j++) {
                     /* NB vars[0] is the full pattern, so we offset j by 1 */
                     p[vars[j+1].rm_eo] = '\0';
-                    if ((groups[ngroup++] =
-                         strdup(p + vars[j+1].rm_so)) == NULL) {
+                    if (VIR_STRDUP(groups[ngroup++], p + vars[j+1].rm_so) < 0) {
                         virReportOOMError();
                         goto cleanup;
                     }
diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backend_disk.c
index 6da2d12..c996416 100644
--- a/src/storage/storage_backend_disk.c
+++ b/src/storage/storage_backend_disk.c
@@ -66,14 +66,14 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool,
          * strip the path to form a reasonable pool-unique name
          */
         tmp = strrchr(groups[0], '/');
-        if ((vol->name = strdup(tmp ? tmp + 1 : groups[0])) == NULL) {
+        if (VIR_STRDUP(vol->name, tmp ? tmp + 1 : groups[0]) < 0) {
             virReportOOMError();
             return -1;
         }
     }
 
     if (vol->target.path == NULL) {
-        if ((devpath = strdup(groups[0])) == NULL) {
+        if (VIR_STRDUP(devpath, groups[0]) < 0) {
             virReportOOMError();
             return -1;
         }
@@ -92,7 +92,7 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool,
 
     if (vol->key == NULL) {
         /* XXX base off a unique key of the underlying disk */
-        if ((vol->key = strdup(vol->target.path)) == NULL) {
+        if (VIR_STRDUP(vol->key, vol->target.path) < 0) {
             virReportOOMError();
             return -1;
         }
@@ -119,8 +119,8 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool,
             return -1;
         }
 
-        if ((vol->source.extents[0].path =
-             strdup(pool->def->source.devices[0].path)) == NULL) {
+        if (VIR_STRDUP(vol->source.extents[0].path,
+                       pool->def->source.devices[0].path) < 0) {
             virReportOOMError();
             return -1;
         }
@@ -485,7 +485,7 @@ virStorageBackendDiskPartFormat(virStoragePoolObjPtr pool,
                     return -1;
                 }
             }
-            if ((*partFormat = strdup(partedFormat)) == NULL) {
+            if (VIR_STRDUP(*partFormat, partedFormat) < 0) {
                 virReportOOMError();
                 return -1;
             }
@@ -527,7 +527,7 @@ virStorageBackendDiskPartFormat(virStoragePoolObjPtr pool,
             }
         }
     } else {
-        if ((*partFormat = strdup("primary")) == NULL) {
+        if (VIR_STRDUP(*partFormat, "primary") < 0) {
             virReportOOMError();
             return -1;
         }
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index 8288b1e..e93da4c 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -207,8 +207,8 @@ virStorageBackendFileSystemNetFindPoolSourcesFunc(virStoragePoolObjPtr pool ATTR
     }
     src->nhost = 1;
 
-    if (!(src->hosts[0].name = strdup(state->host)) ||
-        !(src->dir = strdup(path))) {
+    if (VIR_STRDUP(src->hosts[0].name, state->host) < 0 ||
+        VIR_STRDUP(src->dir, path) < 0) {
         virReportOOMError();
         goto cleanup;
     }
@@ -395,7 +395,7 @@ virStorageBackendFileSystemMount(virStoragePoolObjPtr pool) {
         }
 
     } else {
-        if ((src = strdup(pool->def->source.devices[0].path)) == NULL) {
+        if (VIR_STRDUP(src, pool->def->source.devices[0].path) < 0) {
             virReportOOMError();
             return -1;
         }
@@ -571,7 +571,7 @@ virStorageBackendFileSystemProbe(const char *device,
         goto error;
     }
 
-    if ((libblkid_format = strdup(format)) == NULL) {
+    if (VIR_STRDUP(libblkid_format, format) < 0) {
         virReportOOMError();
         goto error;
     }
@@ -749,7 +749,7 @@ virStorageBackendFileSystemBuild(virConnectPtr conn ATTRIBUTE_UNUSED,
         goto error;
     }
 
-    if ((parent = strdup(pool->def->target.path)) == NULL) {
+    if (VIR_STRDUP(parent, pool->def->target.path) < 0) {
         virReportOOMError();
         goto error;
     }
@@ -833,7 +833,7 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED,
         if (VIR_ALLOC(vol) < 0)
             goto no_memory;
 
-        if ((vol->name = strdup(ent->d_name)) == NULL)
+        if (VIR_STRDUP(vol->name, ent->d_name) < 0)
             goto no_memory;
 
         vol->type = VIR_STORAGE_VOL_FILE;
@@ -843,7 +843,7 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED,
                         vol->name) == -1)
             goto no_memory;
 
-        if ((vol->key = strdup(vol->target.path)) == NULL)
+        if (VIR_STRDUP(vol->key, vol->target.path) < 0)
             goto no_memory;
 
         if ((ret = virStorageBackendProbeTarget(&vol->target,
@@ -1011,8 +1011,7 @@ virStorageBackendFileSystemVolCreate(virConnectPtr conn ATTRIBUTE_UNUSED,
     }
 
     VIR_FREE(vol->key);
-    vol->key = strdup(vol->target.path);
-    if (vol->key == NULL) {
+    if (VIR_STRDUP(vol->key, vol->target.path) < 0) {
         virReportOOMError();
         return -1;
     }
diff --git a/src/storage/storage_backend_iscsi.c b/src/storage/storage_backend_iscsi.c
index cf25919..355f690 100644
--- a/src/storage/storage_backend_iscsi.c
+++ b/src/storage/storage_backend_iscsi.c
@@ -125,11 +125,10 @@ virStorageBackendISCSIExtractSession(virStoragePoolObjPtr pool,
 {
     char **session = data;
 
-    if (STREQ(groups[1], pool->def->source.devices[0].path)) {
-        if ((*session = strdup(groups[0])) == NULL) {
-            virReportOOMError();
-            return -1;
-        }
+    if (STREQ(groups[1], pool->def->source.devices[0].path) &&
+        VIR_STRDUP(*session, groups[0]) < 0) {
+        virReportOOMError();
+        return -1;
     }
 
     return 0;
@@ -247,8 +246,7 @@ virStorageBackendIQNFound(const char *initiatoriqn,
                                  "of '%s'"), ISCSIADM);
                 goto out;
             }
-            *ifacename = strndup(line, token - line);
-            if (*ifacename == NULL) {
+            if (VIR_STRNDUP(*ifacename, line, token - line) < 0) {
                 ret = IQN_ERROR;
                 virReportOOMError();
                 goto out;
@@ -499,7 +497,7 @@ virStorageBackendISCSIGetTargets(virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
     struct virStorageBackendISCSITargetList *list = data;
     char *target;
 
-    if (!(target = strdup(groups[1]))) {
+    if (VIR_STRDUP(target, groups[1]) < 0) {
         virReportOOMError();
         return -1;
     }
diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c
index 316043f..77bc83b 100644
--- a/src/storage/storage_backend_logical.c
+++ b/src/storage/storage_backend_logical.c
@@ -100,7 +100,7 @@ virStorageBackendLogicalMakeVol(virStoragePoolObjPtr pool,
         is_new_vol = true;
         vol->type = VIR_STORAGE_VOL_BLOCK;
 
-        if ((vol->name = strdup(groups[0])) == NULL) {
+        if (VIR_STRDUP(vol->name, groups[0]) < 0) {
             virReportOOMError();
             goto cleanup;
         }
@@ -137,8 +137,7 @@ virStorageBackendLogicalMakeVol(virStoragePoolObjPtr pool,
         vol->backingStore.format = VIR_STORAGE_POOL_LOGICAL_LVM2;
     }
 
-    if (vol->key == NULL &&
-        (vol->key = strdup(groups[2])) == NULL) {
+    if (vol->key == NULL && VIR_STRDUP(vol->key, groups[2]) < 0) {
         virReportOOMError();
         goto cleanup;
     }
@@ -179,7 +178,10 @@ virStorageBackendLogicalMakeVol(virStoragePoolObjPtr pool,
     }
 
     /* Now parse the "devices" field separately */
-    regex = strdup(regex_unit);
+    if (VIR_STRDUP(regex, regex_unit) < 0) {
+        virReportOOMError();
+        goto cleanup;
+    }
 
     for (i = 1; i < nextents; i++) {
         if (VIR_REALLOC_N(regex, strlen(regex) + strlen(regex_unit) + 2) < 0) {
@@ -229,20 +231,20 @@ virStorageBackendLogicalMakeVol(virStoragePoolObjPtr pool,
     /* vars[0] is skipped */
     for (i = 0; i < nextents; i++) {
         int j, len;
-        const char *offset_str = NULL;
+        char *offset_str = NULL;
 
         j = (i * 2) + 1;
         len = vars[j].rm_eo - vars[j].rm_so;
         p[vars[j].rm_eo] = '\0';
 
-        if ((vol->source.extents[vol->source.nextent].path =
-            strndup(p + vars[j].rm_so, len)) == NULL) {
+        if (VIR_STRNDUP(vol->source.extents[vol->source.nextent].path,
+                        p + vars[j].rm_so, len) < 0) {
             virReportOOMError();
             goto cleanup;
         }
 
         len = vars[j + 1].rm_eo - vars[j + 1].rm_so;
-        if (!(offset_str = strndup(p + vars[j + 1].rm_so, len))) {
+        if (VIR_STRNDUP(offset_str, p + vars[j + 1].rm_so, len) < 0) {
             virReportOOMError();
             goto cleanup;
         }
@@ -358,10 +360,8 @@ virStorageBackendLogicalFindPoolSourcesFunc(virStoragePoolObjPtr pool ATTRIBUTE_
     virStoragePoolSourceDevicePtr dev;
     virStoragePoolSource *thisSource;
 
-    pvname = strdup(groups[0]);
-    vgname = strdup(groups[1]);
-
-    if (pvname == NULL || vgname == NULL) {
+    if (VIR_STRDUP(pvname, groups[0]) < 0 ||
+        VIR_STRDUP(vgname, groups[1]) < 0) {
         virReportOOMError();
         goto err_no_memory;
     }
diff --git a/src/storage/storage_backend_mpath.c b/src/storage/storage_backend_mpath.c
index 6e742f7..9545d54 100644
--- a/src/storage/storage_backend_mpath.c
+++ b/src/storage/storage_backend_mpath.c
@@ -99,8 +99,7 @@ virStorageBackendMpathNewVol(virStoragePoolObjPtr pool,
     }
 
     /* XXX should use logical unit's UUID instead */
-    vol->key = strdup(vol->target.path);
-    if (vol->key == NULL) {
+    if (VIR_STRDUP(vol->key, vol->target.path) < 0) {
         virReportOOMError();
         goto cleanup;
     }
diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c
index ca23d4b..3bdd73a 100644
--- a/src/storage/storage_backend_rbd.c
+++ b/src/storage/storage_backend_rbd.c
@@ -333,8 +333,7 @@ static int virStorageBackendRBDRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED,
         if (VIR_ALLOC(vol) < 0)
             goto out_of_memory;
 
-        vol->name = strdup(name);
-        if (vol->name == NULL) {
+        if (VIR_STRDUP(vol->name, name) < 0) {
             VIR_FREE(vol);
             goto out_of_memory;
         }
diff --git a/src/storage/storage_backend_scsi.c b/src/storage/storage_backend_scsi.c
index 154a56a..ac8a156 100644
--- a/src/storage/storage_backend_scsi.c
+++ b/src/storage/storage_backend_scsi.c
@@ -188,7 +188,7 @@ virStorageBackendSCSISerial(const char *dev)
             *nl = '\0';
     } else {
         VIR_FREE(serial);
-        if (!(serial = strdup(dev)))
+        if (VIR_STRDUP(serial, dev) < 0)
             virReportOOMError();
     }
 
@@ -333,9 +333,7 @@ getNewStyleBlockDevice(const char *lun_path,
             continue;
         }
 
-        *block_device = strdup(block_dirent->d_name);
-
-        if (*block_device == NULL) {
+        if (VIR_STRDUP(*block_device, block_dirent->d_name) < 0) {
             virReportOOMError();
             closedir(block_dir);
             retval = -1;
@@ -373,9 +371,7 @@ getOldStyleBlockDevice(const char *lun_path ATTRIBUTE_UNUSED,
         retval = -1;
     } else {
         blockp++;
-        *block_device = strdup(blockp);
-
-        if (*block_device == NULL) {
+        if (VIR_STRDUP(*block_device, blockp) < 0) {
             virReportOOMError();
             retval = -1;
             goto out;
@@ -630,8 +626,10 @@ getAdapterName(virStoragePoolSourceAdapter adapter)
 {
     char *name = NULL;
 
-    if (adapter.type != VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST)
-        return strdup(adapter.data.name);
+    if (adapter.type != VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST) {
+        ignore_value(VIR_STRDUP(name, adapter.data.name));
+        return name;
+    }
 
     if (!(name = virGetFCHostNameByWWN(NULL,
                                        adapter.data.fchost.wwnn,
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 990f0b1..824f501 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -144,7 +144,7 @@ storageStateInitialize(bool privileged,
     storageDriverLock(driverState);
 
     if (privileged) {
-        if ((base = strdup(SYSCONFDIR "/libvirt")) == NULL)
+        if (VIR_STRDUP(base, SYSCONFDIR "/libvirt") < 0)
             goto out_of_memory;
     } else {
         base = virGetUserConfigDirectory();
@@ -336,7 +336,7 @@ storageConnectListStoragePools(virConnectPtr conn,
     for (i = 0 ; i < driver->pools.count && got < nnames ; i++) {
         virStoragePoolObjLock(driver->pools.objs[i]);
         if (virStoragePoolObjIsActive(driver->pools.objs[i])) {
-            if (!(names[got] = strdup(driver->pools.objs[i]->def->name))) {
+            if (VIR_STRDUP(names[got], driver->pools.objs[i]->def->name) < 0) {
                 virStoragePoolObjUnlock(driver->pools.objs[i]);
                 virReportOOMError();
                 goto cleanup;
@@ -384,7 +384,7 @@ storageConnectListDefinedStoragePools(virConnectPtr conn,
     for (i = 0 ; i < driver->pools.count && got < nnames ; i++) {
         virStoragePoolObjLock(driver->pools.objs[i]);
         if (!virStoragePoolObjIsActive(driver->pools.objs[i])) {
-            if (!(names[got] = strdup(driver->pools.objs[i]->def->name))) {
+            if (VIR_STRDUP(names[got], driver->pools.objs[i]->def->name) < 0) {
                 virStoragePoolObjUnlock(driver->pools.objs[i]);
                 virReportOOMError();
                 goto cleanup;
@@ -1117,7 +1117,7 @@ storagePoolListVolumes(virStoragePoolPtr obj,
     }
 
     for (i = 0 ; i < pool->volumes.count && n < maxnames ; i++) {
-        if ((names[n++] = strdup(pool->volumes.objs[i]->name)) == NULL) {
+        if (VIR_STRDUP(names[n++], pool->volumes.objs[i]->name) < 0) {
             virReportOOMError();
             goto cleanup;
         }
@@ -2340,8 +2340,7 @@ storageVolGetPath(virStorageVolPtr obj) {
         goto cleanup;
     }
 
-    ret = strdup(vol->target.path);
-    if (ret == NULL)
+    if (VIR_STRDUP(ret, vol->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]