From nobody Mon Apr 29 05:21:32 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 1526906871719674.9860396999002; Mon, 21 May 2018 05:47:51 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C85F2C106561; Mon, 21 May 2018 12:47:49 +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 22CA530B778B; Mon, 21 May 2018 12:47:49 +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 2A3F11801242; Mon, 21 May 2018 12:47:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4LCljDJ029288 for ; Mon, 21 May 2018 08:47:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8D187215CDAA; Mon, 21 May 2018 12:47:45 +0000 (UTC) Received: from caroline (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6BB69215CDA7 for ; Mon, 21 May 2018 12:47:45 +0000 (UTC) Received: from caroline.brq.redhat.com (caroline.usersys.redhat.com [127.0.0.1]) by caroline (Postfix) with ESMTP id 6C58412001E for ; Mon, 21 May 2018 14:47:44 +0200 (CEST) From: Martin Kletzander To: libvir-list@redhat.com Date: Mon, 21 May 2018 14:47:41 +0200 Message-Id: <445e38374d2f031b9f5a677c40f6cd7ffb2f39e3.1526906861.git.mkletzan@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] tools: Tiny clean-ups for two functions in virsh-completer.c 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: , MIME-Version: 1.0 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.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 21 May 2018 12:47:50 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" These two functions were duplicating some cleanup paths, so let's just merge both cleanup and error paths together. To distinguish whether we need to clean-up the return value let's keep it in @tmp until the function is succe= ssful in which case we set @ret to the value of @tmp and set @tmp to NULL. Signed-off-by: Martin Kletzander Reviewed-by: J=EF=BF=BDn Tomko --- tools/virsh-completer.c | 48 ++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index eb091070c92b..1f9f8e76e90e 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -97,6 +97,7 @@ virshDomainInterfaceCompleter(vshControl *ctl, size_t i; unsigned int domainXMLFlags =3D 0; char **ret =3D NULL; + char **tmp =3D NULL; =20 virCheckFlags(VIRSH_DOMAIN_INTERFACE_COMPLETER_MAC, NULL); =20 @@ -107,39 +108,35 @@ virshDomainInterfaceCompleter(vshControl *ctl, domainXMLFlags =3D VIR_DOMAIN_XML_INACTIVE; =20 if (virshDomainGetXML(ctl, cmd, domainXMLFlags, &xmldoc, &ctxt) < 0) - goto error; + goto cleanup; =20 ninterfaces =3D virXPathNodeSet("./devices/interface", ctxt, &interfac= es); if (ninterfaces < 0) - goto error; + goto cleanup; =20 - if (VIR_ALLOC_N(ret, ninterfaces + 1) < 0) - goto error; + if (VIR_ALLOC_N(tmp, ninterfaces + 1) < 0) + goto cleanup; =20 for (i =3D 0; i < ninterfaces; i++) { ctxt->node =3D interfaces[i]; =20 if (!(flags & VIRSH_DOMAIN_INTERFACE_COMPLETER_MAC) && - (ret[i] =3D virXPathString("string(./target/@dev)", ctxt))) + (tmp[i] =3D virXPathString("string(./target/@dev)", ctxt))) continue; =20 /* In case we are dealing with inactive domain XML there's no * . Offer MAC addresses then. */ - if (!(ret[i] =3D virXPathString("string(./mac/@address)", ctxt))) - goto error; + if (!(tmp[i] =3D virXPathString("string(./mac/@address)", ctxt))) + goto cleanup; } =20 + VIR_STEAL_PTR(ret, tmp); + cleanup: VIR_FREE(interfaces); xmlFreeDoc(xmldoc); xmlXPathFreeContext(ctxt); + virStringListFree(tmp); return ret; - - error: - VIR_FREE(interfaces); - xmlFreeDoc(xmldoc); - xmlXPathFreeContext(ctxt); - virStringListFree(ret); - return NULL; } =20 =20 @@ -154,6 +151,7 @@ virshDomainDiskTargetCompleter(vshControl *ctl, xmlNodePtr *disks =3D NULL; int ndisks; size_t i; + char **tmp =3D NULL; char **ret =3D NULL; =20 virCheckFlags(0, NULL); @@ -162,32 +160,28 @@ virshDomainDiskTargetCompleter(vshControl *ctl, return NULL; =20 if (virshDomainGetXML(ctl, cmd, 0, &xmldoc, &ctxt) < 0) - goto error; + goto cleanup; =20 ndisks =3D virXPathNodeSet("./devices/disk", ctxt, &disks); if (ndisks < 0) - goto error; + goto cleanup; =20 - if (VIR_ALLOC_N(ret, ndisks + 1) < 0) - goto error; + if (VIR_ALLOC_N(tmp, ndisks + 1) < 0) + goto cleanup; =20 for (i =3D 0; i < ndisks; i++) { ctxt->node =3D disks[i]; - if (!(ret[i] =3D virXPathString("string(./target/@dev)", ctxt))) - goto error; + if (!(tmp[i] =3D virXPathString("string(./target/@dev)", ctxt))) + goto cleanup; } =20 + VIR_STEAL_PTR(ret, tmp); + cleanup: VIR_FREE(disks); xmlFreeDoc(xmldoc); xmlXPathFreeContext(ctxt); + virStringListFree(tmp); return ret; - - error: - VIR_FREE(disks); - xmlFreeDoc(xmldoc); - xmlXPathFreeContext(ctxt); - virStringListFree(ret); - return NULL; } =20 =20 --=20 2.17.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list