From nobody Mon Feb 9 00:20:10 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 154965109420724.852927586919577; Fri, 8 Feb 2019 10:38:14 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 25A7D89AD6; Fri, 8 Feb 2019 18:38:12 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DA90E17BBE; Fri, 8 Feb 2019 18:38:11 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 7D72018033AE; Fri, 8 Feb 2019 18:38:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x18IbdWi007596 for ; Fri, 8 Feb 2019 13:37:39 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3BC2D60C55; Fri, 8 Feb 2019 18:37:39 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id D5A8F60BE0; Fri, 8 Feb 2019 18:37:38 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 8 Feb 2019 13:37:04 -0500 Message-Id: <20190208183726.30903-11-jferlan@redhat.com> In-Reply-To: <20190208183726.30903-1-jferlan@redhat.com> References: <20190208183726.30903-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Erik Skultety Subject: [libvirt] [PATCH v2 10/32] storage: Use VIR_AUTOPTR(virString) X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 08 Feb 2019 18:38:13 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Let's make use of the auto __cleanup capabilities cleaning up any now unnecessary goto paths. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety Reviewed-by: J=C3=A1n Tomko --- 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/stora= ge_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 =3D 0; - char **tmp_targets =3D NULL; + VIR_AUTOPTR(virString) tmp_targets =3D NULL; =20 if (!(addr =3D iscsi_discovery_sync(iscsi))) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -439,7 +439,6 @@ virISCSIDirectUpdateTargets(struct iscsi_context *iscsi, ret =3D 0; cleanup: iscsi_free_discovery_data(iscsi, addr); - virStringListFreeCount(tmp_targets, tmp_ntargets); return ret; } =20 diff --git a/src/storage/storage_backend_sheepdog.c b/src/storage/storage_b= ackend_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(virStoragePoolOb= jPtr pool) { int ret =3D -1; char *output =3D NULL; - char **lines =3D NULL; - char **cells =3D NULL; size_t i; + VIR_AUTOPTR(virString) lines =3D NULL; + VIR_AUTOPTR(virString) cells =3D NULL; =20 virCommandPtr cmd =3D virCommandNewArgList(SHEEPDOGCLI, "vdi", "list",= "-r", NULL); virStorageBackendSheepdogAddHostArg(cmd, pool); @@ -173,8 +173,6 @@ virStorageBackendSheepdogRefreshAllVol(virStoragePoolOb= jPtr pool) =20 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_backen= d_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 poo= l, const char *volume_string) { int ret =3D -1; - char **tokens; size_t count; - char **name_tokens =3D NULL; char *vol_name; bool is_new_vol =3D false; virStorageVolDefPtr volume =3D NULL; virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); + VIR_AUTOPTR(virString) tokens =3D NULL; + VIR_AUTOPTR(virString) name_tokens =3D NULL; =20 if (!(tokens =3D virStringSplitCount(volume_string, "\t", 0, &count))) return -1; @@ -169,8 +169,6 @@ virStorageBackendZFSParseVol(virStoragePoolObjPtr pool, =20 ret =3D 0; cleanup: - virStringListFree(tokens); - virStringListFree(name_tokens); if (is_new_vol) virStorageVolDefFree(volume); return ret; @@ -183,8 +181,8 @@ virStorageBackendZFSFindVols(virStoragePoolObjPtr pool, virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); virCommandPtr cmd =3D NULL; char *volumes_list =3D NULL; - char **lines =3D NULL; size_t i; + VIR_AUTOPTR(virString) lines =3D NULL; =20 /** * $ zfs list -Hp -t volume -o name,volsize -r test @@ -221,7 +219,6 @@ virStorageBackendZFSFindVols(virStoragePoolObjPtr pool, =20 cleanup: virCommandFree(cmd); - virStringListFree(lines); VIR_FREE(volumes_list); =20 return 0; @@ -233,9 +230,9 @@ virStorageBackendZFSRefreshPool(virStoragePoolObjPtr po= ol ATTRIBUTE_UNUSED) virStoragePoolDefPtr def =3D virStoragePoolObjGetDef(pool); virCommandPtr cmd =3D NULL; char *zpool_props =3D NULL; - char **lines =3D NULL; - char **tokens =3D NULL; size_t i; + VIR_AUTOPTR(virString) lines =3D NULL; + VIR_AUTOPTR(virString) tokens =3D NULL; =20 /** * $ zpool get -Hp health,size,free,allocated test @@ -296,8 +293,6 @@ virStorageBackendZFSRefreshPool(virStoragePoolObjPtr po= ol ATTRIBUTE_UNUSED) =20 cleanup: virCommandFree(cmd); - virStringListFree(lines); - virStringListFree(tokens); VIR_FREE(zpool_props); =20 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 =3D NULL; size_t nstrings; unsigned int idx =3D 0; char *suffix; - int ret =3D -1; + VIR_AUTOPTR(virString) strings =3D NULL; =20 *chainIndex =3D 0; =20 @@ -1608,19 +1607,15 @@ virStorageFileParseBackingStoreStr(const char *str, if (nstrings =3D=3D 2) { if (virStrToLong_uip(strings[1], &suffix, 10, &idx) < 0 || STRNEQ(suffix, "]")) - goto cleanup; + return -1; } =20 if (target && VIR_STRDUP(*target, strings[0]) < 0) - goto cleanup; + return -1; =20 *chainIndex =3D idx; - ret =3D 0; - - cleanup: - virStringListFreeCount(strings, nstrings); - return ret; + return 0; } =20 =20 @@ -2677,8 +2672,8 @@ virStorageSourceParseBackingURI(virStorageSourcePtr s= rc, { virURIPtr uri =3D NULL; const char *path =3D NULL; - char **scheme =3D NULL; int ret =3D -1; + VIR_AUTOPTR(virString) scheme =3D NULL; =20 if (!(uri =3D virURIParse(uristr))) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -2772,7 +2767,6 @@ virStorageSourceParseBackingURI(virStorageSourcePtr s= rc, =20 cleanup: virURIFree(uri); - virStringListFree(scheme); return ret; } =20 @@ -2783,7 +2777,7 @@ virStorageSourceRBDAddHost(virStorageSourcePtr src, { char *port; size_t skip; - char **parts; + VIR_AUTOPTR(virString) parts =3D NULL; =20 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 =3D virStringListJoin((const char **)pa= rts, ":"); - virStringListFree(parts); if (!src->hosts[src->nhosts-1].name) goto error; =20 @@ -2940,16 +2933,15 @@ static int virStorageSourceParseNBDColonString(const char *nbdstr, virStorageSourcePtr src) { - char **backing =3D NULL; - int ret =3D -1; + VIR_AUTOPTR(virString) backing =3D NULL; =20 if (!(backing =3D virStringSplit(nbdstr, ":", 0))) - goto cleanup; + return -1; =20 /* we know that backing[0] now equals to "nbd" */ =20 if (VIR_ALLOC_N(src->hosts, 1) < 0) - goto cleanup; + return -1; =20 src->nhosts =3D 1; src->hosts->transport =3D VIR_STORAGE_NET_HOST_TRANS_TCP; @@ -2962,44 +2954,39 @@ virStorageSourceParseNBDColonString(const char *nbd= str, 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 stri= ng %s"), nbdstr); - goto cleanup; + return -1; } =20 if (VIR_STRDUP(src->hosts->socket, backing[2]) < 0) - goto cleanup; + return -1; =20 } else { if (VIR_STRDUP(src->hosts->name, backing[1]) < 0) - goto cleanup; + return -1; =20 if (!backing[2]) { virReportError(VIR_ERR_INTERNAL_ERROR, _("missing port in nbd string '%s'"), nbdstr); - goto cleanup; + return -1; } =20 if (virStringParsePort(backing[2], &src->hosts->port) < 0) - goto cleanup; + return -1; } =20 if (backing[3] && STRPREFIX(backing[3], "exportname=3D")) { if (VIR_STRDUP(src->path, backing[3] + strlen("exportname=3D")) < = 0) - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - virStringListFree(backing); - - return ret; + return 0; } =20 =20 @@ -4250,9 +4237,8 @@ virStorageFileGetRelativeBackingPath(virStorageSource= Ptr top, int virStorageFileCheckCompat(const char *compat) { - char **version; unsigned int result; - int ret =3D -1; + VIR_AUTOPTR(virString) version =3D NULL; =20 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 =3D 0; - - cleanup: - virStringListFree(version); - return ret; + return 0; } =20 =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list