From nobody Wed May 14 11:58:49 2025 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 1523033640723207.3472465729643; Fri, 6 Apr 2018 09:54:00 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 662144E90B; Fri, 6 Apr 2018 16:53:59 +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 3AF9160BF2; Fri, 6 Apr 2018 16:53:59 +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 F1208180596F; Fri, 6 Apr 2018 16:53:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w36GrlRi009127 for ; Fri, 6 Apr 2018 12:53:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id 56E9F5D6A6; Fri, 6 Apr 2018 16:53:47 +0000 (UTC) Received: from unknown54ee7586bd10.attlocal.net.com (ovpn-116-52.phx2.redhat.com [10.3.116.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id 18CCD5D6A5 for ; Fri, 6 Apr 2018 16:53:46 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Fri, 6 Apr 2018 12:53:39 -0400 Message-Id: <20180406165340.7473-4-jferlan@redhat.com> In-Reply-To: <20180406165340.7473-1-jferlan@redhat.com> References: <20180406165340.7473-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/4] conf: Convert virDomainChrSourceDefNew to return object 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 06 Apr 2018 16:53:59 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Let's use object referencing to handle the ChrSourceDef. A subsequent patch then can allow the monConfig to take an extra reference before dropping the domain lock to then ensure nothing free's the memory that needs to be used. Signed-off-by: John Ferlan --- src/conf/domain_conf.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index fd57364cd4..b4c5de8b33 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2260,8 +2260,10 @@ virDomainChrSourceDefCopy(virDomainChrSourceDefPtr d= est, return 0; } =20 -void virDomainChrSourceDefFree(virDomainChrSourceDefPtr def) +static void +virDomainChrSourceDefDispose(void *obj) { + virDomainChrSourceDefPtr def =3D obj; size_t i; =20 if (!def) @@ -2275,11 +2277,16 @@ void virDomainChrSourceDefFree(virDomainChrSourceDe= fPtr def) virSecurityDeviceLabelDefFree(def->seclabels[i]); VIR_FREE(def->seclabels); } +} =20 =20 - VIR_FREE(def); +void +virDomainChrSourceDefFree(virDomainChrSourceDefPtr def) +{ + virObjectUnref(def); } =20 + /* virDomainChrSourceDefIsEqual: * @src: Source * @tgt: Target @@ -12211,12 +12218,32 @@ virDomainChrSourceDefParseXML(virDomainChrSourceD= efPtr def, } =20 =20 +static virClassPtr virDomainChrSourceDefClass; + +static int +virDomainChrSourceDefOnceInit(void) +{ + virDomainChrSourceDefClass =3D virClassNew(virClassForObject(), + "virDomainChrSourceDef", + sizeof(virDomainChrSourceDef), + virDomainChrSourceDefDispose); + if (!virDomainChrSourceDefClass) + return -1; + else + return 0; +} + +VIR_ONCE_GLOBAL_INIT(virDomainChrSourceDef); + virDomainChrSourceDefPtr virDomainChrSourceDefNew(virDomainXMLOptionPtr xmlopt) { virDomainChrSourceDefPtr def =3D NULL; =20 - if (VIR_ALLOC(def) < 0) + if (virDomainChrSourceDefInitialize() < 0) + return NULL; + + if (!(def =3D virObjectNew(virDomainChrSourceDefClass))) return NULL; =20 if (xmlopt && xmlopt->privateData.chrSourceNew && --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list