Let's make use of the auto __cleanup capabilities cleaning up any
now unnecessary goto paths.

Signed-off-by: John Ferlan <jfer...@redhat.com>
Reviewed-by: Erik Skultety <eskul...@redhat.com>
---
 src/storage/storage_backend_iscsi_direct.c |  3 +-
 src/storage/storage_backend_sheepdog.c     |  6 +--
 src/storage/storage_backend_zfs.c          | 15 ++----
 src/util/virstoragefile.c                  | 58 ++++++++--------------
 4 files changed, 28 insertions(+), 54 deletions(-)

diff --git a/src/storage/storage_backend_iscsi_direct.c 
b/src/storage/storage_backend_iscsi_direct.c
index 42060dd758..cf48c29cde 100644
--- a/src/storage/storage_backend_iscsi_direct.c
+++ b/src/storage/storage_backend_iscsi_direct.c
@@ -411,7 +411,7 @@ virISCSIDirectUpdateTargets(struct iscsi_context *iscsi,
     struct iscsi_discovery_address *addr;
     struct iscsi_discovery_address *tmp_addr;
     size_t tmp_ntargets = 0;
-    char **tmp_targets = NULL;
+    VIR_AUTOPTR(virString) tmp_targets = NULL;
 
     if (!(addr = iscsi_discovery_sync(iscsi))) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -439,7 +439,6 @@ virISCSIDirectUpdateTargets(struct iscsi_context *iscsi,
     ret = 0;
  cleanup:
     iscsi_free_discovery_data(iscsi, addr);
-    virStringListFreeCount(tmp_targets, tmp_ntargets);
     return ret;
 }
 
diff --git a/src/storage/storage_backend_sheepdog.c 
b/src/storage/storage_backend_sheepdog.c
index 7cba6e02aa..9ab318bb4d 100644
--- a/src/storage/storage_backend_sheepdog.c
+++ b/src/storage/storage_backend_sheepdog.c
@@ -138,9 +138,9 @@ virStorageBackendSheepdogRefreshAllVol(virStoragePoolObjPtr 
pool)
 {
     int ret = -1;
     char *output = NULL;
-    char **lines = NULL;
-    char **cells = NULL;
     size_t i;
+    VIR_AUTOPTR(virString) lines = NULL;
+    VIR_AUTOPTR(virString) cells = NULL;
 
     virCommandPtr cmd = virCommandNewArgList(SHEEPDOGCLI, "vdi", "list", "-r", 
NULL);
     virStorageBackendSheepdogAddHostArg(cmd, pool);
@@ -173,8 +173,6 @@ virStorageBackendSheepdogRefreshAllVol(virStoragePoolObjPtr 
pool)
 
  cleanup:
     virCommandFree(cmd);
-    virStringListFree(lines);
-    virStringListFree(cells);
     VIR_FREE(output);
     return ret;
 }
diff --git a/src/storage/storage_backend_zfs.c 
b/src/storage/storage_backend_zfs.c
index ec39d9403b..4235b48c14 100644
--- a/src/storage/storage_backend_zfs.c
+++ b/src/storage/storage_backend_zfs.c
@@ -104,13 +104,13 @@ virStorageBackendZFSParseVol(virStoragePoolObjPtr pool,
                              const char *volume_string)
 {
     int ret = -1;
-    char **tokens;
     size_t count;
-    char **name_tokens = NULL;
     char *vol_name;
     bool is_new_vol = false;
     virStorageVolDefPtr volume = NULL;
     virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
+    VIR_AUTOPTR(virString) tokens = NULL;
+    VIR_AUTOPTR(virString) name_tokens = NULL;
 
     if (!(tokens = virStringSplitCount(volume_string, "\t", 0, &count)))
         return -1;
@@ -169,8 +169,6 @@ virStorageBackendZFSParseVol(virStoragePoolObjPtr pool,
 
     ret = 0;
  cleanup:
-    virStringListFree(tokens);
-    virStringListFree(name_tokens);
     if (is_new_vol)
         virStorageVolDefFree(volume);
     return ret;
@@ -183,8 +181,8 @@ virStorageBackendZFSFindVols(virStoragePoolObjPtr pool,
     virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
     virCommandPtr cmd = NULL;
     char *volumes_list = NULL;
-    char **lines = NULL;
     size_t i;
+    VIR_AUTOPTR(virString) lines = NULL;
 
     /**
      * $ zfs list -Hp -t volume -o name,volsize -r test
@@ -221,7 +219,6 @@ virStorageBackendZFSFindVols(virStoragePoolObjPtr pool,
 
  cleanup:
     virCommandFree(cmd);
-    virStringListFree(lines);
     VIR_FREE(volumes_list);
 
     return 0;
@@ -233,9 +230,9 @@ virStorageBackendZFSRefreshPool(virStoragePoolObjPtr pool 
ATTRIBUTE_UNUSED)
     virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
     virCommandPtr cmd = NULL;
     char *zpool_props = NULL;
-    char **lines = NULL;
-    char **tokens = NULL;
     size_t i;
+    VIR_AUTOPTR(virString) lines = NULL;
+    VIR_AUTOPTR(virString) tokens = NULL;
 
     /**
      * $ zpool get -Hp health,size,free,allocated test
@@ -296,8 +293,6 @@ virStorageBackendZFSRefreshPool(virStoragePoolObjPtr pool 
ATTRIBUTE_UNUSED)
 
  cleanup:
     virCommandFree(cmd);
-    virStringListFree(lines);
-    virStringListFree(tokens);
     VIR_FREE(zpool_props);
 
     return 0;
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 1eb1ede59d..fc26c2f22e 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1594,11 +1594,10 @@ virStorageFileParseBackingStoreStr(const char *str,
                                    char **target,
                                    unsigned int *chainIndex)
 {
-    char **strings = NULL;
     size_t nstrings;
     unsigned int idx = 0;
     char *suffix;
-    int ret = -1;
+    VIR_AUTOPTR(virString) strings = NULL;
 
     *chainIndex = 0;
 
@@ -1608,19 +1607,15 @@ virStorageFileParseBackingStoreStr(const char *str,
     if (nstrings == 2) {
         if (virStrToLong_uip(strings[1], &suffix, 10, &idx) < 0 ||
             STRNEQ(suffix, "]"))
-            goto cleanup;
+            return -1;
     }
 
     if (target &&
         VIR_STRDUP(*target, strings[0]) < 0)
-        goto cleanup;
+        return -1;
 
     *chainIndex = idx;
-    ret = 0;
-
- cleanup:
-    virStringListFreeCount(strings, nstrings);
-    return ret;
+    return 0;
 }
 
 
@@ -2677,8 +2672,8 @@ virStorageSourceParseBackingURI(virStorageSourcePtr src,
 {
     virURIPtr uri = NULL;
     const char *path = NULL;
-    char **scheme = NULL;
     int ret = -1;
+    VIR_AUTOPTR(virString) scheme = NULL;
 
     if (!(uri = virURIParse(uristr))) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -2772,7 +2767,6 @@ virStorageSourceParseBackingURI(virStorageSourcePtr src,
 
  cleanup:
     virURIFree(uri);
-    virStringListFree(scheme);
     return ret;
 }
 
@@ -2783,7 +2777,7 @@ virStorageSourceRBDAddHost(virStorageSourcePtr src,
 {
     char *port;
     size_t skip;
-    char **parts;
+    VIR_AUTOPTR(virString) parts = NULL;
 
     if (VIR_EXPAND_N(src->hosts, src->nhosts, 1) < 0)
         return -1;
@@ -2808,7 +2802,6 @@ virStorageSourceRBDAddHost(virStorageSourcePtr src,
     if (!parts)
         goto error;
     src->hosts[src->nhosts-1].name = virStringListJoin((const char **)parts, 
":");
-    virStringListFree(parts);
     if (!src->hosts[src->nhosts-1].name)
         goto error;
 
@@ -2940,16 +2933,15 @@ static int
 virStorageSourceParseNBDColonString(const char *nbdstr,
                                     virStorageSourcePtr src)
 {
-    char **backing = NULL;
-    int ret = -1;
+    VIR_AUTOPTR(virString) backing = NULL;
 
     if (!(backing = virStringSplit(nbdstr, ":", 0)))
-        goto cleanup;
+        return -1;
 
     /* we know that backing[0] now equals to "nbd" */
 
     if (VIR_ALLOC_N(src->hosts, 1) < 0)
-        goto cleanup;
+        return -1;
 
     src->nhosts = 1;
     src->hosts->transport = VIR_STORAGE_NET_HOST_TRANS_TCP;
@@ -2962,44 +2954,39 @@ virStorageSourceParseNBDColonString(const char *nbdstr,
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("missing remote information in '%s' for protocol 
nbd"),
                        nbdstr);
-        goto cleanup;
+        return -1;
     } else if (STREQ(backing[1], "unix")) {
         if (!backing[2]) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("missing unix socket path in nbd backing string 
%s"),
                            nbdstr);
-            goto cleanup;
+            return -1;
         }
 
         if (VIR_STRDUP(src->hosts->socket, backing[2]) < 0)
-            goto cleanup;
+            return -1;
 
    } else {
         if (VIR_STRDUP(src->hosts->name, backing[1]) < 0)
-            goto cleanup;
+            return -1;
 
         if (!backing[2]) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("missing port in nbd string '%s'"),
                            nbdstr);
-            goto cleanup;
+            return -1;
         }
 
         if (virStringParsePort(backing[2], &src->hosts->port) < 0)
-            goto cleanup;
+            return -1;
     }
 
     if (backing[3] && STRPREFIX(backing[3], "exportname=")) {
         if (VIR_STRDUP(src->path, backing[3] + strlen("exportname=")) < 0)
-            goto cleanup;
+            return -1;
     }
 
-    ret = 0;
-
- cleanup:
-    virStringListFree(backing);
-
-    return ret;
+    return 0;
 }
 
 
@@ -4250,9 +4237,8 @@ virStorageFileGetRelativeBackingPath(virStorageSourcePtr 
top,
 int
 virStorageFileCheckCompat(const char *compat)
 {
-    char **version;
     unsigned int result;
-    int ret = -1;
+    VIR_AUTOPTR(virString) version = NULL;
 
     if (!compat)
         return 0;
@@ -4263,13 +4249,9 @@ virStorageFileCheckCompat(const char *compat)
         virStrToLong_ui(version[1], NULL, 10, &result) < 0) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
                        _("forbidden characters in 'compat' attribute"));
-        goto cleanup;
+        return -1;
     }
-    ret = 0;
-
- cleanup:
-    virStringListFree(version);
-    return ret;
+    return 0;
 }
 
 
-- 
2.20.1

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

Reply via email to