From 71012d7164e869140a653a4ab8b15aaa0f1826e1 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Fri, 18 Jun 2021 14:08:24 +0200 Subject: [PATCH] virStorageBackendISCSIDirectFindPoolSources: Rework cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit virISCSIDirectScanTargets now returns a GStrv, so we can use automatic cleanup for it and get rid of the cleanup section. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- src/storage/storage_backend_iscsi_direct.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/storage/storage_backend_iscsi_direct.c b/src/storage/storage_backend_iscsi_direct.c index 7b2e62f2b8..37052ac4c6 100644 --- a/src/storage/storage_backend_iscsi_direct.c +++ b/src/storage/storage_backend_iscsi_direct.c @@ -485,8 +485,7 @@ virStorageBackendISCSIDirectFindPoolSources(const char *srcSpec, unsigned int flags) { size_t ntargets = 0; - char **targets = NULL; - char *ret = NULL; + g_auto(GStrv) targets = NULL; size_t i; g_autoptr(virStoragePoolSourceList) list = g_new0(virStoragePoolSourceList, 1); g_autofree char *portal = NULL; @@ -508,20 +507,20 @@ virStorageBackendISCSIDirectFindPoolSources(const char *srcSpec, if (source->nhost != 1) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Expected exactly 1 host for the storage pool")); - goto cleanup; + return NULL; } if (!source->initiator.iqn) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("missing initiator IQN")); - goto cleanup; + return NULL; } if (!(portal = virStorageBackendISCSIDirectPortal(source))) - goto cleanup; + return NULL; if (virISCSIDirectScanTargets(source->initiator.iqn, portal, &ntargets, &targets) < 0) - goto cleanup; + return NULL; list->sources = g_new0(virStoragePoolSource, ntargets); @@ -541,14 +540,7 @@ virStorageBackendISCSIDirectFindPoolSources(const char *srcSpec, list->nsources++; } - if (!(ret = virStoragePoolSourceListFormat(list))) - goto cleanup; - - cleanup: - for (i = 0; i < ntargets; i++) - VIR_FREE(targets[i]); - VIR_FREE(targets); - return ret; + return virStoragePoolSourceListFormat(list); } static struct iscsi_context *