From nobody Tue Apr 30 21:34:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1588868623; cv=none; d=zohomail.com; s=zohoarc; b=ZvLgN+vtKtBZwz3JVrCNhTMWq9YnOMR1LAERo+59k7/7MWwNQWkSmWflMUKV0s67HlDTxXDBLw2P8BFrE1sfM1LHYXZGOz0AdF+qN1VyJm8KO6DALwe9BAVeMkEsrDF09r89GAJPPz82I+/qS0ZlbvBeXuu1degYv5EMX7FH2VM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588868623; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=tNuwmg0etaBwe8Kj4/Uzkx50iD3BIM3jorjGsiUs0ZU=; b=Fy1QK+OlRw/suY7YDrNUilWwEpknMEdHD3PxTiepsv1FXT50Cj5NYTvPlW9ysY1n+9oxqQh895YKUO7p6lZE0OHgVH+/QDe2YyWV2vvCvDNozNCLC0TUmrzPeHz2/FEIkEO88vqhSVCgAVoUrepN1hqOG8VOrB/mpv3ERX19Kks= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1588868623415855.1285460716468; Thu, 7 May 2020 09:23:43 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-22-0Xc7ptHLP0WNKONlweDoAA-1; Thu, 07 May 2020 12:23:39 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6AD011800D4A; Thu, 7 May 2020 16:23:33 +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 418E95C1B0; Thu, 7 May 2020 16:23:33 +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 ECE414CAA7; Thu, 7 May 2020 16:23:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 047GNUMO006181 for ; Thu, 7 May 2020 12:23:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1A34A20A8DCE; Thu, 7 May 2020 16:23:30 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 15DD9202683D for ; Thu, 7 May 2020 16:23:27 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3977E800182 for ; Thu, 7 May 2020 16:23:27 +0000 (UTC) Received: from regular1.263xmail.com (regular1.263xmail.com [211.150.70.204]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-492-cET9Ha79O_SRbUqHUF1gQg-1; Thu, 07 May 2020 12:23:21 -0400 Received: from localhost (unknown [192.168.167.235]) by regular1.263xmail.com (Postfix) with ESMTP id 0FEED246 for ; Fri, 8 May 2020 00:23:15 +0800 (CST) Received: from localhost.localdomain (unknown [14.18.236.69]) by smtp.263.net (postfix) whith ESMTP id P2323T140090414196480S1588868591753723_; Fri, 08 May 2020 00:23:15 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588868622; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=tNuwmg0etaBwe8Kj4/Uzkx50iD3BIM3jorjGsiUs0ZU=; b=S0oFBWDFDDKSyb4V6Qpd+CTw7yn/txQm3HzpZwPH/EMhnnmRONnRUvlPo6J8sbrP/+35mW kKpcLCRAbqzMAip4MJT6fXBieFS177ZZAhqvu0b/fik7QGtGVf1X2PBNTN0si+nPXLIDT1 CeBR1JGnWeTk/BDoinYjoPgz2T9vlmE= X-MC-Unique: 0Xc7ptHLP0WNKONlweDoAA-1 X-MC-Unique: cET9Ha79O_SRbUqHUF1gQg-1 X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-ADDR-CHECKED4: 1 X-ANTISPAM-LEVEL: 2 X-SKE-CHECKED: 1 X-ABS-CHECKED: 1 X-IP-DOMAINF: 1 X-UNIQUE-TAG: X-RL-SENDER: yili@winhong.com X-SENDER: yili@winhong.com X-LOGIN-NAME: yili@winhong.com X-FST-TO: pkrempa@redhat.com X-SENDER-IP: 14.18.236.69 X-ATTACHMENT-NUM: 0 X-DNS-TYPE: 0 X-System-Flag: 0 From: Yi Li To: pkrempa@redhat.com Subject: [PATCH v2] Unlock the storage pool objects after looking it up Date: Fri, 8 May 2020 00:23:09 +0800 Message-Id: <20200507162309.3305467-1-yili@winhong.com> In-Reply-To: <20200507104855.2868736-1-yili@winhong.com> References: <20200507104855.2868736-1-yili@winhong.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 047GNUMO006181 X-loop: libvir-list@redhat.com Cc: libvir-list@redhat.com, yilikernel@gmail.com, yili@winhong.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Use g_new0 to allocate and remove NULL checks from callers and the lock will release properly Signed-off-by: Yi Li Reviewed-by: Michal Privoznik --- src/conf/virstorageobj.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index 13b75b648d..f3c54d0c52 100644 --- a/src/conf/virstorageobj.c +++ b/src/conf/virstorageobj.c @@ -1036,10 +1036,7 @@ virStoragePoolObjVolumeListExport(virConnectPtr conn, return ret; } =20 - if (VIR_ALLOC_N(data.vols, virHashSize(volumes->objsName) + 1) < 0) { - virObjectRWUnlock(volumes); - return -1; - } + data.vols =3D g_new0(virStorageVolPtr, virHashSize(volumes->objsName) = + 1); =20 virHashForEach(volumes->objsName, virStoragePoolObjVolumeListExportCal= lback, &data); virObjectRWUnlock(volumes); @@ -2077,8 +2074,13 @@ virStoragePoolObjListExport(virConnectPtr conn, =20 virObjectRWLockRead(poolobjs); =20 - if (pools && VIR_ALLOC_N(data.pools, virHashSize(poolobjs->objs) + 1) = < 0) - goto error; + if (!pools) { + int ret =3D virHashSize(poolobjs->objs); + virObjectRWUnlock(poolobjs); + return ret; + } + + data.pools =3D g_new0(virStoragePoolPtr, virHashSize(poolobjs->objs) += 1); =20 virHashForEach(poolobjs->objs, virStoragePoolObjListExportCallback, &d= ata); virObjectRWUnlock(poolobjs); --=20 2.25.3