From nobody Mon Feb 9 07:54:43 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.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1493056877335518.8180912634444; Mon, 24 Apr 2017 11:01:17 -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 240F413BF70; Mon, 24 Apr 2017 18:01:15 +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 681CE823CE; Mon, 24 Apr 2017 18:01:14 +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 55E9818523D3; Mon, 24 Apr 2017 18:00:59 +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 v3OI0qrr004810 for ; Mon, 24 Apr 2017 14:00:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0E0D77E2C9; Mon, 24 Apr 2017 18:00:52 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-126-74.rdu2.redhat.com [10.10.126.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id B4F5677ED1 for ; Mon, 24 Apr 2017 18:00:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 240F413BF70 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 240F413BF70 From: John Ferlan To: libvir-list@redhat.com Date: Mon, 24 Apr 2017 14:00:23 -0400 Message-Id: <20170424180023.4695-15-jferlan@redhat.com> In-Reply-To: <20170424180023.4695-1-jferlan@redhat.com> References: <20170424180023.4695-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 14/14] secret: Clean up virSecretObjListExport logic 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.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.38]); Mon, 24 Apr 2017 18:01:16 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Shorten the time needed to keep the list lock and alter the cleanup path to be more of an error path. Utilize the the virObjectListFree function to handle the calls for virObjectUnref on each list element and the VIR_FREE of the list instead of open coding it. Change the name of the virHashForEach callback to match the name of the Export function with the Callback added onto it. Signed-off-by: John Ferlan --- src/conf/virsecretobj.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c index 7a9908d..caed156 100644 --- a/src/conf/virsecretobj.c +++ b/src/conf/virsecretobj.c @@ -550,9 +550,9 @@ struct virSecretObjListData { }; =20 static int -virSecretObjListPopulate(void *payload, - const void *name ATTRIBUTE_UNUSED, - void *opaque) +virSecretObjListExportCallback(void *payload, + const void *name ATTRIBUTE_UNUSED, + void *opaque) { struct virSecretObjListData *data =3D opaque; virSecretObjPtr obj =3D payload; @@ -598,7 +598,6 @@ virSecretObjListExport(virConnectPtr conn, virSecretObjListACLFilter aclfilter, unsigned int flags) { - int ret =3D -1; struct virSecretObjListData data =3D { .conn =3D conn, .secrets =3D NULL, .aclfilter =3D aclfilter, .flags =3D flags, @@ -606,30 +605,28 @@ virSecretObjListExport(virConnectPtr conn, =20 virObjectLock(secretobjs); if (secrets && - VIR_ALLOC_N(data.secrets, virHashSize(secretobjs->objs) + 1) < 0) - goto cleanup; + VIR_ALLOC_N(data.secrets, virHashSize(secretobjs->objs) + 1) < 0) { + virObjectUnlock(secretobjs); + return -1; + } =20 - virHashForEach(secretobjs->objs, virSecretObjListPopulate, &data); + virHashForEach(secretobjs->objs, virSecretObjListExportCallback, &data= ); + virObjectUnlock(secretobjs); =20 if (data.error) - goto cleanup; + goto error; =20 if (data.secrets) { /* trim the array to the final size */ ignore_value(VIR_REALLOC_N(data.secrets, data.nsecrets + 1)); *secrets =3D data.secrets; - data.secrets =3D NULL; } =20 - ret =3D data.nsecrets; + return data.nsecrets; =20 - cleanup: - virObjectUnlock(secretobjs); - while (data.secrets && data.nsecrets) - virObjectUnref(data.secrets[--data.nsecrets]); - - VIR_FREE(data.secrets); - return ret; + error: + virObjectListFree(data.secrets); + return -1; } =20 =20 --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list