From nobody Mon Feb 9 11:32:17 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 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