[PATCH 02/15] conf: Introduce VIR_DEFINE_AUTOPTR_FUNC for virStoragePoolSource

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

 



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

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/conf/storage_conf.c                    |  4 ++--
 src/conf/storage_conf.h                    |  2 ++
 src/storage/storage_backend_fs.c           |  3 +--
 src/storage/storage_backend_gluster.c      |  3 +--
 src/storage/storage_backend_iscsi.c        |  3 +--
 src/storage/storage_backend_iscsi_direct.c |  3 +--
 src/test/test_driver.c                     | 14 +++++++-------
 7 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 9cd3d836a3..6099c64b26 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -625,7 +625,8 @@ virStoragePoolDefParseSourceString(const char *srcSpec,
     xmlDocPtr doc = NULL;
     xmlNodePtr node = NULL;
     xmlXPathContextPtr xpath_ctxt = NULL;
-    virStoragePoolSourcePtr def = NULL, ret = NULL;
+    VIR_AUTOPTR(virStoragePoolSource) def = NULL;
+    virStoragePoolSourcePtr ret = NULL;
 
     if (!(doc = virXMLParseStringCtxt(srcSpec,
                                       _("(storage_source_specification)"),
@@ -647,7 +648,6 @@ virStoragePoolDefParseSourceString(const char *srcSpec,
 
     VIR_STEAL_PTR(ret, def);
  cleanup:
-    virStoragePoolSourceFree(def);
     xmlFreeDoc(doc);
     xmlXPathFreeContext(xpath_ctxt);
 
diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h
index 1ba4b80616..3fa97bba76 100644
--- a/src/conf/storage_conf.h
+++ b/src/conf/storage_conf.h
@@ -460,4 +460,6 @@ VIR_ENUM_DECL(virStoragePartedFs);
                  VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_AUTOSTART  | \
                  VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_POOL_TYPE)
 
+VIR_DEFINE_AUTOPTR_FUNC(virStoragePoolSource, virStoragePoolSourceFree);
+
 #endif /* LIBVIRT_STORAGE_CONF_H */
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index ddb422d874..06c76fde4f 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -145,7 +145,7 @@ virStorageBackendFileSystemNetFindPoolSources(const char *srcSpec,
             .sources = NULL
         }
     };
-    virStoragePoolSourcePtr source = NULL;
+    VIR_AUTOPTR(virStoragePoolSource) source = NULL;
     char *ret = NULL;
     size_t i;
     int retNFS = -1;
@@ -196,7 +196,6 @@ virStorageBackendFileSystemNetFindPoolSources(const char *srcSpec,
         virStoragePoolSourceClear(&state.list.sources[i]);
     VIR_FREE(state.list.sources);
 
-    virStoragePoolSourceFree(source);
     return ret;
 }
 
diff --git a/src/storage/storage_backend_gluster.c b/src/storage/storage_backend_gluster.c
index e09bc54196..8c6205b081 100644
--- a/src/storage/storage_backend_gluster.c
+++ b/src/storage/storage_backend_gluster.c
@@ -489,7 +489,7 @@ virStorageBackendGlusterFindPoolSources(const char *srcSpec,
                                       .nsources = 0,
                                       .sources = NULL
                                     };
-    virStoragePoolSourcePtr source = NULL;
+    VIR_AUTOPTR(virStoragePoolSource) source = NULL;
     char *ret = NULL;
     int rc;
     size_t i;
@@ -532,7 +532,6 @@ virStorageBackendGlusterFindPoolSources(const char *srcSpec,
         virStoragePoolSourceClear(&list.sources[i]);
     VIR_FREE(list.sources);
 
-    virStoragePoolSourceFree(source);
     return ret;
 }
 
diff --git a/src/storage/storage_backend_iscsi.c b/src/storage/storage_backend_iscsi.c
index 4792bd70b8..483ba15102 100644
--- a/src/storage/storage_backend_iscsi.c
+++ b/src/storage/storage_backend_iscsi.c
@@ -158,7 +158,7 @@ static char *
 virStorageBackendISCSIFindPoolSources(const char *srcSpec,
                                       unsigned int flags)
 {
-    virStoragePoolSourcePtr source = NULL;
+    VIR_AUTOPTR(virStoragePoolSource) source = NULL;
     size_t ntargets = 0;
     char **targets = NULL;
     char *ret = NULL;
@@ -227,7 +227,6 @@ virStorageBackendISCSIFindPoolSources(const char *srcSpec,
         VIR_FREE(targets[i]);
     VIR_FREE(targets);
     VIR_FREE(portal);
-    virStoragePoolSourceFree(source);
     return ret;
 }
 
diff --git a/src/storage/storage_backend_iscsi_direct.c b/src/storage/storage_backend_iscsi_direct.c
index 0babe26550..ddc150f03d 100644
--- a/src/storage/storage_backend_iscsi_direct.c
+++ b/src/storage/storage_backend_iscsi_direct.c
@@ -486,7 +486,7 @@ static char *
 virStorageBackendISCSIDirectFindPoolSources(const char *srcSpec,
                                             unsigned int flags)
 {
-    virStoragePoolSourcePtr source = NULL;
+    VIR_AUTOPTR(virStoragePoolSource) source = NULL;
     size_t ntargets = 0;
     char **targets = NULL;
     char *ret = NULL;
@@ -557,7 +557,6 @@ virStorageBackendISCSIDirectFindPoolSources(const char *srcSpec,
         VIR_FREE(targets[i]);
     VIR_FREE(targets);
     VIR_FREE(portal);
-    virStoragePoolSourceFree(source);
     return ret;
 }
 
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index b06567855e..743d03ae8b 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -4394,7 +4394,7 @@ testConnectFindStoragePoolSources(virConnectPtr conn ATTRIBUTE_UNUSED,
                                   const char *srcSpec,
                                   unsigned int flags)
 {
-    virStoragePoolSourcePtr source = NULL;
+    VIR_AUTOPTR(virStoragePoolSource) source = NULL;
     int pool_type;
     char *ret = NULL;
 
@@ -4404,30 +4404,32 @@ testConnectFindStoragePoolSources(virConnectPtr conn ATTRIBUTE_UNUSED,
     if (!pool_type) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("unknown storage pool type %s"), type);
-        goto cleanup;
+        return NULL;
     }
 
     if (srcSpec) {
         source = virStoragePoolDefParseSourceString(srcSpec, pool_type);
         if (!source)
-            goto cleanup;
+            return NULL;
     }
 
     switch (pool_type) {
 
     case VIR_STORAGE_POOL_LOGICAL:
         ignore_value(VIR_STRDUP(ret, defaultPoolSourcesLogicalXML));
+        return ret;
         break;
 
     case VIR_STORAGE_POOL_NETFS:
         if (!source || !source->hosts[0].name) {
             virReportError(VIR_ERR_INVALID_ARG,
                            "%s", _("hostname must be specified for netfs sources"));
-            goto cleanup;
+            return NULL;
         }
 
         ignore_value(virAsprintf(&ret, defaultPoolSourcesNetFSXML,
                                  source->hosts[0].name));
+        return ret;
         break;
 
     default:
@@ -4435,9 +4437,7 @@ testConnectFindStoragePoolSources(virConnectPtr conn ATTRIBUTE_UNUSED,
                        _("pool type '%s' does not support source discovery"), type);
     }
 
- cleanup:
-    virStoragePoolSourceFree(source);
-    return ret;
+    return NULL;
 }
 
 
-- 
2.20.1

--
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]

  Powered by Linux