From nobody Sun Feb 8 21:33:25 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 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