From nobody Sat May 4 07:40:38 2024 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 15541040125081017.1403208003395; Mon, 1 Apr 2019 00:33:32 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2D737A3D22; Mon, 1 Apr 2019 07:33:31 +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 055415D706; Mon, 1 Apr 2019 07:33:31 +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 A7197180338C; Mon, 1 Apr 2019 07:33:30 +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 x317XJLu013799 for ; Mon, 1 Apr 2019 03:33:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id AA31C60BFC; Mon, 1 Apr 2019 07:33:19 +0000 (UTC) Received: from lpt.redhat.com (ovpn-204-90.brq.redhat.com [10.40.204.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id 08A7E60BE6 for ; Mon, 1 Apr 2019 07:33:18 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Mon, 1 Apr 2019 09:33:18 +0200 Message-Id: <43ae298aa3c0e6d119b56dec984f0fd05e622a95.1554103986.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 01/14] virsh: fix indentation of info_managed_save_edit 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-Type: text/plain; charset="utf-8" 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 01 Apr 2019 07:33:31 +0000 (UTC) Use four spaces instead of three. Signed-off-by: J=C3=A1n Tomko --- tools/virsh-domain.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index afcd0a5f8d..e8d5404acf 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -4805,13 +4805,13 @@ cmdManagedSaveRemove(vshControl *ctl, const vshCmd = *cmd) * "managedsave-edit" command */ static const vshCmdInfo info_managed_save_edit[] =3D { - {.name =3D "help", - .data =3D N_("edit XML for a domain's managed save state file") - }, - {.name =3D "desc", - .data =3D N_("Edit the domain XML associated with the managed save sta= te file") - }, - {.name =3D NULL} + {.name =3D "help", + .data =3D N_("edit XML for a domain's managed save state file") + }, + {.name =3D "desc", + .data =3D N_("Edit the domain XML associated with the managed save st= ate file") + }, + {.name =3D NULL} }; =20 static const vshCmdOptDef opts_managed_save_edit[] =3D { --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 07:40:38 2024 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 1554104016134796.7480145891714; Mon, 1 Apr 2019 00:33:36 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B0A5230842D1; Mon, 1 Apr 2019 07:33:34 +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 89D512E041; Mon, 1 Apr 2019 07:33:34 +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 4E588181A000; Mon, 1 Apr 2019 07:33:34 +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 x317XKbD013809 for ; Mon, 1 Apr 2019 03:33:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id AFC9A1908F; Mon, 1 Apr 2019 07:33:20 +0000 (UTC) Received: from lpt.redhat.com (ovpn-204-90.brq.redhat.com [10.40.204.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id 18F0960BFC for ; Mon, 1 Apr 2019 07:33:19 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Mon, 1 Apr 2019 09:33:19 +0200 Message-Id: <3335147ca4f79bb6214d4edcad965b4bdd2f8fb6.1554103986.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 02/14] virsh-completer: fix typo 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-Type: text/plain; charset="utf-8" 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Mon, 01 Apr 2019 07:33:35 +0000 (UTC) Use the posessive determiner instead of a contracted auxiliary. Signed-off-by: J=C3=A1n Tomko --- tools/virsh-completer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index e9ef9b99f9..760ed2088f 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -58,7 +58,7 @@ * * The @flags contains a .completer_flags value defined for each * use or 0 if no .completer_flags were specified. If a completer - * is generic enough @flags can be used to alter it's behaviour. + * is generic enough @flags can be used to alter its behaviour. * For instance, a completer to fetch names of domains can use * @flags to return names of only domains in a particular state * that the command accepts. --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 07:40:38 2024 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 1554104005660835.7256828228197; Mon, 1 Apr 2019 00:33:25 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 268DC81F11; Mon, 1 Apr 2019 07:33:24 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F05555D70E; Mon, 1 Apr 2019 07:33:23 +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 5F0473FB13; Mon, 1 Apr 2019 07:33:23 +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 x317XLsk013819 for ; Mon, 1 Apr 2019 03:33:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id B65A01908F; Mon, 1 Apr 2019 07:33:21 +0000 (UTC) Received: from lpt.redhat.com (ovpn-204-90.brq.redhat.com [10.40.204.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1E33B60BFC for ; Mon, 1 Apr 2019 07:33:20 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Mon, 1 Apr 2019 09:33:20 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 03/14] virsh-completer: reword documentation 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-Type: text/plain; charset="utf-8" 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 01 Apr 2019 07:33:24 +0000 (UTC) Use less strict wording that does not threaten the reader with circumstances. Signed-off-by: J=C3=A1n Tomko --- tools/virsh-completer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 760ed2088f..464a2751fa 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -63,9 +63,9 @@ * @flags to return names of only domains in a particular state * that the command accepts. * - * Under no circumstances should a completer output anything. - * Neither to stdout nor to stderr. This would harm the user - * experience. + * A completer may not harm the user experience by outputting + * anything or, through inaction, allow the user experience + * to be harmed by output. */ =20 =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 07:40:38 2024 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 1554104019526134.46194818895276; Mon, 1 Apr 2019 00:33:39 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7C9AC3087924; Mon, 1 Apr 2019 07:33:38 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 51DC15DC1E; Mon, 1 Apr 2019 07:33:38 +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 05F743FAF6; Mon, 1 Apr 2019 07:33:38 +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 x317XMLO013824 for ; Mon, 1 Apr 2019 03:33:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id EDF2260BE6; Mon, 1 Apr 2019 07:33:22 +0000 (UTC) Received: from lpt.redhat.com (ovpn-204-90.brq.redhat.com [10.40.204.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2371360BFC for ; Mon, 1 Apr 2019 07:33:21 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Mon, 1 Apr 2019 09:33:21 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 04/14] virsh-completer: switch to using tmp instead of ret 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-Type: text/plain; charset="utf-8" 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Mon, 01 Apr 2019 07:33:39 +0000 (UTC) Construct the potential return value in an array called 'tmp' and only assign it to 'ret' if we're going to return it. This will allow us to unify the error and success paths. Signed-off-by: J=C3=A1n Tomko --- tools/virsh-completer.c | 195 +++++++++++++++++++++++++--------------- 1 file changed, 125 insertions(+), 70 deletions(-) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 464a2751fa..0750945b84 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -79,6 +79,7 @@ virshDomainNameCompleter(vshControl *ctl, int ndomains =3D 0; size_t i =3D 0; char **ret =3D NULL; + char **tmp =3D NULL; =20 virCheckFlags(VIR_CONNECT_LIST_DOMAINS_ACTIVE | VIR_CONNECT_LIST_DOMAINS_INACTIVE | @@ -95,19 +96,21 @@ virshDomainNameCompleter(vshControl *ctl, if ((ndomains =3D virConnectListAllDomains(priv->conn, &domains, flags= )) < 0) return NULL; =20 - if (VIR_ALLOC_N(ret, ndomains + 1) < 0) + if (VIR_ALLOC_N(tmp, ndomains + 1) < 0) goto error; =20 for (i =3D 0; i < ndomains; i++) { const char *name =3D virDomainGetName(domains[i]); =20 - if (VIR_STRDUP(ret[i], name) < 0) + if (VIR_STRDUP(tmp[i], name) < 0) goto error; =20 virshDomainFree(domains[i]); } VIR_FREE(domains); =20 + VIR_STEAL_PTR(ret, tmp); + return ret; =20 error: @@ -115,8 +118,8 @@ virshDomainNameCompleter(vshControl *ctl, virshDomainFree(domains[i]); VIR_FREE(domains); for (i =3D 0; i < ndomains; i++) - VIR_FREE(ret[i]); - VIR_FREE(ret); + VIR_FREE(tmp[i]); + VIR_FREE(tmp); return NULL; } =20 @@ -232,6 +235,7 @@ virshStoragePoolNameCompleter(vshControl *ctl, int npools =3D 0; size_t i =3D 0; char **ret =3D NULL; + char **tmp =3D NULL; =20 virCheckFlags(VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE | VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE | @@ -244,19 +248,21 @@ virshStoragePoolNameCompleter(vshControl *ctl, if ((npools =3D virConnectListAllStoragePools(priv->conn, &pools, flag= s)) < 0) return NULL; =20 - if (VIR_ALLOC_N(ret, npools + 1) < 0) + if (VIR_ALLOC_N(tmp, npools + 1) < 0) goto error; =20 for (i =3D 0; i < npools; i++) { const char *name =3D virStoragePoolGetName(pools[i]); =20 - if (VIR_STRDUP(ret[i], name) < 0) + if (VIR_STRDUP(tmp[i], name) < 0) goto error; =20 virStoragePoolFree(pools[i]); } VIR_FREE(pools); =20 + VIR_STEAL_PTR(ret, tmp); + return ret; =20 error: @@ -264,8 +270,8 @@ virshStoragePoolNameCompleter(vshControl *ctl, virStoragePoolFree(pools[i]); VIR_FREE(pools); for (i =3D 0; i < npools; i++) - VIR_FREE(ret[i]); - VIR_FREE(ret); + VIR_FREE(tmp[i]); + VIR_FREE(tmp); return NULL; } =20 @@ -282,6 +288,7 @@ virshStorageVolNameCompleter(vshControl *ctl, int nvols =3D 0; size_t i =3D 0; char **ret =3D NULL; + char **tmp =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -295,20 +302,23 @@ virshStorageVolNameCompleter(vshControl *ctl, goto error; nvols =3D rc; =20 - if (VIR_ALLOC_N(ret, nvols + 1) < 0) + if (VIR_ALLOC_N(tmp, nvols + 1) < 0) goto error; =20 for (i =3D 0; i < nvols; i++) { const char *name =3D virStorageVolGetName(vols[i]); =20 - if (VIR_STRDUP(ret[i], name) < 0) + if (VIR_STRDUP(tmp[i], name) < 0) goto error; =20 virStorageVolFree(vols[i]); } + VIR_FREE(vols); virStoragePoolFree(pool); =20 + VIR_STEAL_PTR(ret, tmp); + return ret; =20 error: @@ -316,8 +326,8 @@ virshStorageVolNameCompleter(vshControl *ctl, virStorageVolFree(vols[i]); VIR_FREE(vols); for (i =3D 0; i < nvols; i++) - VIR_FREE(ret[i]); - VIR_FREE(ret); + VIR_FREE(tmp[i]); + VIR_FREE(tmp); virStoragePoolFree(pool); return NULL; } @@ -333,6 +343,7 @@ virshInterfaceNameCompleter(vshControl *ctl, int nifaces =3D 0; size_t i =3D 0; char **ret =3D NULL; + char **tmp =3D NULL; =20 virCheckFlags(VIR_CONNECT_LIST_INTERFACES_ACTIVE | VIR_CONNECT_LIST_INTERFACES_INACTIVE, @@ -344,19 +355,21 @@ virshInterfaceNameCompleter(vshControl *ctl, if ((nifaces =3D virConnectListAllInterfaces(priv->conn, &ifaces, flag= s)) < 0) return NULL; =20 - if (VIR_ALLOC_N(ret, nifaces + 1) < 0) + if (VIR_ALLOC_N(tmp, nifaces + 1) < 0) goto error; =20 for (i =3D 0; i < nifaces; i++) { const char *name =3D virInterfaceGetName(ifaces[i]); =20 - if (VIR_STRDUP(ret[i], name) < 0) + if (VIR_STRDUP(tmp[i], name) < 0) goto error; =20 virInterfaceFree(ifaces[i]); } VIR_FREE(ifaces); =20 + VIR_STEAL_PTR(ret, tmp); + return ret; =20 error: @@ -364,8 +377,8 @@ virshInterfaceNameCompleter(vshControl *ctl, virInterfaceFree(ifaces[i]); VIR_FREE(ifaces); for (i =3D 0; i < nifaces; i++) - VIR_FREE(ret[i]); - VIR_FREE(ret); + VIR_FREE(tmp[i]); + VIR_FREE(tmp); return NULL; } =20 @@ -380,6 +393,7 @@ virshNetworkNameCompleter(vshControl *ctl, int nnets =3D 0; size_t i =3D 0; char **ret =3D NULL; + char **tmp =3D NULL; =20 virCheckFlags(VIR_CONNECT_LIST_NETWORKS_INACTIVE | VIR_CONNECT_LIST_NETWORKS_ACTIVE | @@ -392,19 +406,21 @@ virshNetworkNameCompleter(vshControl *ctl, if ((nnets =3D virConnectListAllNetworks(priv->conn, &nets, flags)) < = 0) return NULL; =20 - if (VIR_ALLOC_N(ret, nnets + 1) < 0) + if (VIR_ALLOC_N(tmp, nnets + 1) < 0) goto error; =20 for (i =3D 0; i < nnets; i++) { const char *name =3D virNetworkGetName(nets[i]); =20 - if (VIR_STRDUP(ret[i], name) < 0) + if (VIR_STRDUP(tmp[i], name) < 0) goto error; =20 virNetworkFree(nets[i]); } VIR_FREE(nets); =20 + VIR_STEAL_PTR(ret, tmp); + return ret; =20 error: @@ -412,8 +428,8 @@ virshNetworkNameCompleter(vshControl *ctl, virNetworkFree(nets[i]); VIR_FREE(nets); for (i =3D 0; i < nnets; i++) - VIR_FREE(ret[i]); - VIR_FREE(ret); + VIR_FREE(tmp[i]); + VIR_FREE(tmp); return NULL; } =20 @@ -425,21 +441,24 @@ virshNetworkEventNameCompleter(vshControl *ctl ATTRIB= UTE_UNUSED, { size_t i =3D 0; char **ret =3D NULL; + char **tmp =3D NULL; =20 virCheckFlags(0, NULL); =20 - if (VIR_ALLOC_N(ret, VIR_NETWORK_EVENT_ID_LAST + 1) < 0) + if (VIR_ALLOC_N(tmp, VIR_NETWORK_EVENT_ID_LAST + 1) < 0) goto error; =20 for (i =3D 0; i < VIR_NETWORK_EVENT_ID_LAST; i++) { - if (VIR_STRDUP(ret[i], virshNetworkEventCallbacks[i].name) < 0) + if (VIR_STRDUP(tmp[i], virshNetworkEventCallbacks[i].name) < 0) goto error; } =20 + VIR_STEAL_PTR(ret, tmp); + return ret; =20 error: - virStringListFree(ret); + virStringListFree(tmp); return NULL; } =20 @@ -454,6 +473,7 @@ virshNodeDeviceNameCompleter(vshControl *ctl, int ndevs =3D 0; size_t i =3D 0; char **ret =3D NULL; + char **tmp =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -463,19 +483,21 @@ virshNodeDeviceNameCompleter(vshControl *ctl, if ((ndevs =3D virConnectListAllNodeDevices(priv->conn, &devs, flags))= < 0) return NULL; =20 - if (VIR_ALLOC_N(ret, ndevs + 1) < 0) + if (VIR_ALLOC_N(tmp, ndevs + 1) < 0) goto error; =20 for (i =3D 0; i < ndevs; i++) { const char *name =3D virNodeDeviceGetName(devs[i]); =20 - if (VIR_STRDUP(ret[i], name) < 0) + if (VIR_STRDUP(tmp[i], name) < 0) goto error; =20 virNodeDeviceFree(devs[i]); } VIR_FREE(devs); =20 + VIR_STEAL_PTR(ret, tmp); + return ret; =20 error: @@ -483,8 +505,8 @@ virshNodeDeviceNameCompleter(vshControl *ctl, virNodeDeviceFree(devs[i]); VIR_FREE(devs); for (i =3D 0; i < ndevs; i++) - VIR_FREE(ret[i]); - VIR_FREE(ret); + VIR_FREE(tmp[i]); + VIR_FREE(tmp); return NULL; } =20 @@ -499,6 +521,7 @@ virshNWFilterNameCompleter(vshControl *ctl, int nnwfilters =3D 0; size_t i =3D 0; char **ret =3D NULL; + char **tmp =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -508,19 +531,21 @@ virshNWFilterNameCompleter(vshControl *ctl, if ((nnwfilters =3D virConnectListAllNWFilters(priv->conn, &nwfilters,= flags)) < 0) return NULL; =20 - if (VIR_ALLOC_N(ret, nnwfilters + 1) < 0) + if (VIR_ALLOC_N(tmp, nnwfilters + 1) < 0) goto error; =20 for (i =3D 0; i < nnwfilters; i++) { const char *name =3D virNWFilterGetName(nwfilters[i]); =20 - if (VIR_STRDUP(ret[i], name) < 0) + if (VIR_STRDUP(tmp[i], name) < 0) goto error; =20 virNWFilterFree(nwfilters[i]); } VIR_FREE(nwfilters); =20 + VIR_STEAL_PTR(ret, tmp); + return ret; =20 error: @@ -528,8 +553,8 @@ virshNWFilterNameCompleter(vshControl *ctl, virNWFilterFree(nwfilters[i]); VIR_FREE(nwfilters); for (i =3D 0; i < nnwfilters; i++) - VIR_FREE(ret[i]); - VIR_FREE(ret); + VIR_FREE(tmp[i]); + VIR_FREE(tmp); return NULL; } =20 @@ -544,6 +569,7 @@ virshNWFilterBindingNameCompleter(vshControl *ctl, int nbindings =3D 0; size_t i =3D 0; char **ret =3D NULL; + char **tmp =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -553,19 +579,21 @@ virshNWFilterBindingNameCompleter(vshControl *ctl, if ((nbindings =3D virConnectListAllNWFilterBindings(priv->conn, &bind= ings, flags)) < 0) return NULL; =20 - if (VIR_ALLOC_N(ret, nbindings + 1) < 0) + if (VIR_ALLOC_N(tmp, nbindings + 1) < 0) goto error; =20 for (i =3D 0; i < nbindings; i++) { const char *name =3D virNWFilterBindingGetPortDev(bindings[i]); =20 - if (VIR_STRDUP(ret[i], name) < 0) + if (VIR_STRDUP(tmp[i], name) < 0) goto error; =20 virNWFilterBindingFree(bindings[i]); } VIR_FREE(bindings); =20 + VIR_STEAL_PTR(ret, tmp); + return ret; =20 error: @@ -573,8 +601,8 @@ virshNWFilterBindingNameCompleter(vshControl *ctl, virNWFilterBindingFree(bindings[i]); VIR_FREE(bindings); for (i =3D 0; i < nbindings; i++) - VIR_FREE(ret[i]); - VIR_FREE(ret); + VIR_FREE(tmp[i]); + VIR_FREE(tmp); return NULL; } =20 @@ -589,6 +617,7 @@ virshSecretUUIDCompleter(vshControl *ctl, int nsecrets =3D 0; size_t i =3D 0; char **ret =3D NULL; + char **tmp =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -598,20 +627,22 @@ virshSecretUUIDCompleter(vshControl *ctl, if ((nsecrets =3D virConnectListAllSecrets(priv->conn, &secrets, flags= )) < 0) return NULL; =20 - if (VIR_ALLOC_N(ret, nsecrets + 1) < 0) + if (VIR_ALLOC_N(tmp, nsecrets + 1) < 0) goto error; =20 for (i =3D 0; i < nsecrets; i++) { char uuid[VIR_UUID_STRING_BUFLEN]; =20 if (virSecretGetUUIDString(secrets[i], uuid) < 0 || - VIR_STRDUP(ret[i], uuid) < 0) + VIR_STRDUP(tmp[i], uuid) < 0) goto error; =20 virSecretFree(secrets[i]); } VIR_FREE(secrets); =20 + VIR_STEAL_PTR(ret, tmp); + return ret; =20 error: @@ -619,8 +650,8 @@ virshSecretUUIDCompleter(vshControl *ctl, virSecretFree(secrets[i]); VIR_FREE(secrets); for (i =3D 0; i < nsecrets; i++) - VIR_FREE(ret[i]); - VIR_FREE(ret); + VIR_FREE(tmp[i]); + VIR_FREE(tmp); return NULL; } =20 @@ -637,6 +668,7 @@ virshSnapshotNameCompleter(vshControl *ctl, int nsnapshots =3D 0; size_t i =3D 0; char **ret =3D NULL; + char **tmp =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -650,13 +682,13 @@ virshSnapshotNameCompleter(vshControl *ctl, goto error; nsnapshots =3D rc; =20 - if (VIR_ALLOC_N(ret, nsnapshots + 1) < 0) + if (VIR_ALLOC_N(tmp, nsnapshots + 1) < 0) goto error; =20 for (i =3D 0; i < nsnapshots; i++) { const char *name =3D virDomainSnapshotGetName(snapshots[i]); =20 - if (VIR_STRDUP(ret[i], name) < 0) + if (VIR_STRDUP(tmp[i], name) < 0) goto error; =20 virshDomainSnapshotFree(snapshots[i]); @@ -664,6 +696,8 @@ virshSnapshotNameCompleter(vshControl *ctl, VIR_FREE(snapshots); virshDomainFree(dom); =20 + VIR_STEAL_PTR(ret, tmp); + return ret; =20 error: @@ -671,8 +705,8 @@ virshSnapshotNameCompleter(vshControl *ctl, virshDomainSnapshotFree(snapshots[i]); VIR_FREE(snapshots); for (i =3D 0; i < nsnapshots; i++) - VIR_FREE(ret[i]); - VIR_FREE(ret); + VIR_FREE(tmp[i]); + VIR_FREE(tmp); virshDomainFree(dom); return NULL; } @@ -698,6 +732,7 @@ virshAllocpagesPagesizeCompleter(vshControl *ctl, char *cap_xml =3D NULL; char **ret =3D NULL; char *unit =3D NULL; + char **tmp =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -724,7 +759,7 @@ virshAllocpagesPagesizeCompleter(vshControl *ctl, if (npages <=3D 0) goto error; =20 - if (VIR_ALLOC_N(ret, npages + 1) < 0) + if (VIR_ALLOC_N(tmp, npages + 1) < 0) goto error; =20 for (i =3D 0; i < npages; i++) { @@ -737,10 +772,12 @@ virshAllocpagesPagesizeCompleter(vshControl *ctl, if (virScaleInteger(&byteval, unit, 1024, UINT_MAX) < 0) goto error; size =3D vshPrettyCapacity(byteval, &suffix); - if (virAsprintf(&ret[i], "%.0f%s", size, suffix) < 0) + if (virAsprintf(&tmp[i], "%.0f%s", size, suffix) < 0) goto error; } =20 + VIR_STEAL_PTR(ret, tmp); + cleanup: xmlXPathFreeContext(ctxt); VIR_FREE(pages); @@ -753,11 +790,11 @@ virshAllocpagesPagesizeCompleter(vshControl *ctl, return ret; =20 error: - if (ret) { + if (tmp) { for (i =3D 0; i < npages; i++) - VIR_FREE(ret[i]); + VIR_FREE(tmp[i]); } - VIR_FREE(ret); + VIR_FREE(tmp); goto cleanup; } =20 @@ -769,21 +806,24 @@ virshSecretEventNameCompleter(vshControl *ctl ATTRIBU= TE_UNUSED, { size_t i; char **ret =3D NULL; + char **tmp =3D NULL; =20 virCheckFlags(0, NULL); =20 - if (VIR_ALLOC_N(ret, VIR_SECRET_EVENT_ID_LAST + 1) < 0) + if (VIR_ALLOC_N(tmp, VIR_SECRET_EVENT_ID_LAST + 1) < 0) goto error; =20 for (i =3D 0; i < VIR_SECRET_EVENT_ID_LAST; i++) { - if (VIR_STRDUP(ret[i], virshSecretEventCallbacks[i].name) < 0) + if (VIR_STRDUP(tmp[i], virshSecretEventCallbacks[i].name) < 0) goto error; } =20 + VIR_STEAL_PTR(ret, tmp); + return ret; =20 error: - virStringListFree(ret); + virStringListFree(tmp); return NULL; } =20 @@ -795,21 +835,24 @@ virshDomainEventNameCompleter(vshControl *ctl ATTRIBU= TE_UNUSED, { size_t i =3D 0; char **ret =3D NULL; + char **tmp =3D NULL; =20 virCheckFlags(0, NULL); =20 - if (VIR_ALLOC_N(ret, VIR_DOMAIN_EVENT_ID_LAST + 1) < 0) + if (VIR_ALLOC_N(tmp, VIR_DOMAIN_EVENT_ID_LAST + 1) < 0) goto error; =20 for (i =3D 0; i < VIR_DOMAIN_EVENT_ID_LAST; i++) { - if (VIR_STRDUP(ret[i], virshDomainEventCallbacks[i].name) < 0) + if (VIR_STRDUP(tmp[i], virshDomainEventCallbacks[i].name) < 0) goto error; } =20 + VIR_STEAL_PTR(ret, tmp); + return ret; =20 error: - virStringListFree(ret); + virStringListFree(tmp); return NULL; } =20 @@ -821,21 +864,24 @@ virshPoolEventNameCompleter(vshControl *ctl ATTRIBUTE= _UNUSED, { size_t i =3D 0; char **ret =3D NULL; + char **tmp =3D NULL; =20 virCheckFlags(0, NULL); =20 - if (VIR_ALLOC_N(ret, VIR_STORAGE_POOL_EVENT_ID_LAST + 1) < 0) + if (VIR_ALLOC_N(tmp, VIR_STORAGE_POOL_EVENT_ID_LAST + 1) < 0) goto error; =20 for (i =3D 0; i < VIR_STORAGE_POOL_EVENT_ID_LAST; i++) { - if (VIR_STRDUP(ret[i], virshPoolEventCallbacks[i].name) < 0) + if (VIR_STRDUP(tmp[i], virshPoolEventCallbacks[i].name) < 0) goto error; } =20 + VIR_STEAL_PTR(ret, tmp); + return ret; =20 error: - virStringListFree(ret); + virStringListFree(tmp); return NULL; } =20 @@ -856,6 +902,7 @@ virshDomainInterfaceStateCompleter(vshControl *ctl, xmlNodePtr *interfaces =3D NULL; char *xpath =3D NULL; char *state =3D NULL; + char **tmp =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -885,18 +932,20 @@ virshDomainInterfaceStateCompleter(vshControl *ctl, =20 ctxt->node =3D interfaces[0]; =20 - if (VIR_ALLOC_N(ret, 2) < 0) + if (VIR_ALLOC_N(tmp, 2) < 0) goto error; =20 if ((state =3D virXPathString("string(./link/@state)", ctxt)) && STREQ(state, "down")) { - if (VIR_STRDUP(ret[0], "up") < 0) + if (VIR_STRDUP(tmp[0], "up") < 0) goto error; } else { - if (VIR_STRDUP(ret[0], "down") < 0) + if (VIR_STRDUP(tmp[0], "down") < 0) goto error; } =20 + VIR_STEAL_PTR(ret, tmp); + cleanup: VIR_FREE(state); VIR_FREE(xpath); @@ -906,8 +955,8 @@ virshDomainInterfaceStateCompleter(vshControl *ctl, return ret; =20 error: - virStringListFree(ret); - ret =3D NULL; + virStringListFree(tmp); + tmp =3D NULL; goto cleanup; } =20 @@ -919,21 +968,24 @@ virshNodedevEventNameCompleter(vshControl *ctl ATTRIB= UTE_UNUSED, { size_t i =3D 0; char **ret =3D NULL; + char **tmp =3D NULL; =20 virCheckFlags(0, NULL); =20 - if (VIR_ALLOC_N(ret, VIR_NODE_DEVICE_EVENT_ID_LAST + 1) < 0) + if (VIR_ALLOC_N(tmp, VIR_NODE_DEVICE_EVENT_ID_LAST + 1) < 0) goto error; =20 for (i =3D 0; i < VIR_NODE_DEVICE_EVENT_ID_LAST; i++) { - if (VIR_STRDUP(ret[i], virshNodedevEventCallbacks[i].name) < 0) + if (VIR_STRDUP(tmp[i], virshNodedevEventCallbacks[i].name) < 0) goto error; } =20 + VIR_STEAL_PTR(ret, tmp); + return ret; =20 error: - virStringListFree(ret); + virStringListFree(tmp); return NULL; } =20 @@ -951,6 +1003,7 @@ virshCellnoCompleter(vshControl *ctl, size_t i =3D 0; char *cap_xml =3D NULL; char **ret =3D NULL; + char **tmp =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -967,14 +1020,16 @@ virshCellnoCompleter(vshControl *ctl, if (ncells <=3D 0) goto error; =20 - if (VIR_ALLOC_N(ret, ncells + 1)) + if (VIR_ALLOC_N(tmp, ncells + 1)) goto error; =20 for (i =3D 0; i < ncells; i++) { - if (!(ret[i] =3D virXMLPropString(cells[i], "id"))) + if (!(tmp[i] =3D virXMLPropString(cells[i], "id"))) goto error; } =20 + VIR_STEAL_PTR(ret, tmp); + cleanup: xmlXPathFreeContext(ctxt); VIR_FREE(cells); @@ -984,11 +1039,11 @@ virshCellnoCompleter(vshControl *ctl, return ret; =20 error: - if (ret) { + if (tmp) { for (i =3D 0; i < ncells; i++) - VIR_FREE(ret[i]); + VIR_FREE(tmp[i]); } - VIR_FREE(ret); + VIR_FREE(tmp); goto cleanup; } =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 07:40:38 2024 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 1554104024034626.5974996796464; Mon, 1 Apr 2019 00:33:44 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C1A7EF74B5; Mon, 1 Apr 2019 07:33:42 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 946AF26DF5; Mon, 1 Apr 2019 07:33:42 +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 4EFDC3FA4C; Mon, 1 Apr 2019 07:33:42 +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 x317XOgK013839 for ; Mon, 1 Apr 2019 03:33:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id F3A8160BFC; Mon, 1 Apr 2019 07:33:23 +0000 (UTC) Received: from lpt.redhat.com (ovpn-204-90.brq.redhat.com [10.40.204.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5BC5760BE6 for ; Mon, 1 Apr 2019 07:33:23 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Mon, 1 Apr 2019 09:33:22 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 05/14] virsh-completer: add a cleanup label everywhere 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 01 Apr 2019 07:33:43 +0000 (UTC) Unify the cleanup paths for error and success. Now that 'ret' is only set (from tmp) on the success path, it is safe to jump right before 'return ret' after processing the error block. Signed-off-by: J=C3=A1n Tomko --- tools/virsh-completer.c | 45 +++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 0750945b84..46fedc06d9 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -111,6 +111,7 @@ virshDomainNameCompleter(vshControl *ctl, =20 VIR_STEAL_PTR(ret, tmp); =20 + cleanup: return ret; =20 error: @@ -120,7 +121,7 @@ virshDomainNameCompleter(vshControl *ctl, for (i =3D 0; i < ndomains; i++) VIR_FREE(tmp[i]); VIR_FREE(tmp); - return NULL; + goto cleanup; } =20 =20 @@ -263,6 +264,7 @@ virshStoragePoolNameCompleter(vshControl *ctl, =20 VIR_STEAL_PTR(ret, tmp); =20 + cleanup: return ret; =20 error: @@ -272,7 +274,7 @@ virshStoragePoolNameCompleter(vshControl *ctl, for (i =3D 0; i < npools; i++) VIR_FREE(tmp[i]); VIR_FREE(tmp); - return NULL; + goto cleanup; } =20 =20 @@ -319,6 +321,7 @@ virshStorageVolNameCompleter(vshControl *ctl, =20 VIR_STEAL_PTR(ret, tmp); =20 + cleanup: return ret; =20 error: @@ -329,7 +332,7 @@ virshStorageVolNameCompleter(vshControl *ctl, VIR_FREE(tmp[i]); VIR_FREE(tmp); virStoragePoolFree(pool); - return NULL; + goto cleanup; } =20 =20 @@ -370,6 +373,7 @@ virshInterfaceNameCompleter(vshControl *ctl, =20 VIR_STEAL_PTR(ret, tmp); =20 + cleanup: return ret; =20 error: @@ -379,7 +383,7 @@ virshInterfaceNameCompleter(vshControl *ctl, for (i =3D 0; i < nifaces; i++) VIR_FREE(tmp[i]); VIR_FREE(tmp); - return NULL; + goto cleanup; } =20 =20 @@ -421,6 +425,7 @@ virshNetworkNameCompleter(vshControl *ctl, =20 VIR_STEAL_PTR(ret, tmp); =20 + cleanup: return ret; =20 error: @@ -430,7 +435,7 @@ virshNetworkNameCompleter(vshControl *ctl, for (i =3D 0; i < nnets; i++) VIR_FREE(tmp[i]); VIR_FREE(tmp); - return NULL; + goto cleanup; } =20 =20 @@ -455,11 +460,12 @@ virshNetworkEventNameCompleter(vshControl *ctl ATTRIB= UTE_UNUSED, =20 VIR_STEAL_PTR(ret, tmp); =20 + cleanup: return ret; =20 error: virStringListFree(tmp); - return NULL; + goto cleanup; } =20 =20 @@ -498,6 +504,7 @@ virshNodeDeviceNameCompleter(vshControl *ctl, =20 VIR_STEAL_PTR(ret, tmp); =20 + cleanup: return ret; =20 error: @@ -507,7 +514,7 @@ virshNodeDeviceNameCompleter(vshControl *ctl, for (i =3D 0; i < ndevs; i++) VIR_FREE(tmp[i]); VIR_FREE(tmp); - return NULL; + goto cleanup; } =20 =20 @@ -546,6 +553,7 @@ virshNWFilterNameCompleter(vshControl *ctl, =20 VIR_STEAL_PTR(ret, tmp); =20 + cleanup: return ret; =20 error: @@ -555,7 +563,7 @@ virshNWFilterNameCompleter(vshControl *ctl, for (i =3D 0; i < nnwfilters; i++) VIR_FREE(tmp[i]); VIR_FREE(tmp); - return NULL; + goto cleanup; } =20 =20 @@ -594,6 +602,7 @@ virshNWFilterBindingNameCompleter(vshControl *ctl, =20 VIR_STEAL_PTR(ret, tmp); =20 + cleanup: return ret; =20 error: @@ -603,7 +612,7 @@ virshNWFilterBindingNameCompleter(vshControl *ctl, for (i =3D 0; i < nbindings; i++) VIR_FREE(tmp[i]); VIR_FREE(tmp); - return NULL; + goto cleanup; } =20 =20 @@ -643,6 +652,7 @@ virshSecretUUIDCompleter(vshControl *ctl, =20 VIR_STEAL_PTR(ret, tmp); =20 + cleanup: return ret; =20 error: @@ -652,7 +662,7 @@ virshSecretUUIDCompleter(vshControl *ctl, for (i =3D 0; i < nsecrets; i++) VIR_FREE(tmp[i]); VIR_FREE(tmp); - return NULL; + goto cleanup; } =20 =20 @@ -698,6 +708,7 @@ virshSnapshotNameCompleter(vshControl *ctl, =20 VIR_STEAL_PTR(ret, tmp); =20 + cleanup: return ret; =20 error: @@ -708,7 +719,7 @@ virshSnapshotNameCompleter(vshControl *ctl, VIR_FREE(tmp[i]); VIR_FREE(tmp); virshDomainFree(dom); - return NULL; + goto cleanup; } =20 char ** @@ -820,11 +831,12 @@ virshSecretEventNameCompleter(vshControl *ctl ATTRIBU= TE_UNUSED, =20 VIR_STEAL_PTR(ret, tmp); =20 + cleanup: return ret; =20 error: virStringListFree(tmp); - return NULL; + goto cleanup; } =20 =20 @@ -849,11 +861,12 @@ virshDomainEventNameCompleter(vshControl *ctl ATTRIBU= TE_UNUSED, =20 VIR_STEAL_PTR(ret, tmp); =20 + cleanup: return ret; =20 error: virStringListFree(tmp); - return NULL; + goto cleanup; } =20 =20 @@ -878,11 +891,12 @@ virshPoolEventNameCompleter(vshControl *ctl ATTRIBUTE= _UNUSED, =20 VIR_STEAL_PTR(ret, tmp); =20 + cleanup: return ret; =20 error: virStringListFree(tmp); - return NULL; + goto cleanup; } =20 =20 @@ -982,11 +996,12 @@ virshNodedevEventNameCompleter(vshControl *ctl ATTRIB= UTE_UNUSED, =20 VIR_STEAL_PTR(ret, tmp); =20 + cleanup: return ret; =20 error: virStringListFree(tmp); - return NULL; + goto cleanup; } =20 =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 07:40:38 2024 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 1554104008292648.212324858534; Mon, 1 Apr 2019 00:33:28 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D02C830832EB; Mon, 1 Apr 2019 07:33:26 +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 A6B0A10AFFFC; Mon, 1 Apr 2019 07:33:26 +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 65EF01803389; Mon, 1 Apr 2019 07:33:26 +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 x317XPpM013849 for ; Mon, 1 Apr 2019 03:33:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0562260BFC; Mon, 1 Apr 2019 07:33:25 +0000 (UTC) Received: from lpt.redhat.com (ovpn-204-90.brq.redhat.com [10.40.204.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id 60FFC60BE6 for ; Mon, 1 Apr 2019 07:33:24 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Mon, 1 Apr 2019 09:33:23 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 06/14] virsh-completer: unify cleanup of items in name completers 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Mon, 01 Apr 2019 07:33:27 +0000 (UTC) Merge the cleanup of fetched items for the success and the error paths. Signed-off-by: J=C3=A1n Tomko --- tools/virsh-completer.c | 97 ++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 65 deletions(-) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 46fedc06d9..9d56659259 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -104,20 +104,17 @@ virshDomainNameCompleter(vshControl *ctl, =20 if (VIR_STRDUP(tmp[i], name) < 0) goto error; - - virshDomainFree(domains[i]); } - VIR_FREE(domains); =20 VIR_STEAL_PTR(ret, tmp); =20 cleanup: + for (i =3D 0; i < ndomains; i++) + virshDomainFree(domains[i]); + VIR_FREE(domains); return ret; =20 error: - for (; i < ndomains; i++) - virshDomainFree(domains[i]); - VIR_FREE(domains); for (i =3D 0; i < ndomains; i++) VIR_FREE(tmp[i]); VIR_FREE(tmp); @@ -257,20 +254,17 @@ virshStoragePoolNameCompleter(vshControl *ctl, =20 if (VIR_STRDUP(tmp[i], name) < 0) goto error; - - virStoragePoolFree(pools[i]); } - VIR_FREE(pools); =20 VIR_STEAL_PTR(ret, tmp); =20 cleanup: + for (i =3D 0; i < npools; i++) + virStoragePoolFree(pools[i]); + VIR_FREE(pools); return ret; =20 error: - for (; i < npools; i++) - virStoragePoolFree(pools[i]); - VIR_FREE(pools); for (i =3D 0; i < npools; i++) VIR_FREE(tmp[i]); VIR_FREE(tmp); @@ -312,26 +306,21 @@ virshStorageVolNameCompleter(vshControl *ctl, =20 if (VIR_STRDUP(tmp[i], name) < 0) goto error; - - virStorageVolFree(vols[i]); } =20 - VIR_FREE(vols); - virStoragePoolFree(pool); - VIR_STEAL_PTR(ret, tmp); =20 cleanup: + virStoragePoolFree(pool); + for (i =3D 0; i < nvols; i++) + virStorageVolFree(vols[i]); + VIR_FREE(vols); return ret; =20 error: - for (; i < nvols; i++) - virStorageVolFree(vols[i]); - VIR_FREE(vols); for (i =3D 0; i < nvols; i++) VIR_FREE(tmp[i]); VIR_FREE(tmp); - virStoragePoolFree(pool); goto cleanup; } =20 @@ -366,20 +355,17 @@ virshInterfaceNameCompleter(vshControl *ctl, =20 if (VIR_STRDUP(tmp[i], name) < 0) goto error; - - virInterfaceFree(ifaces[i]); } - VIR_FREE(ifaces); =20 VIR_STEAL_PTR(ret, tmp); =20 cleanup: + for (i =3D 0; i < nifaces; i++) + virInterfaceFree(ifaces[i]); + VIR_FREE(ifaces); return ret; =20 error: - for (; i < nifaces; i++) - virInterfaceFree(ifaces[i]); - VIR_FREE(ifaces); for (i =3D 0; i < nifaces; i++) VIR_FREE(tmp[i]); VIR_FREE(tmp); @@ -418,20 +404,17 @@ virshNetworkNameCompleter(vshControl *ctl, =20 if (VIR_STRDUP(tmp[i], name) < 0) goto error; - - virNetworkFree(nets[i]); } - VIR_FREE(nets); =20 VIR_STEAL_PTR(ret, tmp); =20 cleanup: + for (i =3D 0; i < nnets; i++) + virNetworkFree(nets[i]); + VIR_FREE(nets); return ret; =20 error: - for (; i < nnets; i++) - virNetworkFree(nets[i]); - VIR_FREE(nets); for (i =3D 0; i < nnets; i++) VIR_FREE(tmp[i]); VIR_FREE(tmp); @@ -497,20 +480,17 @@ virshNodeDeviceNameCompleter(vshControl *ctl, =20 if (VIR_STRDUP(tmp[i], name) < 0) goto error; - - virNodeDeviceFree(devs[i]); } - VIR_FREE(devs); =20 VIR_STEAL_PTR(ret, tmp); =20 cleanup: + for (i =3D 0; i < ndevs; i++) + virNodeDeviceFree(devs[i]); + VIR_FREE(devs); return ret; =20 error: - for (; i < ndevs; i++) - virNodeDeviceFree(devs[i]); - VIR_FREE(devs); for (i =3D 0; i < ndevs; i++) VIR_FREE(tmp[i]); VIR_FREE(tmp); @@ -546,20 +526,17 @@ virshNWFilterNameCompleter(vshControl *ctl, =20 if (VIR_STRDUP(tmp[i], name) < 0) goto error; - - virNWFilterFree(nwfilters[i]); } - VIR_FREE(nwfilters); =20 VIR_STEAL_PTR(ret, tmp); =20 cleanup: + for (i =3D 0; i < nnwfilters; i++) + virNWFilterFree(nwfilters[i]); + VIR_FREE(nwfilters); return ret; =20 error: - for (; i < nnwfilters; i++) - virNWFilterFree(nwfilters[i]); - VIR_FREE(nwfilters); for (i =3D 0; i < nnwfilters; i++) VIR_FREE(tmp[i]); VIR_FREE(tmp); @@ -595,20 +572,17 @@ virshNWFilterBindingNameCompleter(vshControl *ctl, =20 if (VIR_STRDUP(tmp[i], name) < 0) goto error; - - virNWFilterBindingFree(bindings[i]); } - VIR_FREE(bindings); =20 VIR_STEAL_PTR(ret, tmp); =20 cleanup: + for (i =3D 0; i < nbindings; i++) + virNWFilterBindingFree(bindings[i]); + VIR_FREE(bindings); return ret; =20 error: - for (; i < nbindings; i++) - virNWFilterBindingFree(bindings[i]); - VIR_FREE(bindings); for (i =3D 0; i < nbindings; i++) VIR_FREE(tmp[i]); VIR_FREE(tmp); @@ -645,20 +619,17 @@ virshSecretUUIDCompleter(vshControl *ctl, if (virSecretGetUUIDString(secrets[i], uuid) < 0 || VIR_STRDUP(tmp[i], uuid) < 0) goto error; - - virSecretFree(secrets[i]); } - VIR_FREE(secrets); =20 VIR_STEAL_PTR(ret, tmp); =20 cleanup: + for (i =3D 0; i < nsecrets; i++) + virSecretFree(secrets[i]); + VIR_FREE(secrets); return ret; =20 error: - for (; i < nsecrets; i++) - virSecretFree(secrets[i]); - VIR_FREE(secrets); for (i =3D 0; i < nsecrets; i++) VIR_FREE(tmp[i]); VIR_FREE(tmp); @@ -700,25 +671,21 @@ virshSnapshotNameCompleter(vshControl *ctl, =20 if (VIR_STRDUP(tmp[i], name) < 0) goto error; - - virshDomainSnapshotFree(snapshots[i]); } - VIR_FREE(snapshots); - virshDomainFree(dom); =20 VIR_STEAL_PTR(ret, tmp); =20 cleanup: + virshDomainFree(dom); + for (i =3D 0; i < nsnapshots; i++) + virshDomainSnapshotFree(snapshots[i]); + VIR_FREE(snapshots); return ret; =20 error: - for (; i < nsnapshots; i++) - virshDomainSnapshotFree(snapshots[i]); - VIR_FREE(snapshots); for (i =3D 0; i < nsnapshots; i++) VIR_FREE(tmp[i]); VIR_FREE(tmp); - virshDomainFree(dom); goto cleanup; } =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 07:40:38 2024 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 15541040133481017.8041995405831; Mon, 1 Apr 2019 00:33:33 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A0B6F307CDD5; Mon, 1 Apr 2019 07:33:31 +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 6E3C0600C7; Mon, 1 Apr 2019 07:33:31 +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 2EBB4180338C; Mon, 1 Apr 2019 07:33:31 +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 x317XRHD013865 for ; Mon, 1 Apr 2019 03:33:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id 74C361908F; Mon, 1 Apr 2019 07:33:27 +0000 (UTC) Received: from lpt.redhat.com (ovpn-204-90.brq.redhat.com [10.40.204.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id B5F1960BE6 for ; Mon, 1 Apr 2019 07:33:25 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Mon, 1 Apr 2019 09:33:24 +0200 Message-Id: <2141a7a442ffeaa290cc9750375bc76d04810406.1554103986.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 07/14] virsh-completer: virStringListFree where possible 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-Type: text/plain; charset="utf-8" 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Mon, 01 Apr 2019 07:33:32 +0000 (UTC) We've been open-coding virStringListFreeCount for cleaning up the completion list we're building. This had the advantage of zeoring the pointer afterwards, which is no longer needed now that we compile the list in 'tmp' instead of 'ret'. Since all our lists are NULL-terminated anyway, switch to using virStringListFree which has the benefit of being usable with our VIR_AUTOSTRINGLIST macro. Fixes nearly impossible NULL dereferences in virshNWFilterBindingNameCompleter virshNWFilterNameCompleter virshNodeDeviceNameCompleter virshNetworkNameCompleter virshInterfaceNameCompleter virshStoragePoolNameCompleter virshDomainNameCompleter which jumped on the error label after a failed allocation and a possible one in virshStorageVolNameCompleter which jumped there when we fail to fetch the list of volumes. Signed-off-by: J=C3=A1n Tomko --- tools/virsh-completer.c | 67 +++++++++++------------------------------ 1 file changed, 18 insertions(+), 49 deletions(-) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 9d56659259..20b325c020 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -112,12 +112,10 @@ virshDomainNameCompleter(vshControl *ctl, for (i =3D 0; i < ndomains; i++) virshDomainFree(domains[i]); VIR_FREE(domains); + virStringListFree(tmp); return ret; =20 error: - for (i =3D 0; i < ndomains; i++) - VIR_FREE(tmp[i]); - VIR_FREE(tmp); goto cleanup; } =20 @@ -262,12 +260,10 @@ virshStoragePoolNameCompleter(vshControl *ctl, for (i =3D 0; i < npools; i++) virStoragePoolFree(pools[i]); VIR_FREE(pools); + virStringListFree(tmp); return ret; =20 error: - for (i =3D 0; i < npools; i++) - VIR_FREE(tmp[i]); - VIR_FREE(tmp); goto cleanup; } =20 @@ -315,12 +311,10 @@ virshStorageVolNameCompleter(vshControl *ctl, for (i =3D 0; i < nvols; i++) virStorageVolFree(vols[i]); VIR_FREE(vols); + virStringListFree(tmp); return ret; =20 error: - for (i =3D 0; i < nvols; i++) - VIR_FREE(tmp[i]); - VIR_FREE(tmp); goto cleanup; } =20 @@ -363,12 +357,10 @@ virshInterfaceNameCompleter(vshControl *ctl, for (i =3D 0; i < nifaces; i++) virInterfaceFree(ifaces[i]); VIR_FREE(ifaces); + virStringListFree(tmp); return ret; =20 error: - for (i =3D 0; i < nifaces; i++) - VIR_FREE(tmp[i]); - VIR_FREE(tmp); goto cleanup; } =20 @@ -412,12 +404,10 @@ virshNetworkNameCompleter(vshControl *ctl, for (i =3D 0; i < nnets; i++) virNetworkFree(nets[i]); VIR_FREE(nets); + virStringListFree(tmp); return ret; =20 error: - for (i =3D 0; i < nnets; i++) - VIR_FREE(tmp[i]); - VIR_FREE(tmp); goto cleanup; } =20 @@ -444,10 +434,10 @@ virshNetworkEventNameCompleter(vshControl *ctl ATTRIB= UTE_UNUSED, VIR_STEAL_PTR(ret, tmp); =20 cleanup: + virStringListFree(tmp); return ret; =20 error: - virStringListFree(tmp); goto cleanup; } =20 @@ -488,12 +478,10 @@ virshNodeDeviceNameCompleter(vshControl *ctl, for (i =3D 0; i < ndevs; i++) virNodeDeviceFree(devs[i]); VIR_FREE(devs); + virStringListFree(tmp); return ret; =20 error: - for (i =3D 0; i < ndevs; i++) - VIR_FREE(tmp[i]); - VIR_FREE(tmp); goto cleanup; } =20 @@ -534,12 +522,10 @@ virshNWFilterNameCompleter(vshControl *ctl, for (i =3D 0; i < nnwfilters; i++) virNWFilterFree(nwfilters[i]); VIR_FREE(nwfilters); + virStringListFree(tmp); return ret; =20 error: - for (i =3D 0; i < nnwfilters; i++) - VIR_FREE(tmp[i]); - VIR_FREE(tmp); goto cleanup; } =20 @@ -580,12 +566,10 @@ virshNWFilterBindingNameCompleter(vshControl *ctl, for (i =3D 0; i < nbindings; i++) virNWFilterBindingFree(bindings[i]); VIR_FREE(bindings); + virStringListFree(tmp); return ret; =20 error: - for (i =3D 0; i < nbindings; i++) - VIR_FREE(tmp[i]); - VIR_FREE(tmp); goto cleanup; } =20 @@ -627,12 +611,10 @@ virshSecretUUIDCompleter(vshControl *ctl, for (i =3D 0; i < nsecrets; i++) virSecretFree(secrets[i]); VIR_FREE(secrets); + virStringListFree(tmp); return ret; =20 error: - for (i =3D 0; i < nsecrets; i++) - VIR_FREE(tmp[i]); - VIR_FREE(tmp); goto cleanup; } =20 @@ -680,12 +662,10 @@ virshSnapshotNameCompleter(vshControl *ctl, for (i =3D 0; i < nsnapshots; i++) virshDomainSnapshotFree(snapshots[i]); VIR_FREE(snapshots); + virStringListFree(tmp); return ret; =20 error: - for (i =3D 0; i < nsnapshots; i++) - VIR_FREE(tmp[i]); - VIR_FREE(tmp); goto cleanup; } =20 @@ -764,15 +744,10 @@ virshAllocpagesPagesizeCompleter(vshControl *ctl, VIR_FREE(pagesize); VIR_FREE(cap_xml); VIR_FREE(unit); - + virStringListFree(tmp); return ret; =20 error: - if (tmp) { - for (i =3D 0; i < npages; i++) - VIR_FREE(tmp[i]); - } - VIR_FREE(tmp); goto cleanup; } =20 @@ -799,10 +774,10 @@ virshSecretEventNameCompleter(vshControl *ctl ATTRIBU= TE_UNUSED, VIR_STEAL_PTR(ret, tmp); =20 cleanup: + virStringListFree(tmp); return ret; =20 error: - virStringListFree(tmp); goto cleanup; } =20 @@ -829,10 +804,10 @@ virshDomainEventNameCompleter(vshControl *ctl ATTRIBU= TE_UNUSED, VIR_STEAL_PTR(ret, tmp); =20 cleanup: + virStringListFree(tmp); return ret; =20 error: - virStringListFree(tmp); goto cleanup; } =20 @@ -859,10 +834,10 @@ virshPoolEventNameCompleter(vshControl *ctl ATTRIBUTE= _UNUSED, VIR_STEAL_PTR(ret, tmp); =20 cleanup: + virStringListFree(tmp); return ret; =20 error: - virStringListFree(tmp); goto cleanup; } =20 @@ -933,11 +908,10 @@ virshDomainInterfaceStateCompleter(vshControl *ctl, VIR_FREE(interfaces); xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); + virStringListFree(tmp); return ret; =20 error: - virStringListFree(tmp); - tmp =3D NULL; goto cleanup; } =20 @@ -964,10 +938,10 @@ virshNodedevEventNameCompleter(vshControl *ctl ATTRIB= UTE_UNUSED, VIR_STEAL_PTR(ret, tmp); =20 cleanup: + virStringListFree(tmp); return ret; =20 error: - virStringListFree(tmp); goto cleanup; } =20 @@ -1017,15 +991,10 @@ virshCellnoCompleter(vshControl *ctl, VIR_FREE(cells); xmlFreeDoc(doc); VIR_FREE(cap_xml); - + virStringListFree(tmp); return ret; =20 error: - if (tmp) { - for (i =3D 0; i < ncells; i++) - VIR_FREE(tmp[i]); - } - VIR_FREE(tmp); goto cleanup; } =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 07:40:38 2024 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 1554104028002329.3025628439974; Mon, 1 Apr 2019 00:33:48 -0700 (PDT) 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 6543B30BC666; Mon, 1 Apr 2019 07:33:46 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4159560BFC; Mon, 1 Apr 2019 07:33:46 +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 E2B143FA50; Mon, 1 Apr 2019 07:33:45 +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 x317XSbR013881 for ; Mon, 1 Apr 2019 03:33:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 75E3860BFC; Mon, 1 Apr 2019 07:33:28 +0000 (UTC) Received: from lpt.redhat.com (ovpn-204-90.brq.redhat.com [10.40.204.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id D7A2F60BE6 for ; Mon, 1 Apr 2019 07:33:27 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Mon, 1 Apr 2019 09:33:25 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 08/14] virsh-completer: use VIR_AUTOSTRINGLIST for tmp 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-Type: text/plain; charset="utf-8" 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.46]); Mon, 01 Apr 2019 07:33:47 +0000 (UTC) Now that every function uses virStringListFree, we can use the VIR_AUTOSTRINGLIST to have the compiler call this function automatically when 'tmp' goes out of scope. Signed-off-by: J=C3=A1n Tomko --- tools/virsh-completer.c | 63 ++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 42 deletions(-) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 20b325c020..669eda0f84 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -79,7 +79,7 @@ virshDomainNameCompleter(vshControl *ctl, int ndomains =3D 0; size_t i =3D 0; char **ret =3D NULL; - char **tmp =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; =20 virCheckFlags(VIR_CONNECT_LIST_DOMAINS_ACTIVE | VIR_CONNECT_LIST_DOMAINS_INACTIVE | @@ -112,7 +112,6 @@ virshDomainNameCompleter(vshControl *ctl, for (i =3D 0; i < ndomains; i++) virshDomainFree(domains[i]); VIR_FREE(domains); - virStringListFree(tmp); return ret; =20 error: @@ -133,7 +132,7 @@ virshDomainInterfaceCompleter(vshControl *ctl, size_t i; unsigned int domainXMLFlags =3D 0; char **ret =3D NULL; - char **tmp =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; =20 virCheckFlags(VIRSH_DOMAIN_INTERFACE_COMPLETER_MAC, NULL); =20 @@ -171,7 +170,6 @@ virshDomainInterfaceCompleter(vshControl *ctl, VIR_FREE(interfaces); xmlFreeDoc(xmldoc); xmlXPathFreeContext(ctxt); - virStringListFree(tmp); return ret; } =20 @@ -187,7 +185,7 @@ virshDomainDiskTargetCompleter(vshControl *ctl, xmlNodePtr *disks =3D NULL; int ndisks; size_t i; - char **tmp =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; char **ret =3D NULL; =20 virCheckFlags(0, NULL); @@ -216,7 +214,6 @@ virshDomainDiskTargetCompleter(vshControl *ctl, VIR_FREE(disks); xmlFreeDoc(xmldoc); xmlXPathFreeContext(ctxt); - virStringListFree(tmp); return ret; } =20 @@ -231,7 +228,7 @@ virshStoragePoolNameCompleter(vshControl *ctl, int npools =3D 0; size_t i =3D 0; char **ret =3D NULL; - char **tmp =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; =20 virCheckFlags(VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE | VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE | @@ -260,7 +257,6 @@ virshStoragePoolNameCompleter(vshControl *ctl, for (i =3D 0; i < npools; i++) virStoragePoolFree(pools[i]); VIR_FREE(pools); - virStringListFree(tmp); return ret; =20 error: @@ -280,7 +276,7 @@ virshStorageVolNameCompleter(vshControl *ctl, int nvols =3D 0; size_t i =3D 0; char **ret =3D NULL; - char **tmp =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -311,7 +307,6 @@ virshStorageVolNameCompleter(vshControl *ctl, for (i =3D 0; i < nvols; i++) virStorageVolFree(vols[i]); VIR_FREE(vols); - virStringListFree(tmp); return ret; =20 error: @@ -329,7 +324,7 @@ virshInterfaceNameCompleter(vshControl *ctl, int nifaces =3D 0; size_t i =3D 0; char **ret =3D NULL; - char **tmp =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; =20 virCheckFlags(VIR_CONNECT_LIST_INTERFACES_ACTIVE | VIR_CONNECT_LIST_INTERFACES_INACTIVE, @@ -357,7 +352,6 @@ virshInterfaceNameCompleter(vshControl *ctl, for (i =3D 0; i < nifaces; i++) virInterfaceFree(ifaces[i]); VIR_FREE(ifaces); - virStringListFree(tmp); return ret; =20 error: @@ -375,7 +369,7 @@ virshNetworkNameCompleter(vshControl *ctl, int nnets =3D 0; size_t i =3D 0; char **ret =3D NULL; - char **tmp =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; =20 virCheckFlags(VIR_CONNECT_LIST_NETWORKS_INACTIVE | VIR_CONNECT_LIST_NETWORKS_ACTIVE | @@ -404,7 +398,6 @@ virshNetworkNameCompleter(vshControl *ctl, for (i =3D 0; i < nnets; i++) virNetworkFree(nets[i]); VIR_FREE(nets); - virStringListFree(tmp); return ret; =20 error: @@ -419,7 +412,7 @@ virshNetworkEventNameCompleter(vshControl *ctl ATTRIBUT= E_UNUSED, { size_t i =3D 0; char **ret =3D NULL; - char **tmp =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -434,7 +427,6 @@ virshNetworkEventNameCompleter(vshControl *ctl ATTRIBUT= E_UNUSED, VIR_STEAL_PTR(ret, tmp); =20 cleanup: - virStringListFree(tmp); return ret; =20 error: @@ -452,7 +444,7 @@ virshNodeDeviceNameCompleter(vshControl *ctl, int ndevs =3D 0; size_t i =3D 0; char **ret =3D NULL; - char **tmp =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -478,7 +470,6 @@ virshNodeDeviceNameCompleter(vshControl *ctl, for (i =3D 0; i < ndevs; i++) virNodeDeviceFree(devs[i]); VIR_FREE(devs); - virStringListFree(tmp); return ret; =20 error: @@ -496,7 +487,7 @@ virshNWFilterNameCompleter(vshControl *ctl, int nnwfilters =3D 0; size_t i =3D 0; char **ret =3D NULL; - char **tmp =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -522,7 +513,6 @@ virshNWFilterNameCompleter(vshControl *ctl, for (i =3D 0; i < nnwfilters; i++) virNWFilterFree(nwfilters[i]); VIR_FREE(nwfilters); - virStringListFree(tmp); return ret; =20 error: @@ -540,7 +530,7 @@ virshNWFilterBindingNameCompleter(vshControl *ctl, int nbindings =3D 0; size_t i =3D 0; char **ret =3D NULL; - char **tmp =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -566,7 +556,6 @@ virshNWFilterBindingNameCompleter(vshControl *ctl, for (i =3D 0; i < nbindings; i++) virNWFilterBindingFree(bindings[i]); VIR_FREE(bindings); - virStringListFree(tmp); return ret; =20 error: @@ -584,7 +573,7 @@ virshSecretUUIDCompleter(vshControl *ctl, int nsecrets =3D 0; size_t i =3D 0; char **ret =3D NULL; - char **tmp =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -611,7 +600,6 @@ virshSecretUUIDCompleter(vshControl *ctl, for (i =3D 0; i < nsecrets; i++) virSecretFree(secrets[i]); VIR_FREE(secrets); - virStringListFree(tmp); return ret; =20 error: @@ -631,7 +619,7 @@ virshSnapshotNameCompleter(vshControl *ctl, int nsnapshots =3D 0; size_t i =3D 0; char **ret =3D NULL; - char **tmp =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -662,7 +650,6 @@ virshSnapshotNameCompleter(vshControl *ctl, for (i =3D 0; i < nsnapshots; i++) virshDomainSnapshotFree(snapshots[i]); VIR_FREE(snapshots); - virStringListFree(tmp); return ret; =20 error: @@ -690,7 +677,7 @@ virshAllocpagesPagesizeCompleter(vshControl *ctl, char *cap_xml =3D NULL; char **ret =3D NULL; char *unit =3D NULL; - char **tmp =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -744,7 +731,6 @@ virshAllocpagesPagesizeCompleter(vshControl *ctl, VIR_FREE(pagesize); VIR_FREE(cap_xml); VIR_FREE(unit); - virStringListFree(tmp); return ret; =20 error: @@ -759,7 +745,7 @@ virshSecretEventNameCompleter(vshControl *ctl ATTRIBUTE= _UNUSED, { size_t i; char **ret =3D NULL; - char **tmp =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -774,7 +760,6 @@ virshSecretEventNameCompleter(vshControl *ctl ATTRIBUTE= _UNUSED, VIR_STEAL_PTR(ret, tmp); =20 cleanup: - virStringListFree(tmp); return ret; =20 error: @@ -789,7 +774,7 @@ virshDomainEventNameCompleter(vshControl *ctl ATTRIBUTE= _UNUSED, { size_t i =3D 0; char **ret =3D NULL; - char **tmp =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -804,7 +789,6 @@ virshDomainEventNameCompleter(vshControl *ctl ATTRIBUTE= _UNUSED, VIR_STEAL_PTR(ret, tmp); =20 cleanup: - virStringListFree(tmp); return ret; =20 error: @@ -819,7 +803,7 @@ virshPoolEventNameCompleter(vshControl *ctl ATTRIBUTE_U= NUSED, { size_t i =3D 0; char **ret =3D NULL; - char **tmp =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -834,7 +818,6 @@ virshPoolEventNameCompleter(vshControl *ctl ATTRIBUTE_U= NUSED, VIR_STEAL_PTR(ret, tmp); =20 cleanup: - virStringListFree(tmp); return ret; =20 error: @@ -858,7 +841,7 @@ virshDomainInterfaceStateCompleter(vshControl *ctl, xmlNodePtr *interfaces =3D NULL; char *xpath =3D NULL; char *state =3D NULL; - char **tmp =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -908,7 +891,6 @@ virshDomainInterfaceStateCompleter(vshControl *ctl, VIR_FREE(interfaces); xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); - virStringListFree(tmp); return ret; =20 error: @@ -923,7 +905,7 @@ virshNodedevEventNameCompleter(vshControl *ctl ATTRIBUT= E_UNUSED, { size_t i =3D 0; char **ret =3D NULL; - char **tmp =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -938,7 +920,6 @@ virshNodedevEventNameCompleter(vshControl *ctl ATTRIBUT= E_UNUSED, VIR_STEAL_PTR(ret, tmp); =20 cleanup: - virStringListFree(tmp); return ret; =20 error: @@ -959,7 +940,7 @@ virshCellnoCompleter(vshControl *ctl, size_t i =3D 0; char *cap_xml =3D NULL; char **ret =3D NULL; - char **tmp =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -991,7 +972,6 @@ virshCellnoCompleter(vshControl *ctl, VIR_FREE(cells); xmlFreeDoc(doc); VIR_FREE(cap_xml); - virStringListFree(tmp); return ret; =20 error: @@ -1012,7 +992,7 @@ virshDomainDeviceAliasCompleter(vshControl *ctl, size_t i; unsigned int domainXMLFlags =3D 0; char **ret =3D NULL; - char **tmp =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -1042,6 +1022,5 @@ virshDomainDeviceAliasCompleter(vshControl *ctl, VIR_FREE(aliases); xmlFreeDoc(xmldoc); xmlXPathFreeContext(ctxt); - virStringListFree(tmp); return ret; } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 07:40:38 2024 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 155410403165424.32719031103443; Mon, 1 Apr 2019 00:33:51 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 36BBA307D84F; Mon, 1 Apr 2019 07:33:50 +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 0ADA82E042; Mon, 1 Apr 2019 07:33:50 +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 BEF89181A84A; Mon, 1 Apr 2019 07:33:49 +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 x317XT3E013891 for ; Mon, 1 Apr 2019 03:33:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id 80F6A60BFC; Mon, 1 Apr 2019 07:33:29 +0000 (UTC) Received: from lpt.redhat.com (ovpn-204-90.brq.redhat.com [10.40.204.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id DCC8460BE6 for ; Mon, 1 Apr 2019 07:33:28 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Mon, 1 Apr 2019 09:33:26 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 09/14] use VIR_AUTOFREE for xmlNodePtr* variables 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-Type: text/plain; charset="utf-8" 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Mon, 01 Apr 2019 07:33:50 +0000 (UTC) Signed-off-by: J=C3=A1n Tomko --- tools/virsh-completer.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 669eda0f84..3d107f0504 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -128,7 +128,7 @@ virshDomainInterfaceCompleter(vshControl *ctl, xmlDocPtr xmldoc =3D NULL; xmlXPathContextPtr ctxt =3D NULL; int ninterfaces; - xmlNodePtr *interfaces =3D NULL; + VIR_AUTOFREE(xmlNodePtr *) interfaces =3D NULL; size_t i; unsigned int domainXMLFlags =3D 0; char **ret =3D NULL; @@ -167,7 +167,6 @@ virshDomainInterfaceCompleter(vshControl *ctl, =20 VIR_STEAL_PTR(ret, tmp); cleanup: - VIR_FREE(interfaces); xmlFreeDoc(xmldoc); xmlXPathFreeContext(ctxt); return ret; @@ -182,7 +181,7 @@ virshDomainDiskTargetCompleter(vshControl *ctl, virshControlPtr priv =3D ctl->privData; xmlDocPtr xmldoc =3D NULL; xmlXPathContextPtr ctxt =3D NULL; - xmlNodePtr *disks =3D NULL; + VIR_AUTOFREE(xmlNodePtr *) disks =3D NULL; int ndisks; size_t i; VIR_AUTOSTRINGLIST tmp =3D NULL; @@ -211,7 +210,6 @@ virshDomainDiskTargetCompleter(vshControl *ctl, =20 VIR_STEAL_PTR(ret, tmp); cleanup: - VIR_FREE(disks); xmlFreeDoc(xmldoc); xmlXPathFreeContext(ctxt); return ret; @@ -665,7 +663,7 @@ virshAllocpagesPagesizeCompleter(vshControl *ctl, xmlXPathContextPtr ctxt =3D NULL; virshControlPtr priv =3D ctl->privData; unsigned int npages =3D 0; - xmlNodePtr *pages =3D NULL; + VIR_AUTOFREE(xmlNodePtr *) pages =3D NULL; xmlDocPtr doc =3D NULL; double size =3D 0; size_t i =3D 0; @@ -725,7 +723,6 @@ virshAllocpagesPagesizeCompleter(vshControl *ctl, =20 cleanup: xmlXPathFreeContext(ctxt); - VIR_FREE(pages); xmlFreeDoc(doc); VIR_FREE(path); VIR_FREE(pagesize); @@ -838,7 +835,7 @@ virshDomainInterfaceStateCompleter(vshControl *ctl, virMacAddr macaddr; char macstr[VIR_MAC_STRING_BUFLEN] =3D ""; int ninterfaces; - xmlNodePtr *interfaces =3D NULL; + VIR_AUTOFREE(xmlNodePtr *) interfaces =3D NULL; char *xpath =3D NULL; char *state =3D NULL; VIR_AUTOSTRINGLIST tmp =3D NULL; @@ -888,7 +885,6 @@ virshDomainInterfaceStateCompleter(vshControl *ctl, cleanup: VIR_FREE(state); VIR_FREE(xpath); - VIR_FREE(interfaces); xmlXPathFreeContext(ctxt); xmlFreeDoc(xml); return ret; @@ -935,7 +931,7 @@ virshCellnoCompleter(vshControl *ctl, xmlXPathContextPtr ctxt =3D NULL; virshControlPtr priv =3D ctl->privData; unsigned int ncells =3D 0; - xmlNodePtr *cells =3D NULL; + VIR_AUTOFREE(xmlNodePtr *) cells =3D NULL; xmlDocPtr doc =3D NULL; size_t i =3D 0; char *cap_xml =3D NULL; @@ -969,7 +965,6 @@ virshCellnoCompleter(vshControl *ctl, =20 cleanup: xmlXPathFreeContext(ctxt); - VIR_FREE(cells); xmlFreeDoc(doc); VIR_FREE(cap_xml); return ret; @@ -988,7 +983,7 @@ virshDomainDeviceAliasCompleter(vshControl *ctl, xmlDocPtr xmldoc =3D NULL; xmlXPathContextPtr ctxt =3D NULL; int naliases; - xmlNodePtr *aliases =3D NULL; + VIR_AUTOFREE(xmlNodePtr *) aliases =3D NULL; size_t i; unsigned int domainXMLFlags =3D 0; char **ret =3D NULL; @@ -1019,7 +1014,6 @@ virshDomainDeviceAliasCompleter(vshControl *ctl, =20 VIR_STEAL_PTR(ret, tmp); cleanup: - VIR_FREE(aliases); xmlFreeDoc(xmldoc); xmlXPathFreeContext(ctxt); return ret; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 07:40:38 2024 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 1554104035002238.64212477611227; Mon, 1 Apr 2019 00:33:55 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E7CA4308621A; Mon, 1 Apr 2019 07:33:53 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BCB1718EF5; Mon, 1 Apr 2019 07:33:53 +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 7652E3FA46; Mon, 1 Apr 2019 07:33:53 +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 x317XUI8013901 for ; Mon, 1 Apr 2019 03:33:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 85FC11908F; Mon, 1 Apr 2019 07:33:30 +0000 (UTC) Received: from lpt.redhat.com (ovpn-204-90.brq.redhat.com [10.40.204.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id DC59760BE6 for ; Mon, 1 Apr 2019 07:33:29 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Mon, 1 Apr 2019 09:33:27 +0200 Message-Id: <982c08c9d5b289290ca007f8c9941876699496a1.1554103986.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 10/14] virsh-completer: use VIR_AUTOPTR for xml* variables 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-Type: text/plain; charset="utf-8" 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Mon, 01 Apr 2019 07:33:54 +0000 (UTC) Signed-off-by: J=C3=A1n Tomko --- tools/virsh-completer.c | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 3d107f0504..dc4fe2b83a 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -125,8 +125,8 @@ virshDomainInterfaceCompleter(vshControl *ctl, unsigned int flags) { virshControlPtr priv =3D ctl->privData; - xmlDocPtr xmldoc =3D NULL; - xmlXPathContextPtr ctxt =3D NULL; + VIR_AUTOPTR(xmlDoc) xmldoc =3D NULL; + VIR_AUTOPTR(xmlXPathContext) ctxt =3D NULL; int ninterfaces; VIR_AUTOFREE(xmlNodePtr *) interfaces =3D NULL; size_t i; @@ -167,8 +167,6 @@ virshDomainInterfaceCompleter(vshControl *ctl, =20 VIR_STEAL_PTR(ret, tmp); cleanup: - xmlFreeDoc(xmldoc); - xmlXPathFreeContext(ctxt); return ret; } =20 @@ -179,8 +177,8 @@ virshDomainDiskTargetCompleter(vshControl *ctl, unsigned int flags) { virshControlPtr priv =3D ctl->privData; - xmlDocPtr xmldoc =3D NULL; - xmlXPathContextPtr ctxt =3D NULL; + VIR_AUTOPTR(xmlDoc) xmldoc =3D NULL; + VIR_AUTOPTR(xmlXPathContext) ctxt =3D NULL; VIR_AUTOFREE(xmlNodePtr *) disks =3D NULL; int ndisks; size_t i; @@ -210,8 +208,6 @@ virshDomainDiskTargetCompleter(vshControl *ctl, =20 VIR_STEAL_PTR(ret, tmp); cleanup: - xmlFreeDoc(xmldoc); - xmlXPathFreeContext(ctxt); return ret; } =20 @@ -660,11 +656,11 @@ virshAllocpagesPagesizeCompleter(vshControl *ctl, unsigned int flags) { unsigned long long byteval =3D 0; - xmlXPathContextPtr ctxt =3D NULL; + VIR_AUTOPTR(xmlXPathContext) ctxt =3D NULL; virshControlPtr priv =3D ctl->privData; unsigned int npages =3D 0; VIR_AUTOFREE(xmlNodePtr *) pages =3D NULL; - xmlDocPtr doc =3D NULL; + VIR_AUTOPTR(xmlDoc) doc =3D NULL; double size =3D 0; size_t i =3D 0; const char *suffix =3D NULL; @@ -722,8 +718,6 @@ virshAllocpagesPagesizeCompleter(vshControl *ctl, VIR_STEAL_PTR(ret, tmp); =20 cleanup: - xmlXPathFreeContext(ctxt); - xmlFreeDoc(doc); VIR_FREE(path); VIR_FREE(pagesize); VIR_FREE(cap_xml); @@ -830,8 +824,8 @@ virshDomainInterfaceStateCompleter(vshControl *ctl, virshControlPtr priv =3D ctl->privData; const char *iface =3D NULL; char **ret =3D NULL; - xmlDocPtr xml =3D NULL; - xmlXPathContextPtr ctxt =3D NULL; + VIR_AUTOPTR(xmlDoc) xml =3D NULL; + VIR_AUTOPTR(xmlXPathContext) ctxt =3D NULL; virMacAddr macaddr; char macstr[VIR_MAC_STRING_BUFLEN] =3D ""; int ninterfaces; @@ -885,8 +879,6 @@ virshDomainInterfaceStateCompleter(vshControl *ctl, cleanup: VIR_FREE(state); VIR_FREE(xpath); - xmlXPathFreeContext(ctxt); - xmlFreeDoc(xml); return ret; =20 error: @@ -928,11 +920,11 @@ virshCellnoCompleter(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED, unsigned int flags) { - xmlXPathContextPtr ctxt =3D NULL; + VIR_AUTOPTR(xmlXPathContext) ctxt =3D NULL; virshControlPtr priv =3D ctl->privData; unsigned int ncells =3D 0; VIR_AUTOFREE(xmlNodePtr *) cells =3D NULL; - xmlDocPtr doc =3D NULL; + VIR_AUTOPTR(xmlDoc) doc =3D NULL; size_t i =3D 0; char *cap_xml =3D NULL; char **ret =3D NULL; @@ -964,8 +956,6 @@ virshCellnoCompleter(vshControl *ctl, VIR_STEAL_PTR(ret, tmp); =20 cleanup: - xmlXPathFreeContext(ctxt); - xmlFreeDoc(doc); VIR_FREE(cap_xml); return ret; =20 @@ -980,8 +970,8 @@ virshDomainDeviceAliasCompleter(vshControl *ctl, unsigned int flags) { virshControlPtr priv =3D ctl->privData; - xmlDocPtr xmldoc =3D NULL; - xmlXPathContextPtr ctxt =3D NULL; + VIR_AUTOPTR(xmlDoc) xmldoc =3D NULL; + VIR_AUTOPTR(xmlXPathContext) ctxt =3D NULL; int naliases; VIR_AUTOFREE(xmlNodePtr *) aliases =3D NULL; size_t i; @@ -1014,7 +1004,5 @@ virshDomainDeviceAliasCompleter(vshControl *ctl, =20 VIR_STEAL_PTR(ret, tmp); cleanup: - xmlFreeDoc(xmldoc); - xmlXPathFreeContext(ctxt); return ret; } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 07:40:38 2024 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 1554104019972963.1902461811635; Mon, 1 Apr 2019 00:33:39 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C1E3B308FBB1; Mon, 1 Apr 2019 07:33:38 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 92DB96013A; Mon, 1 Apr 2019 07:33:38 +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 51EBD3FA46; Mon, 1 Apr 2019 07:33:38 +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 x317XbC1013923 for ; Mon, 1 Apr 2019 03:33:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7E08E60BE6; Mon, 1 Apr 2019 07:33:37 +0000 (UTC) Received: from lpt.redhat.com (ovpn-204-90.brq.redhat.com [10.40.204.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id B491D60BFC for ; Mon, 1 Apr 2019 07:33:32 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Mon, 1 Apr 2019 09:33:28 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 11/14] virsh-completer: use VIR_AUTOFREE for char* variables 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-Type: text/plain; charset="utf-8" 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Mon, 01 Apr 2019 07:33:39 +0000 (UTC) Signed-off-by: J=C3=A1n Tomko --- tools/virsh-completer.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index dc4fe2b83a..025eee19e2 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -666,11 +666,11 @@ virshAllocpagesPagesizeCompleter(vshControl *ctl, const char *suffix =3D NULL; const char *cellnum =3D NULL; bool cellno =3D vshCommandOptBool(cmd, "cellno"); - char *path =3D NULL; - char *pagesize =3D NULL; - char *cap_xml =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; + VIR_AUTOFREE(char *) pagesize =3D NULL; + VIR_AUTOFREE(char *) cap_xml =3D NULL; char **ret =3D NULL; - char *unit =3D NULL; + VIR_AUTOFREE(char *) unit =3D NULL; VIR_AUTOSTRINGLIST tmp =3D NULL; =20 virCheckFlags(0, NULL); @@ -718,10 +718,6 @@ virshAllocpagesPagesizeCompleter(vshControl *ctl, VIR_STEAL_PTR(ret, tmp); =20 cleanup: - VIR_FREE(path); - VIR_FREE(pagesize); - VIR_FREE(cap_xml); - VIR_FREE(unit); return ret; =20 error: @@ -830,8 +826,8 @@ virshDomainInterfaceStateCompleter(vshControl *ctl, char macstr[VIR_MAC_STRING_BUFLEN] =3D ""; int ninterfaces; VIR_AUTOFREE(xmlNodePtr *) interfaces =3D NULL; - char *xpath =3D NULL; - char *state =3D NULL; + VIR_AUTOFREE(char *) xpath =3D NULL; + VIR_AUTOFREE(char *) state =3D NULL; VIR_AUTOSTRINGLIST tmp =3D NULL; =20 virCheckFlags(0, NULL); @@ -877,8 +873,6 @@ virshDomainInterfaceStateCompleter(vshControl *ctl, VIR_STEAL_PTR(ret, tmp); =20 cleanup: - VIR_FREE(state); - VIR_FREE(xpath); return ret; =20 error: @@ -926,7 +920,7 @@ virshCellnoCompleter(vshControl *ctl, VIR_AUTOFREE(xmlNodePtr *) cells =3D NULL; VIR_AUTOPTR(xmlDoc) doc =3D NULL; size_t i =3D 0; - char *cap_xml =3D NULL; + VIR_AUTOFREE(char *) cap_xml =3D NULL; char **ret =3D NULL; VIR_AUTOSTRINGLIST tmp =3D NULL; =20 @@ -956,7 +950,6 @@ virshCellnoCompleter(vshControl *ctl, VIR_STEAL_PTR(ret, tmp); =20 cleanup: - VIR_FREE(cap_xml); return ret; =20 error: --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 07:40:38 2024 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 1554104023966834.583858182705; Mon, 1 Apr 2019 00:33:43 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 619C48667A; Mon, 1 Apr 2019 07:33:42 +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 38A73272A4; Mon, 1 Apr 2019 07:33:42 +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 E8229181A00D; Mon, 1 Apr 2019 07:33:41 +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 x317XcvE013928 for ; Mon, 1 Apr 2019 03:33:38 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7DE0A60FAB; Mon, 1 Apr 2019 07:33:38 +0000 (UTC) Received: from lpt.redhat.com (ovpn-204-90.brq.redhat.com [10.40.204.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id E0C6E60BFC for ; Mon, 1 Apr 2019 07:33:37 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Mon, 1 Apr 2019 09:33:29 +0200 Message-Id: <723653ec7296528dc923196df9ad6b2178dc8831.1554103986.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 12/14] virsh-completer: remove excessive labels 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 01 Apr 2019 07:33:43 +0000 (UTC) Now that we have a shared cleanup section everywhere, delete all the 'error' labels which all contain just 'goto cleanup' anyway. Also remove all the 'cleanup' labels that only 'return ret' - we can simply return NULL instead of jumping to that label. Signed-off-by: J=C3=A1n Tomko --- tools/virsh-completer.c | 207 +++++++++++++--------------------------- 1 file changed, 68 insertions(+), 139 deletions(-) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 025eee19e2..2b9749300a 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -97,13 +97,13 @@ virshDomainNameCompleter(vshControl *ctl, return NULL; =20 if (VIR_ALLOC_N(tmp, ndomains + 1) < 0) - goto error; + goto cleanup; =20 for (i =3D 0; i < ndomains; i++) { const char *name =3D virDomainGetName(domains[i]); =20 if (VIR_STRDUP(tmp[i], name) < 0) - goto error; + goto cleanup; } =20 VIR_STEAL_PTR(ret, tmp); @@ -113,9 +113,6 @@ virshDomainNameCompleter(vshControl *ctl, virshDomainFree(domains[i]); VIR_FREE(domains); return ret; - - error: - goto cleanup; } =20 =20 @@ -143,14 +140,14 @@ virshDomainInterfaceCompleter(vshControl *ctl, domainXMLFlags =3D VIR_DOMAIN_XML_INACTIVE; =20 if (virshDomainGetXML(ctl, cmd, domainXMLFlags, &xmldoc, &ctxt) < 0) - goto cleanup; + return NULL; =20 ninterfaces =3D virXPathNodeSet("./devices/interface", ctxt, &interfac= es); if (ninterfaces < 0) - goto cleanup; + return NULL; =20 if (VIR_ALLOC_N(tmp, ninterfaces + 1) < 0) - goto cleanup; + return NULL; =20 for (i =3D 0; i < ninterfaces; i++) { ctxt->node =3D interfaces[i]; @@ -162,11 +159,10 @@ virshDomainInterfaceCompleter(vshControl *ctl, /* In case we are dealing with inactive domain XML there's no * . Offer MAC addresses then. */ if (!(tmp[i] =3D virXPathString("string(./mac/@address)", ctxt))) - goto cleanup; + return NULL; } =20 VIR_STEAL_PTR(ret, tmp); - cleanup: return ret; } =20 @@ -191,23 +187,22 @@ virshDomainDiskTargetCompleter(vshControl *ctl, return NULL; =20 if (virshDomainGetXML(ctl, cmd, 0, &xmldoc, &ctxt) < 0) - goto cleanup; + return NULL; =20 ndisks =3D virXPathNodeSet("./devices/disk", ctxt, &disks); if (ndisks < 0) - goto cleanup; + return NULL; =20 if (VIR_ALLOC_N(tmp, ndisks + 1) < 0) - goto cleanup; + return NULL; =20 for (i =3D 0; i < ndisks; i++) { ctxt->node =3D disks[i]; if (!(tmp[i] =3D virXPathString("string(./target/@dev)", ctxt))) - goto cleanup; + return NULL; } =20 VIR_STEAL_PTR(ret, tmp); - cleanup: return ret; } =20 @@ -236,13 +231,13 @@ virshStoragePoolNameCompleter(vshControl *ctl, return NULL; =20 if (VIR_ALLOC_N(tmp, npools + 1) < 0) - goto error; + goto cleanup; =20 for (i =3D 0; i < npools; i++) { const char *name =3D virStoragePoolGetName(pools[i]); =20 if (VIR_STRDUP(tmp[i], name) < 0) - goto error; + goto cleanup; } =20 VIR_STEAL_PTR(ret, tmp); @@ -252,9 +247,6 @@ virshStoragePoolNameCompleter(vshControl *ctl, virStoragePoolFree(pools[i]); VIR_FREE(pools); return ret; - - error: - goto cleanup; } =20 =20 @@ -281,17 +273,17 @@ virshStorageVolNameCompleter(vshControl *ctl, return NULL; =20 if ((rc =3D virStoragePoolListAllVolumes(pool, &vols, flags)) < 0) - goto error; + goto cleanup; nvols =3D rc; =20 if (VIR_ALLOC_N(tmp, nvols + 1) < 0) - goto error; + goto cleanup; =20 for (i =3D 0; i < nvols; i++) { const char *name =3D virStorageVolGetName(vols[i]); =20 if (VIR_STRDUP(tmp[i], name) < 0) - goto error; + goto cleanup; } =20 VIR_STEAL_PTR(ret, tmp); @@ -302,9 +294,6 @@ virshStorageVolNameCompleter(vshControl *ctl, virStorageVolFree(vols[i]); VIR_FREE(vols); return ret; - - error: - goto cleanup; } =20 =20 @@ -331,13 +320,13 @@ virshInterfaceNameCompleter(vshControl *ctl, return NULL; =20 if (VIR_ALLOC_N(tmp, nifaces + 1) < 0) - goto error; + goto cleanup; =20 for (i =3D 0; i < nifaces; i++) { const char *name =3D virInterfaceGetName(ifaces[i]); =20 if (VIR_STRDUP(tmp[i], name) < 0) - goto error; + goto cleanup; } =20 VIR_STEAL_PTR(ret, tmp); @@ -347,9 +336,6 @@ virshInterfaceNameCompleter(vshControl *ctl, virInterfaceFree(ifaces[i]); VIR_FREE(ifaces); return ret; - - error: - goto cleanup; } =20 =20 @@ -377,13 +363,13 @@ virshNetworkNameCompleter(vshControl *ctl, return NULL; =20 if (VIR_ALLOC_N(tmp, nnets + 1) < 0) - goto error; + goto cleanup; =20 for (i =3D 0; i < nnets; i++) { const char *name =3D virNetworkGetName(nets[i]); =20 if (VIR_STRDUP(tmp[i], name) < 0) - goto error; + goto cleanup; } =20 VIR_STEAL_PTR(ret, tmp); @@ -393,9 +379,6 @@ virshNetworkNameCompleter(vshControl *ctl, virNetworkFree(nets[i]); VIR_FREE(nets); return ret; - - error: - goto cleanup; } =20 =20 @@ -411,20 +394,17 @@ virshNetworkEventNameCompleter(vshControl *ctl ATTRIB= UTE_UNUSED, virCheckFlags(0, NULL); =20 if (VIR_ALLOC_N(tmp, VIR_NETWORK_EVENT_ID_LAST + 1) < 0) - goto error; + goto cleanup; =20 for (i =3D 0; i < VIR_NETWORK_EVENT_ID_LAST; i++) { if (VIR_STRDUP(tmp[i], virshNetworkEventCallbacks[i].name) < 0) - goto error; + goto cleanup; } =20 VIR_STEAL_PTR(ret, tmp); =20 cleanup: return ret; - - error: - goto cleanup; } =20 =20 @@ -449,13 +429,13 @@ virshNodeDeviceNameCompleter(vshControl *ctl, return NULL; =20 if (VIR_ALLOC_N(tmp, ndevs + 1) < 0) - goto error; + goto cleanup; =20 for (i =3D 0; i < ndevs; i++) { const char *name =3D virNodeDeviceGetName(devs[i]); =20 if (VIR_STRDUP(tmp[i], name) < 0) - goto error; + goto cleanup; } =20 VIR_STEAL_PTR(ret, tmp); @@ -465,9 +445,6 @@ virshNodeDeviceNameCompleter(vshControl *ctl, virNodeDeviceFree(devs[i]); VIR_FREE(devs); return ret; - - error: - goto cleanup; } =20 =20 @@ -492,13 +469,13 @@ virshNWFilterNameCompleter(vshControl *ctl, return NULL; =20 if (VIR_ALLOC_N(tmp, nnwfilters + 1) < 0) - goto error; + goto cleanup; =20 for (i =3D 0; i < nnwfilters; i++) { const char *name =3D virNWFilterGetName(nwfilters[i]); =20 if (VIR_STRDUP(tmp[i], name) < 0) - goto error; + goto cleanup; } =20 VIR_STEAL_PTR(ret, tmp); @@ -508,9 +485,6 @@ virshNWFilterNameCompleter(vshControl *ctl, virNWFilterFree(nwfilters[i]); VIR_FREE(nwfilters); return ret; - - error: - goto cleanup; } =20 =20 @@ -535,13 +509,13 @@ virshNWFilterBindingNameCompleter(vshControl *ctl, return NULL; =20 if (VIR_ALLOC_N(tmp, nbindings + 1) < 0) - goto error; + goto cleanup; =20 for (i =3D 0; i < nbindings; i++) { const char *name =3D virNWFilterBindingGetPortDev(bindings[i]); =20 if (VIR_STRDUP(tmp[i], name) < 0) - goto error; + goto cleanup; } =20 VIR_STEAL_PTR(ret, tmp); @@ -551,9 +525,6 @@ virshNWFilterBindingNameCompleter(vshControl *ctl, virNWFilterBindingFree(bindings[i]); VIR_FREE(bindings); return ret; - - error: - goto cleanup; } =20 =20 @@ -578,14 +549,14 @@ virshSecretUUIDCompleter(vshControl *ctl, return NULL; =20 if (VIR_ALLOC_N(tmp, nsecrets + 1) < 0) - goto error; + goto cleanup; =20 for (i =3D 0; i < nsecrets; i++) { char uuid[VIR_UUID_STRING_BUFLEN]; =20 if (virSecretGetUUIDString(secrets[i], uuid) < 0 || VIR_STRDUP(tmp[i], uuid) < 0) - goto error; + goto cleanup; } =20 VIR_STEAL_PTR(ret, tmp); @@ -595,9 +566,6 @@ virshSecretUUIDCompleter(vshControl *ctl, virSecretFree(secrets[i]); VIR_FREE(secrets); return ret; - - error: - goto cleanup; } =20 =20 @@ -624,17 +592,17 @@ virshSnapshotNameCompleter(vshControl *ctl, return NULL; =20 if ((rc =3D virDomainListAllSnapshots(dom, &snapshots, flags)) < 0) - goto error; + goto cleanup; nsnapshots =3D rc; =20 if (VIR_ALLOC_N(tmp, nsnapshots + 1) < 0) - goto error; + goto cleanup; =20 for (i =3D 0; i < nsnapshots; i++) { const char *name =3D virDomainSnapshotGetName(snapshots[i]); =20 if (VIR_STRDUP(tmp[i], name) < 0) - goto error; + goto cleanup; } =20 VIR_STEAL_PTR(ret, tmp); @@ -645,9 +613,6 @@ virshSnapshotNameCompleter(vshControl *ctl, virshDomainSnapshotFree(snapshots[i]); VIR_FREE(snapshots); return ret; - - error: - goto cleanup; } =20 char ** @@ -676,30 +641,30 @@ virshAllocpagesPagesizeCompleter(vshControl *ctl, virCheckFlags(0, NULL); =20 if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) - goto error; + return NULL; =20 if (!(cap_xml =3D virConnectGetCapabilities(priv->conn))) - goto error; + return NULL; =20 if (!(doc =3D virXMLParseStringCtxt(cap_xml, _("capabilities"), &ctxt)= )) - goto error; + return NULL; =20 if (cellno && vshCommandOptStringQuiet(ctl, cmd, "cellno", &cellnum) >= 0) { if (virAsprintf(&path, "/capabilities/host/topology/cells/cell[@id=3D\"%s= \"]/pages", cellnum) < 0) - goto error; + return NULL; } else { if (virAsprintf(&path, "/capabilities/host/cpu/pages") < 0) - goto error; + return NULL; } =20 npages =3D virXPathNodeSet(path, ctxt, &pages); if (npages <=3D 0) - goto error; + return NULL; =20 if (VIR_ALLOC_N(tmp, npages + 1) < 0) - goto error; + return NULL; =20 for (i =3D 0; i < npages; i++) { VIR_FREE(pagesize); @@ -707,21 +672,16 @@ virshAllocpagesPagesizeCompleter(vshControl *ctl, pagesize =3D virXMLPropString(pages[i], "size"); unit =3D virXMLPropString(pages[i], "unit"); if (virStrToLong_ull(pagesize, NULL, 10, &byteval) < 0) - goto error; + return NULL; if (virScaleInteger(&byteval, unit, 1024, UINT_MAX) < 0) - goto error; + return NULL; size =3D vshPrettyCapacity(byteval, &suffix); if (virAsprintf(&tmp[i], "%.0f%s", size, suffix) < 0) - goto error; + return NULL; } =20 VIR_STEAL_PTR(ret, tmp); - - cleanup: return ret; - - error: - goto cleanup; } =20 =20 @@ -737,20 +697,15 @@ virshSecretEventNameCompleter(vshControl *ctl ATTRIBU= TE_UNUSED, virCheckFlags(0, NULL); =20 if (VIR_ALLOC_N(tmp, VIR_SECRET_EVENT_ID_LAST + 1) < 0) - goto error; + return NULL; =20 for (i =3D 0; i < VIR_SECRET_EVENT_ID_LAST; i++) { if (VIR_STRDUP(tmp[i], virshSecretEventCallbacks[i].name) < 0) - goto error; + return NULL; } =20 VIR_STEAL_PTR(ret, tmp); - - cleanup: return ret; - - error: - goto cleanup; } =20 =20 @@ -766,20 +721,15 @@ virshDomainEventNameCompleter(vshControl *ctl ATTRIBU= TE_UNUSED, virCheckFlags(0, NULL); =20 if (VIR_ALLOC_N(tmp, VIR_DOMAIN_EVENT_ID_LAST + 1) < 0) - goto error; + return NULL; =20 for (i =3D 0; i < VIR_DOMAIN_EVENT_ID_LAST; i++) { if (VIR_STRDUP(tmp[i], virshDomainEventCallbacks[i].name) < 0) - goto error; + return NULL; } =20 VIR_STEAL_PTR(ret, tmp); - - cleanup: return ret; - - error: - goto cleanup; } =20 =20 @@ -795,20 +745,15 @@ virshPoolEventNameCompleter(vshControl *ctl ATTRIBUTE= _UNUSED, virCheckFlags(0, NULL); =20 if (VIR_ALLOC_N(tmp, VIR_STORAGE_POOL_EVENT_ID_LAST + 1) < 0) - goto error; + return NULL; =20 for (i =3D 0; i < VIR_STORAGE_POOL_EVENT_ID_LAST; i++) { if (VIR_STRDUP(tmp[i], virshPoolEventCallbacks[i].name) < 0) - goto error; + return NULL; } =20 VIR_STEAL_PTR(ret, tmp); - - cleanup: return ret; - - error: - goto cleanup; } =20 =20 @@ -836,10 +781,10 @@ virshDomainInterfaceStateCompleter(vshControl *ctl, return NULL; =20 if (virshDomainGetXML(ctl, cmd, flags, &xml, &ctxt) < 0) - goto cleanup; + return NULL; =20 if (vshCommandOptStringReq(ctl, cmd, "interface", &iface) < 0) - goto cleanup; + return NULL; =20 /* normalize the mac addr */ if (virMacAddrParse(iface, &macaddr) =3D=3D 0) @@ -848,35 +793,30 @@ virshDomainInterfaceStateCompleter(vshControl *ctl, if (virAsprintf(&xpath, "/domain/devices/interface[(mac/@address =3D '= %s') or " " (target/@dev =3D '%= s')]", macstr, iface) < 0) - goto cleanup; + return NULL; =20 if ((ninterfaces =3D virXPathNodeSet(xpath, ctxt, &interfaces)) < 0) - goto cleanup; + return NULL; =20 if (ninterfaces !=3D 1) - goto cleanup; + return NULL; =20 ctxt->node =3D interfaces[0]; =20 if (VIR_ALLOC_N(tmp, 2) < 0) - goto error; + return NULL; =20 if ((state =3D virXPathString("string(./link/@state)", ctxt)) && STREQ(state, "down")) { if (VIR_STRDUP(tmp[0], "up") < 0) - goto error; + return NULL; } else { if (VIR_STRDUP(tmp[0], "down") < 0) - goto error; + return NULL; } =20 VIR_STEAL_PTR(ret, tmp); - - cleanup: return ret; - - error: - goto cleanup; } =20 =20 @@ -892,20 +832,15 @@ virshNodedevEventNameCompleter(vshControl *ctl ATTRIB= UTE_UNUSED, virCheckFlags(0, NULL); =20 if (VIR_ALLOC_N(tmp, VIR_NODE_DEVICE_EVENT_ID_LAST + 1) < 0) - goto error; + return NULL; =20 for (i =3D 0; i < VIR_NODE_DEVICE_EVENT_ID_LAST; i++) { if (VIR_STRDUP(tmp[i], virshNodedevEventCallbacks[i].name) < 0) - goto error; + return NULL; } =20 VIR_STEAL_PTR(ret, tmp); - - cleanup: return ret; - - error: - goto cleanup; } =20 =20 @@ -927,33 +862,28 @@ virshCellnoCompleter(vshControl *ctl, virCheckFlags(0, NULL); =20 if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) - goto error; + return NULL; =20 if (!(cap_xml =3D virConnectGetCapabilities(priv->conn))) - goto error; + return NULL; =20 if (!(doc =3D virXMLParseStringCtxt(cap_xml, _("capabilities"), &ctxt)= )) - goto error; + return NULL; =20 ncells =3D virXPathNodeSet("/capabilities/host/topology/cells/cell", c= txt, &cells); if (ncells <=3D 0) - goto error; + return NULL; =20 if (VIR_ALLOC_N(tmp, ncells + 1)) - goto error; + return NULL; =20 for (i =3D 0; i < ncells; i++) { if (!(tmp[i] =3D virXMLPropString(cells[i], "id"))) - goto error; + return NULL; } =20 VIR_STEAL_PTR(ret, tmp); - - cleanup: return ret; - - error: - goto cleanup; } =20 =20 @@ -981,21 +911,20 @@ virshDomainDeviceAliasCompleter(vshControl *ctl, domainXMLFlags =3D VIR_DOMAIN_XML_INACTIVE; =20 if (virshDomainGetXML(ctl, cmd, domainXMLFlags, &xmldoc, &ctxt) < 0) - goto cleanup; + return NULL; =20 naliases =3D virXPathNodeSet("./devices//alias/@name", ctxt, &aliases); if (naliases < 0) - goto cleanup; + return NULL; =20 if (VIR_ALLOC_N(tmp, naliases + 1) < 0) - goto cleanup; + return NULL; =20 for (i =3D 0; i < naliases; i++) { if (!(tmp[i] =3D virXMLNodeContentString(aliases[i]))) - goto cleanup; + return NULL; } =20 VIR_STEAL_PTR(ret, tmp); - cleanup: return ret; } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 07:40:38 2024 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 1554104038796394.65402436626744; Mon, 1 Apr 2019 00:33:58 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B4F4AA5E13; Mon, 1 Apr 2019 07:33:57 +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 8F0E46092F; Mon, 1 Apr 2019 07:33:57 +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 452F4181A850; Mon, 1 Apr 2019 07:33:57 +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 x317Xdcw013938 for ; Mon, 1 Apr 2019 03:33:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8BA6160FAB; Mon, 1 Apr 2019 07:33:39 +0000 (UTC) Received: from lpt.redhat.com (ovpn-204-90.brq.redhat.com [10.40.204.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id E57D260BFC for ; Mon, 1 Apr 2019 07:33:38 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Mon, 1 Apr 2019 09:33:30 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 13/14] virsh-completer: introduce virshPagesizeNodeToString 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-Type: text/plain; charset="utf-8" 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 01 Apr 2019 07:33:58 +0000 (UTC) A helper function that takes a XML node with a "size" and "unit" attributes and converts it into a human-readable string. Reduce the size and number of variables in the parent function. Signed-off-by: J=C3=A1n Tomko --- tools/virsh-completer.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 2b9749300a..5985f09272 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -615,27 +615,44 @@ virshSnapshotNameCompleter(vshControl *ctl, return ret; } =20 +static char * +virshPagesizeNodeToString(xmlNodePtr node) +{ + VIR_AUTOFREE(char *) pagesize =3D NULL; + VIR_AUTOFREE(char *) unit =3D NULL; + unsigned long long byteval =3D 0; + const char *suffix =3D NULL; + double size =3D 0; + char *ret; + + pagesize =3D virXMLPropString(node, "size"); + unit =3D virXMLPropString(node, "unit"); + if (virStrToLong_ull(pagesize, NULL, 10, &byteval) < 0) + return NULL; + if (virScaleInteger(&byteval, unit, 1024, UINT_MAX) < 0) + return NULL; + size =3D vshPrettyCapacity(byteval, &suffix); + if (virAsprintf(&ret, "%.0f%s", size, suffix) < 0) + return NULL; + return ret; +} + char ** virshAllocpagesPagesizeCompleter(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED, unsigned int flags) { - unsigned long long byteval =3D 0; VIR_AUTOPTR(xmlXPathContext) ctxt =3D NULL; virshControlPtr priv =3D ctl->privData; unsigned int npages =3D 0; VIR_AUTOFREE(xmlNodePtr *) pages =3D NULL; VIR_AUTOPTR(xmlDoc) doc =3D NULL; - double size =3D 0; size_t i =3D 0; - const char *suffix =3D NULL; const char *cellnum =3D NULL; bool cellno =3D vshCommandOptBool(cmd, "cellno"); VIR_AUTOFREE(char *) path =3D NULL; - VIR_AUTOFREE(char *) pagesize =3D NULL; VIR_AUTOFREE(char *) cap_xml =3D NULL; char **ret =3D NULL; - VIR_AUTOFREE(char *) unit =3D NULL; VIR_AUTOSTRINGLIST tmp =3D NULL; =20 virCheckFlags(0, NULL); @@ -667,16 +684,7 @@ virshAllocpagesPagesizeCompleter(vshControl *ctl, return NULL; =20 for (i =3D 0; i < npages; i++) { - VIR_FREE(pagesize); - VIR_FREE(unit); - pagesize =3D virXMLPropString(pages[i], "size"); - unit =3D virXMLPropString(pages[i], "unit"); - if (virStrToLong_ull(pagesize, NULL, 10, &byteval) < 0) - return NULL; - if (virScaleInteger(&byteval, unit, 1024, UINT_MAX) < 0) - return NULL; - size =3D vshPrettyCapacity(byteval, &suffix); - if (virAsprintf(&tmp[i], "%.0f%s", size, suffix) < 0) + if (!(tmp[i] =3D virshPagesizeNodeToString(pages[i]))) return NULL; } =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 07:40:38 2024 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 1554104043351214.08051280782342; Mon, 1 Apr 2019 00:34:03 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ACA5081DEB; Mon, 1 Apr 2019 07:34:01 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 75DA06013A; Mon, 1 Apr 2019 07:34:01 +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 355093FA50; Mon, 1 Apr 2019 07:34:01 +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 x317Xeob013951 for ; Mon, 1 Apr 2019 03:33:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8EDAC60BFC; Mon, 1 Apr 2019 07:33:40 +0000 (UTC) Received: from lpt.redhat.com (ovpn-204-90.brq.redhat.com [10.40.204.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id EB83F60BE6 for ; Mon, 1 Apr 2019 07:33:39 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Mon, 1 Apr 2019 09:33:31 +0200 Message-Id: <20d7d20adc05e7d58579901d560402da68e5a2ae.1554103986.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 14/14] virsh-completer: introduce virshPasswordCompleter 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-Type: text/plain; charset="utf-8" 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 01 Apr 2019 07:34:02 +0000 (UTC) Suggest some passwords to the user. Signed-off-by: J=C3=A1n Tomko --- tools/virsh-completer.c | 58 +++++++++++++++++++++++++++++++++++++++++ tools/virsh-completer.h | 4 +++ tools/virsh-domain.c | 1 + 3 files changed, 63 insertions(+) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 5985f09272..0687670d37 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -32,6 +32,7 @@ #include "virutil.h" #include "viralloc.h" #include "virmacaddr.h" +#include "virrandom.h" #include "virstring.h" #include "virxml.h" =20 @@ -936,3 +937,60 @@ virshDomainDeviceAliasCompleter(vshControl *ctl, VIR_STEAL_PTR(ret, tmp); return ret; } + + +const char *builtin_passwords[] =3D { + "hunter2", /* ******* */ + "nbusr123", /* Ke=C4=8F nevie=C5=A1, tak nefu=C5=A1uj */ + "4ezgi4", +}; + + +char ** +virshPasswordCompleter(vshControl *ctl ATTRIBUTE_UNUSED, + const vshCmd *cmd ATTRIBUTE_UNUSED, + unsigned int flags) +{ + VIR_AUTOFREE(char *) base64 =3D NULL; + VIR_AUTOFREE(unsigned char *) rand =3D NULL; + VIR_AUTOSTRINGLIST tmp =3D NULL; + const size_t optimal_passlen =3D 8; /* ought to be enough */ + const char *prefix =3D NULL; + const size_t num =3D 1; + char **ret =3D NULL; + size_t missing; + size_t i; + + virCheckFlags(0, NULL); + + if (VIR_ALLOC_N(tmp, num + ARRAY_CARDINALITY(builtin_passwords) + 1) <= 0) + return NULL; + + ignore_value(vshCommandOptStringQuiet(ctl, cmd, "password", &prefix)); + if (STREQ_NULLABLE(prefix, " ")) + prefix =3D NULL; + + missing =3D optimal_passlen - MIN(strlen(NULLSTR_EMPTY(prefix)), optim= al_passlen); + + if (VIR_ALLOC_N(rand, 7) < 0) + return NULL; + + if (virRandomBytes(rand, 6) < 0) + return NULL; + + if (!(base64 =3D virStringEncodeBase64(rand, 6))) + return NULL; + + base64[missing] =3D '\0'; + + if (virAsprintf(&tmp[0], "%s%s", NULLSTR_EMPTY(prefix), base64) < 0) + return NULL; + + for (i =3D 0; i < ARRAY_CARDINALITY(builtin_passwords); i++) { + if (VIR_STRDUP(tmp[i + 1], builtin_passwords[i]) < 0) + return NULL; + } + + VIR_STEAL_PTR(ret, tmp); + return ret; +} diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index 2e2e1edafb..d47a5f4da6 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -110,4 +110,8 @@ char ** virshDomainDeviceAliasCompleter(vshControl *ctl, char ** virshCellnoCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); + +char ** virshPasswordCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); #endif /* LIBVIRT_VIRSH_COMPLETER_H */ diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index e8d5404acf..d8978f5bd1 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -5732,6 +5732,7 @@ static const vshCmdOptDef opts_set_user_password[] = =3D { {.name =3D "password", .type =3D VSH_OT_DATA, .flags =3D VSH_OFLAG_REQ, + .completer =3D virshPasswordCompleter, .help =3D N_("the new password") }, {.name =3D "encrypted", --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list