Let's make use of the auto __cleanup capabilities cleaning up any
now unnecessary goto paths.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
Reviewed-by: Erik Skultety <eskultet(a)redhat.com>
---
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 ead24816bc..9563d2bc6b 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;
+ virStoragePoolSourcePtr ret = NULL;
+ VIR_AUTOPTR(virStoragePoolSource) def = 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..420601a303 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -145,11 +145,11 @@ virStorageBackendFileSystemNetFindPoolSources(const char *srcSpec,
.sources = NULL
}
};
- virStoragePoolSourcePtr source = NULL;
char *ret = NULL;
size_t i;
int retNFS = -1;
int retGluster = 0;
+ VIR_AUTOPTR(virStoragePoolSource) source = NULL;
virCheckFlags(0, NULL);
@@ -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..559189fd1d 100644
--- a/src/storage/storage_backend_gluster.c
+++ b/src/storage/storage_backend_gluster.c
@@ -489,10 +489,10 @@ virStorageBackendGlusterFindPoolSources(const char *srcSpec,
.nsources = 0,
.sources = NULL
};
- virStoragePoolSourcePtr source = NULL;
char *ret = NULL;
int rc;
size_t i;
+ VIR_AUTOPTR(virStoragePoolSource) source = NULL;
virCheckFlags(0, NULL);
@@ -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..dc1a983b58 100644
--- a/src/storage/storage_backend_iscsi.c
+++ b/src/storage/storage_backend_iscsi.c
@@ -158,7 +158,6 @@ static char *
virStorageBackendISCSIFindPoolSources(const char *srcSpec,
unsigned int flags)
{
- virStoragePoolSourcePtr source = NULL;
size_t ntargets = 0;
char **targets = NULL;
char *ret = NULL;
@@ -169,6 +168,7 @@ virStorageBackendISCSIFindPoolSources(const char *srcSpec,
.sources = NULL
};
char *portal = NULL;
+ VIR_AUTOPTR(virStoragePoolSource) source = NULL;
virCheckFlags(0, 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..8d12c1a274 100644
--- a/src/storage/storage_backend_iscsi_direct.c
+++ b/src/storage/storage_backend_iscsi_direct.c
@@ -486,7 +486,6 @@ static char *
virStorageBackendISCSIDirectFindPoolSources(const char *srcSpec,
unsigned int flags)
{
- virStoragePoolSourcePtr source = NULL;
size_t ntargets = 0;
char **targets = NULL;
char *ret = NULL;
@@ -497,6 +496,7 @@ virStorageBackendISCSIDirectFindPoolSources(const char *srcSpec,
.sources = NULL
};
char *portal = NULL;
+ VIR_AUTOPTR(virStoragePoolSource) source = NULL;
virCheckFlags(0, 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..de221b4190 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -4394,9 +4394,9 @@ testConnectFindStoragePoolSources(virConnectPtr conn
ATTRIBUTE_UNUSED,
const char *srcSpec,
unsigned int flags)
{
- virStoragePoolSourcePtr source = NULL;
int pool_type;
char *ret = NULL;
+ VIR_AUTOPTR(virStoragePoolSource) source = NULL;
virCheckFlags(0, 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