From nobody Wed May 1 23:09:08 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 ARC-Seal: i=1; a=rsa-sha256; t=1568636245; cv=none; d=zoho.com; s=zohoarc; b=MAk6T6OCPBmYhe5FntYzpyec96D7o6HRFRKnSBKkp6+qUOJ+dA8BY4iTxo69yeo1/GPycODh71M/ssF6FZD/QfViBTWfFIImv4Npr/o6xfo3kV3GPqJxj7/axQufBNf3rxoCASV2pWhWwKcpJZP7yApuZBI6HZJwQsY9O3Y3PRw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568636245; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=2Yeuh0Zk4+YiPBENOwShpPcTcXWE1kM3m75rUMjacro=; b=PR78k4e568QJ/MUWPL3Nf1QZRkvZLKmCS3fgRk6KSWyuhLgS7o4/Ea+Jd1rVdSFZXsZ9Ynppg+aCH2VtWYtmELzleymhzGRF56xEai8rWnBzKjMpc73MukxAX3f+noxRsvwsmQqQL+94/A7w8vrUOmsgBEHMM/cfi8AsN0Df/+w= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568636245541273.03852763040175; Mon, 16 Sep 2019 05:17:25 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CEC2B88383B; Mon, 16 Sep 2019 12:17:23 +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 63BC8100EBA2; Mon, 16 Sep 2019 12:17:23 +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 6666E180B536; Mon, 16 Sep 2019 12:17:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8GCHK6g024490 for ; Mon, 16 Sep 2019 08:17:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8287F196AE; Mon, 16 Sep 2019 12:17:20 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0A77FA20C for ; Mon, 16 Sep 2019 12:17:19 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Mon, 16 Sep 2019 14:17:04 +0200 Message-Id: <778d3e675eb92479e01e74a5fe35402b499f0bb3.1568636165.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/9] util: xml: Add wrapper for xmlXPathNewContext 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-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.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.69]); Mon, 16 Sep 2019 12:17:24 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The wrapper reports libvirt errors for the libxml2 function so that the same does not have to be repeated over and over. Signed-off-by: Peter Krempa Reviewed-by: Jiri Denemark --- src/conf/checkpoint_conf.c | 5 +---- src/conf/domain_conf.c | 9 ++------- src/conf/interface_conf.c | 5 +---- src/conf/network_conf.c | 5 +---- src/conf/node_device_conf.c | 5 +---- src/conf/nwfilter_conf.c | 5 +---- src/conf/secret_conf.c | 6 ++---- src/conf/snapshot_conf.c | 5 +---- src/conf/storage_conf.c | 10 ++-------- src/conf/virnetworkportdef.c | 5 +---- src/conf/virnwfilterbindingdef.c | 5 +---- src/conf/virnwfilterbindingobj.c | 5 +---- src/libvirt_private.syms | 1 + src/qemu/qemu_capabilities.c | 4 +--- src/util/virxml.c | 20 ++++++++++++++++---- src/util/virxml.h | 3 +++ src/vbox/vbox_snapshot_conf.c | 17 ++++++++--------- src/vz/vz_sdk.c | 6 ++---- 18 files changed, 46 insertions(+), 75 deletions(-) diff --git a/src/conf/checkpoint_conf.c b/src/conf/checkpoint_conf.c index a3513aaa65..113d85cc14 100644 --- a/src/conf/checkpoint_conf.c +++ b/src/conf/checkpoint_conf.c @@ -227,11 +227,8 @@ virDomainCheckpointDefParseNode(xmlDocPtr xml, if (virXMLValidateAgainstSchema(schema, xml) < 0) return NULL; - ctxt =3D xmlXPathNewContext(xml); - if (ctxt =3D=3D NULL) { - virReportOOMError(); + if (!(ctxt =3D virXMLXPathContextNew(xml))) goto cleanup; - } ctxt->node =3D root; def =3D virDomainCheckpointDefParse(ctxt, caps, xmlopt, parseOpaque, f= lags); diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 848c831330..e5e3f31f76 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -21575,11 +21575,8 @@ virDomainDefParseNode(xmlDocPtr xml, virDomainDefPtr def =3D NULL; virDomainDefPtr ret =3D NULL; - ctxt =3D xmlXPathNewContext(xml); - if (ctxt =3D=3D NULL) { - virReportOOMError(); + if (!(ctxt =3D virXMLXPathContextNew(xml))) goto cleanup; - } ctxt->node =3D root; @@ -21621,10 +21618,8 @@ virDomainObjParseNode(xmlDocPtr xml, goto cleanup; } - if (!(ctxt =3D xmlXPathNewContext(xml))) { - virReportOOMError(); + if (!(ctxt =3D virXMLXPathContextNew(xml))) goto cleanup; - } ctxt->node =3D root; obj =3D virDomainObjParseXML(xml, ctxt, caps, xmlopt, flags); diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c index b134ff4adc..64729aea43 100644 --- a/src/conf/interface_conf.c +++ b/src/conf/interface_conf.c @@ -830,11 +830,8 @@ virInterfaceDefParseNode(xmlDocPtr xml, return NULL; } - ctxt =3D xmlXPathNewContext(xml); - if (ctxt =3D=3D NULL) { - virReportOOMError(); + if (!(ctxt =3D virXMLXPathContextNew(xml))) goto cleanup; - } ctxt->node =3D root; def =3D virInterfaceDefParseXML(ctxt, VIR_INTERFACE_TYPE_LAST); diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index aa0d48af8f..585c87a9f4 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -2125,11 +2125,8 @@ virNetworkDefParseNode(xmlDocPtr xml, return NULL; } - ctxt =3D xmlXPathNewContext(xml); - if (ctxt =3D=3D NULL) { - virReportOOMError(); + if (!(ctxt =3D virXMLXPathContextNew(xml))) goto cleanup; - } ctxt->node =3D root; def =3D virNetworkDefParseXML(ctxt, xmlopt); diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 618ce8e00e..8f8830aef1 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -2063,11 +2063,8 @@ virNodeDeviceDefParseNode(xmlDocPtr xml, return NULL; } - ctxt =3D xmlXPathNewContext(xml); - if (ctxt =3D=3D NULL) { - virReportOOMError(); + if (!(ctxt =3D virXMLXPathContextNew(xml))) goto cleanup; - } ctxt->node =3D root; def =3D virNodeDeviceDefParseXML(ctxt, create, virt_type); diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c index cecee51d87..21885eb7ae 100644 --- a/src/conf/nwfilter_conf.c +++ b/src/conf/nwfilter_conf.c @@ -2756,11 +2756,8 @@ virNWFilterDefParseNode(xmlDocPtr xml, goto cleanup; } - ctxt =3D xmlXPathNewContext(xml); - if (ctxt =3D=3D NULL) { - virReportOOMError(); + if (!(ctxt =3D virXMLXPathContextNew(xml))) goto cleanup; - } ctxt->node =3D root; def =3D virNWFilterDefParseXML(ctxt); diff --git a/src/conf/secret_conf.c b/src/conf/secret_conf.c index b291339e77..a7691da7b5 100644 --- a/src/conf/secret_conf.c +++ b/src/conf/secret_conf.c @@ -144,11 +144,9 @@ secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root) goto cleanup; } - ctxt =3D xmlXPathNewContext(xml); - if (ctxt =3D=3D NULL) { - virReportOOMError(); + if (!(ctxt =3D virXMLXPathContextNew(xml))) goto cleanup; - } + ctxt->node =3D root; if (VIR_ALLOC(def) < 0) diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index cce9a7999c..8cf80aed83 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -450,11 +450,8 @@ virDomainSnapshotDefParseNode(xmlDocPtr xml, goto cleanup; } - ctxt =3D xmlXPathNewContext(xml); - if (ctxt =3D=3D NULL) { - virReportOOMError(); + if (!(ctxt =3D virXMLXPathContextNew(xml))) goto cleanup; - } ctxt->node =3D root; def =3D virDomainSnapshotDefParse(ctxt, caps, xmlopt, parseOpaque, cur= rent, flags); diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 024f047fab..0560994281 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -1024,11 +1024,8 @@ virStoragePoolDefParseNode(xmlDocPtr xml, goto cleanup; } - ctxt =3D xmlXPathNewContext(xml); - if (ctxt =3D=3D NULL) { - virReportOOMError(); + if (!(ctxt =3D virXMLXPathContextNew(xml))) goto cleanup; - } ctxt->node =3D root; def =3D virStoragePoolDefParseXML(ctxt); @@ -1468,11 +1465,8 @@ virStorageVolDefParseNode(virStoragePoolDefPtr pool, goto cleanup; } - ctxt =3D xmlXPathNewContext(xml); - if (ctxt =3D=3D NULL) { - virReportOOMError(); + if (!(ctxt =3D virXMLXPathContextNew(xml))) goto cleanup; - } ctxt->node =3D root; def =3D virStorageVolDefParseXML(pool, ctxt, flags); diff --git a/src/conf/virnetworkportdef.c b/src/conf/virnetworkportdef.c index 29ecf5b178..2e20bff66e 100644 --- a/src/conf/virnetworkportdef.c +++ b/src/conf/virnetworkportdef.c @@ -277,11 +277,8 @@ virNetworkPortDefParseNode(xmlDocPtr xml, goto cleanup; } - ctxt =3D xmlXPathNewContext(xml); - if (ctxt =3D=3D NULL) { - virReportOOMError(); + if (!(ctxt =3D virXMLXPathContextNew(xml))) goto cleanup; - } ctxt->node =3D root; def =3D virNetworkPortDefParseXML(ctxt); diff --git a/src/conf/virnwfilterbindingdef.c b/src/conf/virnwfilterbinding= def.c index facca61833..6f13bc581a 100644 --- a/src/conf/virnwfilterbindingdef.c +++ b/src/conf/virnwfilterbindingdef.c @@ -182,11 +182,8 @@ virNWFilterBindingDefParseNode(xmlDocPtr xml, goto cleanup; } - ctxt =3D xmlXPathNewContext(xml); - if (ctxt =3D=3D NULL) { - virReportOOMError(); + if (!(ctxt =3D virXMLXPathContextNew(xml))) goto cleanup; - } ctxt->node =3D root; def =3D virNWFilterBindingDefParseXML(ctxt); diff --git a/src/conf/virnwfilterbindingobj.c b/src/conf/virnwfilterbinding= obj.c index 68afb9c434..06dd66a5d1 100644 --- a/src/conf/virnwfilterbindingobj.c +++ b/src/conf/virnwfilterbindingobj.c @@ -248,11 +248,8 @@ virNWFilterBindingObjParseNode(xmlDocPtr doc, goto cleanup; } - ctxt =3D xmlXPathNewContext(doc); - if (ctxt =3D=3D NULL) { - virReportOOMError(); + if (!(ctxt =3D virXMLXPathContextNew(doc))) goto cleanup; - } ctxt->node =3D root; obj =3D virNWFilterBindingObjParseXML(doc, ctxt); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 4865edaf59..cd880d2c43 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3366,6 +3366,7 @@ virXMLValidateAgainstSchema; virXMLValidatorFree; virXMLValidatorInit; virXMLValidatorValidate; +virXMLXPathContextNew; virXPathBoolean; virXPathContextNodeRestore; virXPathInt; diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 9b19930964..01d3b008f0 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -3612,10 +3612,8 @@ virQEMUCapsLoadCache(virArch hostArch, if (!(doc =3D virXMLParseFile(filename))) goto cleanup; - if (!(ctxt =3D xmlXPathNewContext(doc))) { - virReportOOMError(); + if (!(ctxt =3D virXMLXPathContextNew(doc))) goto cleanup; - } ctxt->node =3D xmlDocGetRootElement(doc); diff --git a/src/util/virxml.c b/src/util/virxml.c index f9c117dd58..245ca0a752 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -46,6 +46,20 @@ struct virParserData { }; +xmlXPathContextPtr +virXMLXPathContextNew(xmlDocPtr xml) +{ + xmlXPathContextPtr ctxt; + + if (!(ctxt =3D xmlXPathNewContext(xml))) { + virReportOOMError(); + return NULL; + } + + return ctxt; +} + + /** * virXPathString: * @xpath: the XPath string to evaluate @@ -824,11 +838,9 @@ virXMLParseHelper(int domcode, } if (ctxt) { - *ctxt =3D xmlXPathNewContext(xml); - if (!*ctxt) { - virReportOOMError(); + if (!(*ctxt =3D virXMLXPathContextNew(xml))) goto error; - } + (*ctxt)->node =3D xmlDocGetRootElement(xml); } diff --git a/src/util/virxml.h b/src/util/virxml.h index 30cc895436..39e5a988a2 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -30,6 +30,9 @@ #include "virbuffer.h" #include "virautoclean.h" +xmlXPathContextPtr virXMLXPathContextNew(xmlDocPtr xml) + ATTRIBUTE_RETURN_CHECK; + int virXPathBoolean(const char *xpath, xmlXPathContextPtr ctxt); char * virXPathString(const char *xpath, diff --git a/src/vbox/vbox_snapshot_conf.c b/src/vbox/vbox_snapshot_conf.c index a36da30a4f..a6daf0ffcf 100644 --- a/src/vbox/vbox_snapshot_conf.c +++ b/src/vbox/vbox_snapshot_conf.c @@ -615,10 +615,9 @@ virVBoxSnapshotConfLoadVboxFile(const char *filePath, _("Unable to parse the xml")); goto cleanup; } - if (!(xPathContext =3D xmlXPathNewContext(xml))) { - virReportOOMError(); + if (!(xPathContext =3D virXMLXPathContextNew(xml))) goto cleanup; - } + if (xmlXPathRegisterNs(xPathContext, BAD_CAST "vbox", BAD_CAST "http://www.innotek.de/VirtualBox-sett= ings") < 0) { @@ -1299,10 +1298,10 @@ virVBoxSnapshotConfGetRWDisksPathsFromLibvirtXML(co= nst char *filePath, _("Unable to parse the xml")); goto cleanup; } - if (!(xPathContext =3D xmlXPathNewContext(xml))) { - virReportOOMError(); + + if (!(xPathContext =3D virXMLXPathContextNew(xml))) goto cleanup; - } + xPathContext->node =3D xmlDocGetRootElement(xml); if ((nodeSize =3D virXPathNodeSet("/domainsnapshot/disks/disk", xPathContext, &nodes)) < 0) @@ -1360,10 +1359,10 @@ virVBoxSnapshotConfGetRODisksPathsFromLibvirtXML(co= nst char *filePath, _("Unable to parse the xml")); goto cleanup; } - if (!(xPathContext =3D xmlXPathNewContext(xml))) { - virReportOOMError(); + + if (!(xPathContext =3D virXMLXPathContextNew(xml))) goto cleanup; - } + xPathContext->node =3D xmlDocGetRootElement(xml); if ((nodeSize =3D virXPathNodeSet("/domainsnapshot/domain/devices/disk= ", xPathContext, diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c index 478443298f..c6e3398620 100644 --- a/src/vz/vz_sdk.c +++ b/src/vz/vz_sdk.c @@ -4674,11 +4674,9 @@ prlsdkParseSnapshotTree(const char *treexml) goto cleanup; } - ctxt =3D xmlXPathNewContext(xml); - if (ctxt =3D=3D NULL) { - virReportOOMError(); + if (!(ctxt =3D virXMLXPathContextNew(xml))) goto cleanup; - } + ctxt->node =3D root; if ((n =3D virXPathNodeSet("//SavedStateItem", ctxt, &nodes)) < 0) { --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 23:09:08 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 ARC-Seal: i=1; a=rsa-sha256; t=1568636246; cv=none; d=zoho.com; s=zohoarc; b=bkRLj0228aKthZXCMlcEj6PoDYTxgY3PcGjmSlsyF2mZ9i1ZRkzbApNYLsp61zIQv4s6bo996LvdDIIRXVBluDWe2Saz6T4nzPhpbVq4I0/C8iMmPUTeS5K1Hl3rzHExOP6fBozKXr+1UtJ3ZVTtDhB1mxJEKMIQsOXuEvgcnBo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568636246; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=URjTYvU0FAZDFflsWfMAyxN5CEdxEkhanDrVNlixiVo=; b=eLISmpSKICMrJemIiyS5Ad3z8nPH8ONaLuUZo09SeRQsBzrYX7vy6IuX7lQ0CHKEah/Xbz1qhEOcZd57+LWCY8HNW6j51S07wHg6HzMZxiENv40CKv63xO0V84mSsLogMmY/pjHc1aS3U+EkI4D99zMG2NPjFbaXDF4cPqg2RPU= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568636246980851.7910401570064; Mon, 16 Sep 2019 05:17:26 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 36761315C015; Mon, 16 Sep 2019 12:17:24 +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 DDAB960BE1; Mon, 16 Sep 2019 12:17:23 +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 369E683543; Mon, 16 Sep 2019 12:17:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8GCHL88024497 for ; Mon, 16 Sep 2019 08:17:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 54973196AE; Mon, 16 Sep 2019 12:17:21 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id D1089A20C for ; Mon, 16 Sep 2019 12:17:20 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Mon, 16 Sep 2019 14:17:05 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/9] conf: network: Use VIR_AUTOPTR in virNetworkDefUpdateSection 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-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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Mon, 16 Sep 2019 12:17:24 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Add automatic cleanup for variables of xmlDoc and xmlXPathContext type to remove the cleanup section. Signed-off-by: Peter Krempa Reviewed-by: Jiri Denemark --- src/conf/network_conf.c | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 585c87a9f4..b65fb1f67a 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -3640,57 +3640,56 @@ virNetworkDefUpdateSection(virNetworkDefPtr def, const char *xml, unsigned int flags) /* virNetworkUpdateFlags */ { - int ret =3D -1; - xmlDocPtr doc; - xmlXPathContextPtr ctxt =3D NULL; + VIR_AUTOPTR(xmlDoc) doc =3D NULL; + VIR_AUTOPTR(xmlXPathContext) ctxt =3D NULL; if (!(doc =3D virXMLParseStringCtxt(xml, _("network_update_xml"), &ctx= t))) - goto cleanup; + return -1; switch (section) { case VIR_NETWORK_SECTION_BRIDGE: - ret =3D virNetworkDefUpdateBridge(def, command, parentIndex, ctxt, = flags); + return virNetworkDefUpdateBridge(def, command, parentIndex, ctxt, = flags); break; case VIR_NETWORK_SECTION_DOMAIN: - ret =3D virNetworkDefUpdateDomain(def, command, parentIndex, ctxt,= flags); + return virNetworkDefUpdateDomain(def, command, parentIndex, ctxt, = flags); break; case VIR_NETWORK_SECTION_IP: - ret =3D virNetworkDefUpdateIP(def, command, parentIndex, ctxt, fla= gs); + return virNetworkDefUpdateIP(def, command, parentIndex, ctxt, flag= s); break; case VIR_NETWORK_SECTION_IP_DHCP_HOST: - ret =3D virNetworkDefUpdateIPDHCPHost(def, command, + return virNetworkDefUpdateIPDHCPHost(def, command, parentIndex, ctxt, flags); break; case VIR_NETWORK_SECTION_IP_DHCP_RANGE: - ret =3D virNetworkDefUpdateIPDHCPRange(def, command, + return virNetworkDefUpdateIPDHCPRange(def, command, parentIndex, ctxt, flags); break; case VIR_NETWORK_SECTION_FORWARD: - ret =3D virNetworkDefUpdateForward(def, command, + return virNetworkDefUpdateForward(def, command, parentIndex, ctxt, flags); break; case VIR_NETWORK_SECTION_FORWARD_INTERFACE: - ret =3D virNetworkDefUpdateForwardInterface(def, command, + return virNetworkDefUpdateForwardInterface(def, command, parentIndex, ctxt, flags= ); break; case VIR_NETWORK_SECTION_FORWARD_PF: - ret =3D virNetworkDefUpdateForwardPF(def, command, + return virNetworkDefUpdateForwardPF(def, command, parentIndex, ctxt, flags); break; case VIR_NETWORK_SECTION_PORTGROUP: - ret =3D virNetworkDefUpdatePortGroup(def, command, + return virNetworkDefUpdatePortGroup(def, command, parentIndex, ctxt, flags); break; case VIR_NETWORK_SECTION_DNS_HOST: - ret =3D virNetworkDefUpdateDNSHost(def, command, + return virNetworkDefUpdateDNSHost(def, command, parentIndex, ctxt, flags); break; case VIR_NETWORK_SECTION_DNS_TXT: - ret =3D virNetworkDefUpdateDNSTxt(def, command, parentIndex, ctxt,= flags); + return virNetworkDefUpdateDNSTxt(def, command, parentIndex, ctxt, = flags); break; case VIR_NETWORK_SECTION_DNS_SRV: - ret =3D virNetworkDefUpdateDNSSrv(def, command, parentIndex, ctxt,= flags); + return virNetworkDefUpdateDNSSrv(def, command, parentIndex, ctxt, = flags); break; default: virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", @@ -3698,8 +3697,5 @@ virNetworkDefUpdateSection(virNetworkDefPtr def, break; } - cleanup: - xmlFreeDoc(doc); - xmlXPathFreeContext(ctxt); - return ret; + return -1; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 23:09:08 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 ARC-Seal: i=1; a=rsa-sha256; t=1568636260; cv=none; d=zoho.com; s=zohoarc; b=PTZZDLjXx5zsdX+jhnZJAC0yLcub/5qnfqBbAQcL9UKqDDLI0j0QjbZfcGCssh9/zQ6t+pToTFwqMdubFPflRsw8n1j5sAQxCYGD/r/znbCj0/XnDSQW3O0UvIpg+oKKI6hQtDKRskfc2bLwjEIkfpxPjI3GL1LHrrHVdgB9Uhg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568636260; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=Yy+VF7MLN7R9SLmfC0J24qo3Wmtwr9KgvskLsJyczDQ=; b=d5IOZZ5nconV0if2QMyNliauQcuHtqA0Te+SucKZndLz9L0mMK6wBR+ri0Q/5c1GNnzLYiCbn4iBJ2HxsBU7SjccJXgHVXWjfJ0sAs8s9ceH5YeoXQnLPu8HbJVShlHA3UCy3tHn/xt+QdZucElMDAJfkal3zOO/lg3x11Un8UU= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 156863626064726.142531356029394; Mon, 16 Sep 2019 05:17:40 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BCC9C2A09A2; Mon, 16 Sep 2019 12:17:38 +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 97EEC19D7A; Mon, 16 Sep 2019 12:17: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 549CF1808876; Mon, 16 Sep 2019 12:17:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8GCHMsf024507 for ; Mon, 16 Sep 2019 08:17:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id 23E6F9D51; Mon, 16 Sep 2019 12:17:22 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id A14D0196AE for ; Mon, 16 Sep 2019 12:17:21 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Mon, 16 Sep 2019 14:17:06 +0200 Message-Id: <7cdbf65fe162dd23810dac48b89d40e761e0d9db.1568636165.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/9] conf: Refactor resource cleanup in virDomainDeviceDefParse 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-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.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 16 Sep 2019 12:17:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Use VIR_AUTO* helpers to get rid of the convoluted cleanup path. Signed-off-by: Peter Krempa Reviewed-by: Jiri Denemark --- src/conf/domain_conf.c | 73 +++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 40 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index e5e3f31f76..2fe591c328 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -16330,19 +16330,19 @@ virDomainDeviceDefParse(const char *xmlStr, void *parseOpaque, unsigned int flags) { - xmlDocPtr xml; + VIR_AUTOPTR(xmlDoc) xml =3D NULL; xmlNodePtr node; - xmlXPathContextPtr ctxt =3D NULL; - virDomainDeviceDefPtr dev =3D NULL; + VIR_AUTOPTR(xmlXPathContext) ctxt =3D NULL; + VIR_AUTOFREE(virDomainDeviceDefPtr) dev =3D NULL; char *netprefix; if (!(xml =3D virXMLParseStringCtxt(xmlStr, _("(device_definition)"), = &ctxt))) - goto error; + return NULL; node =3D ctxt->node; if (VIR_ALLOC(dev) < 0) - goto error; + return NULL; if ((dev->type =3D virDomainDeviceTypeFromString((const char *) node->= name)) < 0) { /* Some crazy mapping of serial, parallel, console and channel to @@ -16356,7 +16356,7 @@ virDomainDeviceDefParse(const char *xmlStr, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown device type '%s'"), node->name); - goto error; + return NULL; } } @@ -16366,71 +16366,71 @@ virDomainDeviceDefParse(const char *xmlStr, def->seclabels, def->nseclabels, flags))) - goto error; + return NULL; break; case VIR_DOMAIN_DEVICE_LEASE: if (!(dev->data.lease =3D virDomainLeaseDefParseXML(node))) - goto error; + return NULL; break; case VIR_DOMAIN_DEVICE_FS: if (!(dev->data.fs =3D virDomainFSDefParseXML(xmlopt, node, ctxt, = flags))) - goto error; + return NULL; break; case VIR_DOMAIN_DEVICE_NET: netprefix =3D caps->host.netprefix; if (!(dev->data.net =3D virDomainNetDefParseXML(xmlopt, node, ctxt, netprefix, flags))) - goto error; + return NULL; break; case VIR_DOMAIN_DEVICE_INPUT: if (!(dev->data.input =3D virDomainInputDefParseXML(xmlopt, def, n= ode, ctxt, flags))) - goto error; + return NULL; break; case VIR_DOMAIN_DEVICE_SOUND: if (!(dev->data.sound =3D virDomainSoundDefParseXML(xmlopt, node, ctxt, flags))) - goto error; + return NULL; break; case VIR_DOMAIN_DEVICE_WATCHDOG: if (!(dev->data.watchdog =3D virDomainWatchdogDefParseXML(xmlopt, node, flag= s))) - goto error; + return NULL; break; case VIR_DOMAIN_DEVICE_VIDEO: if (!(dev->data.video =3D virDomainVideoDefParseXML(xmlopt, node, ctxt, def, flags= ))) - goto error; + return NULL; break; case VIR_DOMAIN_DEVICE_HOSTDEV: if (!(dev->data.hostdev =3D virDomainHostdevDefParseXML(xmlopt, no= de, ctxt, flags))) - goto error; + return NULL; break; case VIR_DOMAIN_DEVICE_CONTROLLER: if (!(dev->data.controller =3D virDomainControllerDefParseXML(xmlo= pt, node, ctxt, = flags))) - goto error; + return NULL; break; case VIR_DOMAIN_DEVICE_GRAPHICS: if (!(dev->data.graphics =3D virDomainGraphicsDefParseXML(xmlopt, = node, ctxt, flag= s))) - goto error; + return NULL; break; case VIR_DOMAIN_DEVICE_HUB: if (!(dev->data.hub =3D virDomainHubDefParseXML(xmlopt, node, flag= s))) - goto error; + return NULL; break; case VIR_DOMAIN_DEVICE_REDIRDEV: if (!(dev->data.redirdev =3D virDomainRedirdevDefParseXML(xmlopt, = node, ctxt, flag= s))) - goto error; + return NULL; break; case VIR_DOMAIN_DEVICE_RNG: if (!(dev->data.rng =3D virDomainRNGDefParseXML(xmlopt, node, ctxt, flags))) - goto error; + return NULL; break; case VIR_DOMAIN_DEVICE_CHR: if (!(dev->data.chr =3D virDomainChrDefParseXML(xmlopt, @@ -16439,50 +16439,50 @@ virDomainDeviceDefParse(const char *xmlStr, def->seclabels, def->nseclabels, flags))) - goto error; + return NULL; break; case VIR_DOMAIN_DEVICE_SMARTCARD: if (!(dev->data.smartcard =3D virDomainSmartcardDefParseXML(xmlopt= , node, ctxt, fl= ags))) - goto error; + return NULL; break; case VIR_DOMAIN_DEVICE_MEMBALLOON: if (!(dev->data.memballoon =3D virDomainMemballoonDefParseXML(xmlo= pt, node, ctxt, flags)= )) - goto error; + return NULL; break; case VIR_DOMAIN_DEVICE_NVRAM: if (!(dev->data.nvram =3D virDomainNVRAMDefParseXML(xmlopt, node, = flags))) - goto error; + return NULL; break; case VIR_DOMAIN_DEVICE_SHMEM: if (!(dev->data.shmem =3D virDomainShmemDefParseXML(xmlopt, node, ctxt, flags))) - goto error; + return NULL; break; case VIR_DOMAIN_DEVICE_TPM: if (!(dev->data.tpm =3D virDomainTPMDefParseXML(xmlopt, node, ctxt= , flags))) - goto error; + return NULL; break; case VIR_DOMAIN_DEVICE_PANIC: if (!(dev->data.panic =3D virDomainPanicDefParseXML(xmlopt, node, = flags))) - goto error; + return NULL; break; case VIR_DOMAIN_DEVICE_MEMORY: if (!(dev->data.memory =3D virDomainMemoryDefParseXML(xmlopt, node, ctxt, flags))) - goto error; + return NULL; break; case VIR_DOMAIN_DEVICE_IOMMU: if (!(dev->data.iommu =3D virDomainIOMMUDefParseXML(node, ctxt))) - goto error; + return NULL; break; case VIR_DOMAIN_DEVICE_VSOCK: if (!(dev->data.vsock =3D virDomainVsockDefParseXML(xmlopt, node, = ctxt, flags))) - goto error; + return NULL; break; case VIR_DOMAIN_DEVICE_NONE: case VIR_DOMAIN_DEVICE_LAST: @@ -16492,20 +16492,13 @@ virDomainDeviceDefParse(const char *xmlStr, /* callback to fill driver specific device aspects */ if (virDomainDeviceDefPostParseOne(dev, def, caps, flags, xmlopt, parseOpaque) < 0) - goto error; + return NULL; /* validate the configuration */ if (virDomainDeviceDefValidate(dev, def, flags, xmlopt) < 0) - goto error; - - cleanup: - xmlFreeDoc(xml); - xmlXPathFreeContext(ctxt); - return dev; + return NULL; - error: - VIR_FREE(dev); - goto cleanup; + VIR_RETURN_PTR(dev); } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 23:09:08 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 ARC-Seal: i=1; a=rsa-sha256; t=1568636260; cv=none; d=zoho.com; s=zohoarc; b=RWgPqpdcAHDYzrfRwSfSgzUwolzkzlqBiaCCOOraX2XtdjkKtX+SYoTI9OEY2uevpX9GevZkyLKZjiy6R7UcbWm2DxeUmnRr8nFDc+s65ej4yRLi4rMB9M8mRbVS2JlRqecDKp4TyOqYInJGhlVuHZjV4ibw6ouJ1Bs9Xxeqr3M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568636260; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=JLciMzXJIPUUUUdcId/bildtU4ID0EoGLYUJIxVP7FQ=; b=f3eJCfeKbbNE3MWxCSEIRnWfJQgAt7cEsdDsU2QxJGG/+MjNE7eY3AYhoSPy2b/2kV1mVcc+kGDTcEGjHaCHfZ+gorTuG8dsbVewwC82A5bdc6JbMGJXF6FIKeicsQcuMYDDSuzt9bJ9wGdhxN35gQ4bEg8vE90DvS/4X/NX5y4= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568636260827101.44932846978668; Mon, 16 Sep 2019 05:17:40 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BE73D3175293; Mon, 16 Sep 2019 12:17: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 95A756012C; Mon, 16 Sep 2019 12:17: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 57D408354B; Mon, 16 Sep 2019 12:17:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8GCHOIP024524 for ; Mon, 16 Sep 2019 08:17:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9071F196AE; Mon, 16 Sep 2019 12:17:24 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1A5129938 for ; Mon, 16 Sep 2019 12:17:22 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Mon, 16 Sep 2019 14:17:07 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/9] conf: Use automatic pointers for xmlXPathContext 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-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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Mon, 16 Sep 2019 12:17:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Clean up functions which grab and free the context to use VIR_AUTOPTR. Signed-off-by: Peter Krempa Reviewed-by: Jiri Denemark --- src/conf/checkpoint_conf.c | 12 ++++-------- src/conf/domain_conf.c | 13 ++++--------- src/conf/interface_conf.c | 11 +++-------- src/conf/network_conf.c | 11 +++-------- src/conf/node_device_conf.c | 11 +++-------- src/conf/nwfilter_conf.c | 13 ++++--------- src/conf/snapshot_conf.c | 16 ++++++---------- src/conf/storage_conf.c | 24 ++++++++---------------- 8 files changed, 35 insertions(+), 76 deletions(-) diff --git a/src/conf/checkpoint_conf.c b/src/conf/checkpoint_conf.c index 113d85cc14..5c998267aa 100644 --- a/src/conf/checkpoint_conf.c +++ b/src/conf/checkpoint_conf.c @@ -209,13 +209,12 @@ virDomainCheckpointDefParseNode(xmlDocPtr xml, void *parseOpaque, unsigned int flags) { - xmlXPathContextPtr ctxt =3D NULL; - virDomainCheckpointDefPtr def =3D NULL; + VIR_AUTOPTR(xmlXPathContext) ctxt =3D NULL; VIR_AUTOFREE(char *) schema =3D NULL; if (!virXMLNodeNameEqual(root, "domaincheckpoint")) { virReportError(VIR_ERR_XML_ERROR, "%s", _("domaincheckpoint")); - goto cleanup; + return NULL; } /* This is a new enough API to make schema validation unconditional */ @@ -228,13 +227,10 @@ virDomainCheckpointDefParseNode(xmlDocPtr xml, return NULL; if (!(ctxt =3D virXMLXPathContextNew(xml))) - goto cleanup; + return NULL; ctxt->node =3D root; - def =3D virDomainCheckpointDefParse(ctxt, caps, xmlopt, parseOpaque, f= lags); - cleanup: - xmlXPathFreeContext(ctxt); - return def; + return virDomainCheckpointDefParse(ctxt, caps, xmlopt, parseOpaque, fl= ags); } virDomainCheckpointDefPtr diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 2fe591c328..0ab69a9366 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -21600,26 +21600,21 @@ virDomainObjParseNode(xmlDocPtr xml, virDomainXMLOptionPtr xmlopt, unsigned int flags) { - xmlXPathContextPtr ctxt =3D NULL; - virDomainObjPtr obj =3D NULL; + VIR_AUTOPTR(xmlXPathContext) ctxt =3D NULL; if (!virXMLNodeNameEqual(root, "domstatus")) { virReportError(VIR_ERR_XML_ERROR, _("unexpected root element <%s>, " "expecting "), root->name); - goto cleanup; + return NULL; } if (!(ctxt =3D virXMLXPathContextNew(xml))) - goto cleanup; + return NULL; ctxt->node =3D root; - obj =3D virDomainObjParseXML(xml, ctxt, caps, xmlopt, flags); - - cleanup: - xmlXPathFreeContext(ctxt); - return obj; + return virDomainObjParseXML(xml, ctxt, caps, xmlopt, flags); } diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c index 64729aea43..2b65a235ea 100644 --- a/src/conf/interface_conf.c +++ b/src/conf/interface_conf.c @@ -819,8 +819,7 @@ virInterfaceDefPtr virInterfaceDefParseNode(xmlDocPtr xml, xmlNodePtr root) { - xmlXPathContextPtr ctxt =3D NULL; - virInterfaceDefPtr def =3D NULL; + VIR_AUTOPTR(xmlXPathContext) ctxt =3D NULL; if (!virXMLNodeNameEqual(root, "interface")) { virReportError(VIR_ERR_XML_ERROR, @@ -831,14 +830,10 @@ virInterfaceDefParseNode(xmlDocPtr xml, } if (!(ctxt =3D virXMLXPathContextNew(xml))) - goto cleanup; + return NULL; ctxt->node =3D root; - def =3D virInterfaceDefParseXML(ctxt, VIR_INTERFACE_TYPE_LAST); - - cleanup: - xmlXPathFreeContext(ctxt); - return def; + return virInterfaceDefParseXML(ctxt, VIR_INTERFACE_TYPE_LAST); } diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index b65fb1f67a..9990d5e79d 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -2114,8 +2114,7 @@ virNetworkDefParseNode(xmlDocPtr xml, xmlNodePtr root, virNetworkXMLOptionPtr xmlopt) { - xmlXPathContextPtr ctxt =3D NULL; - virNetworkDefPtr def =3D NULL; + VIR_AUTOPTR(xmlXPathContext) ctxt =3D NULL; if (!virXMLNodeNameEqual(root, "network")) { virReportError(VIR_ERR_XML_ERROR, @@ -2126,14 +2125,10 @@ virNetworkDefParseNode(xmlDocPtr xml, } if (!(ctxt =3D virXMLXPathContextNew(xml))) - goto cleanup; + return NULL; ctxt->node =3D root; - def =3D virNetworkDefParseXML(ctxt, xmlopt); - - cleanup: - xmlXPathFreeContext(ctxt); - return def; + return virNetworkDefParseXML(ctxt, xmlopt); } diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 8f8830aef1..84fcbd3e78 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -2052,8 +2052,7 @@ virNodeDeviceDefParseNode(xmlDocPtr xml, int create, const char *virt_type) { - xmlXPathContextPtr ctxt =3D NULL; - virNodeDeviceDefPtr def =3D NULL; + VIR_AUTOPTR(xmlXPathContext) ctxt =3D NULL; if (!virXMLNodeNameEqual(root, "device")) { virReportError(VIR_ERR_XML_ERROR, @@ -2064,14 +2063,10 @@ virNodeDeviceDefParseNode(xmlDocPtr xml, } if (!(ctxt =3D virXMLXPathContextNew(xml))) - goto cleanup; + return NULL; ctxt->node =3D root; - def =3D virNodeDeviceDefParseXML(ctxt, create, virt_type); - - cleanup: - xmlXPathFreeContext(ctxt); - return def; + return virNodeDeviceDefParseXML(ctxt, create, virt_type); } diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c index 21885eb7ae..d21eebf19d 100644 --- a/src/conf/nwfilter_conf.c +++ b/src/conf/nwfilter_conf.c @@ -2746,25 +2746,20 @@ virNWFilterDefPtr virNWFilterDefParseNode(xmlDocPtr xml, xmlNodePtr root) { - xmlXPathContextPtr ctxt =3D NULL; - virNWFilterDefPtr def =3D NULL; + VIR_AUTOPTR(xmlXPathContext) ctxt =3D NULL; if (STRNEQ((const char *)root->name, "filter")) { virReportError(VIR_ERR_XML_ERROR, "%s", _("unknown root element for nw filter")); - goto cleanup; + return NULL; } if (!(ctxt =3D virXMLXPathContextNew(xml))) - goto cleanup; + return NULL; ctxt->node =3D root; - def =3D virNWFilterDefParseXML(ctxt); - - cleanup: - xmlXPathFreeContext(ctxt); - return def; + return virNWFilterDefParseXML(ctxt); } diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index 8cf80aed83..61c807a71f 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -430,12 +430,11 @@ virDomainSnapshotDefParseNode(xmlDocPtr xml, bool *current, unsigned int flags) { - xmlXPathContextPtr ctxt =3D NULL; - virDomainSnapshotDefPtr def =3D NULL; + VIR_AUTOPTR(xmlXPathContext) ctxt =3D NULL; if (!virXMLNodeNameEqual(root, "domainsnapshot")) { virReportError(VIR_ERR_XML_ERROR, "%s", _("domainsnapshot")); - goto cleanup; + return NULL; } if (flags & VIR_DOMAIN_SNAPSHOT_PARSE_VALIDATE) { @@ -445,19 +444,16 @@ virDomainSnapshotDefParseNode(xmlDocPtr xml, abs_top_srcdir "/docs/schemas", PKGDATADIR "/schemas"); if (!schema) - goto cleanup; + return NULL; if (virXMLValidateAgainstSchema(schema, xml) < 0) - goto cleanup; + return NULL; } if (!(ctxt =3D virXMLXPathContextNew(xml))) - goto cleanup; + return NULL; ctxt->node =3D root; - def =3D virDomainSnapshotDefParse(ctxt, caps, xmlopt, parseOpaque, cur= rent, flags); - cleanup: - xmlXPathFreeContext(ctxt); - return def; + return virDomainSnapshotDefParse(ctxt, caps, xmlopt, parseOpaque, curr= ent, flags); } virDomainSnapshotDefPtr diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 0560994281..f6de3687ab 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -1013,25 +1013,21 @@ virStoragePoolDefPtr virStoragePoolDefParseNode(xmlDocPtr xml, xmlNodePtr root) { - xmlXPathContextPtr ctxt =3D NULL; - virStoragePoolDefPtr def =3D NULL; + VIR_AUTOPTR(xmlXPathContext) ctxt =3D NULL; if (!virXMLNodeNameEqual(root, "pool")) { virReportError(VIR_ERR_XML_ERROR, _("unexpected root element <%s>, " "expecting "), root->name); - goto cleanup; + return NULL; } if (!(ctxt =3D virXMLXPathContextNew(xml))) - goto cleanup; + return NULL; ctxt->node =3D root; - def =3D virStoragePoolDefParseXML(ctxt); - cleanup: - xmlXPathFreeContext(ctxt); - return def; + return virStoragePoolDefParseXML(ctxt); } @@ -1454,25 +1450,21 @@ virStorageVolDefParseNode(virStoragePoolDefPtr pool, xmlNodePtr root, unsigned int flags) { - xmlXPathContextPtr ctxt =3D NULL; - virStorageVolDefPtr def =3D NULL; + VIR_AUTOPTR(xmlXPathContext) ctxt =3D NULL; if (!virXMLNodeNameEqual(root, "volume")) { virReportError(VIR_ERR_XML_ERROR, _("unexpected root element <%s>, " "expecting "), root->name); - goto cleanup; + return NULL; } if (!(ctxt =3D virXMLXPathContextNew(xml))) - goto cleanup; + return NULL; ctxt->node =3D root; - def =3D virStorageVolDefParseXML(pool, ctxt, flags); - cleanup: - xmlXPathFreeContext(ctxt); - return def; + return virStorageVolDefParseXML(pool, ctxt, flags); } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 23:09:08 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 ARC-Seal: i=1; a=rsa-sha256; t=1568636263; cv=none; d=zoho.com; s=zohoarc; b=jwRJkDDN700mPemargcxeFdB0h8xA8MFN1IW3ocI8XVMnaD/SKygEm8eWxTcsf1iiRzqpx/lwot7RkANDvu5fl/dj/bJPelwcNOWrseaWlArrC3amsLE3wWX7Q1ZFN3f587onVjkBvM2Mi8yWuqB3sgsCleZR/HiCr5gHhfgfl8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568636263; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=5qVDttex3GajnD6oDwIpEqk8wBylT+NYzBHR8kRmFJo=; b=jCVO9lW9WJDAfHRK8Pq6vQh0XpU4WVv3tKP9m7+fERPcmKW/qPpYzkt2VuM77xsqaHKeTWNddeT0Y343wNVbKeX1CmZdyryht4cVD/fw5wkfMzNIEQyH5bXwnnLHlvBPDEpMjPluZMnpmdZzJ5DXQIV+KtmksczuIGY36/FTkQc= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568636263931137.40769069258306; Mon, 16 Sep 2019 05:17:43 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 376F8315C01B; Mon, 16 Sep 2019 12:17:42 +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 123D85D6C8; Mon, 16 Sep 2019 12:17:42 +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 C30738354D; Mon, 16 Sep 2019 12:17:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8GCHPL6024529 for ; Mon, 16 Sep 2019 08:17:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id 610148D5E; Mon, 16 Sep 2019 12:17:25 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id DE5E24115 for ; Mon, 16 Sep 2019 12:17:24 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Mon, 16 Sep 2019 14:17:08 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 5/9] conf: Use VIR_AUTOPTR for xmlDoc and xmlXPath objects 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-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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Mon, 16 Sep 2019 12:17:42 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Refactor functions using these two object types together with VIR_AUTOPTR. Signed-off-by: Peter Krempa Reviewed-by: Jiri Denemark --- src/conf/domain_conf.c | 16 +++++----------- src/conf/storage_conf.c | 20 +++++++------------- 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 0ab69a9366..5fec2e5220 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -16508,20 +16508,19 @@ virDomainDiskDefParse(const char *xmlStr, virDomainXMLOptionPtr xmlopt, unsigned int flags) { - xmlDocPtr xml; - xmlXPathContextPtr ctxt =3D NULL; - virDomainDiskDefPtr disk =3D NULL; + VIR_AUTOPTR(xmlDoc) xml =3D NULL; + VIR_AUTOPTR(xmlXPathContext) ctxt =3D NULL; virSecurityLabelDefPtr *seclabels =3D NULL; size_t nseclabels =3D 0; if (!(xml =3D virXMLParseStringCtxt(xmlStr, _("(disk_definition)"), &c= txt))) - goto cleanup; + return NULL; if (!virXMLNodeNameEqual(ctxt->node, "disk")) { virReportError(VIR_ERR_XML_ERROR, _("expecting root element of 'disk', not '%s'"), ctxt->node->name); - goto cleanup; + return NULL; } if (def) { @@ -16529,13 +16528,8 @@ virDomainDiskDefParse(const char *xmlStr, nseclabels =3D def->nseclabels; } - disk =3D virDomainDiskDefParseXML(xmlopt, ctxt->node, ctxt, + return virDomainDiskDefParseXML(xmlopt, ctxt->node, ctxt, seclabels, nseclabels, flags); - - cleanup: - xmlFreeDoc(xml); - xmlXPathFreeContext(ctxt); - return disk; } diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index f6de3687ab..fcd1701d37 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -695,36 +695,30 @@ virStoragePoolSourcePtr virStoragePoolDefParseSourceString(const char *srcSpec, int pool_type) { - xmlDocPtr doc =3D NULL; + VIR_AUTOPTR(xmlDoc) doc =3D NULL; xmlNodePtr node =3D NULL; - xmlXPathContextPtr xpath_ctxt =3D NULL; - virStoragePoolSourcePtr ret =3D NULL; + VIR_AUTOPTR(xmlXPathContext) xpath_ctxt =3D NULL; VIR_AUTOPTR(virStoragePoolSource) def =3D NULL; if (!(doc =3D virXMLParseStringCtxt(srcSpec, _("(storage_source_specification)"), &xpath_ctxt))) - goto cleanup; + return NULL; if (VIR_ALLOC(def) < 0) - goto cleanup; + return NULL; if (!(node =3D virXPathNode("/source", xpath_ctxt))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("root element was not source")); - goto cleanup; + return NULL; } if (virStoragePoolDefParseSource(xpath_ctxt, def, pool_type, node) < 0) - goto cleanup; - - VIR_STEAL_PTR(ret, def); - cleanup: - xmlFreeDoc(doc); - xmlXPathFreeContext(xpath_ctxt); + return NULL; - return ret; + VIR_RETURN_PTR(def); } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 23:09:08 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 ARC-Seal: i=1; a=rsa-sha256; t=1568636260; cv=none; d=zoho.com; s=zohoarc; b=IZCc139y7uSXom5rLDTBCwvigu2CntV79dYhS4uDIdW96GbYK2yqF2TYIX4/xqGV9umxEH7WnaBhvoJPyTHAR62Vhi9fhG4cyYW24MHiSZn2NlJBxhN0y2dyK0+3AattRe0aJE6DgyZVdTHHNxqQI4wwMhZXgHDz9TFsx0AwE7k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568636260; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=khp1gwLwISnuKBnKHRK4VmwJvCnqPzSQ5Ih35bWK6w4=; b=jokUAjvITK+ffb2IsJ8alXlm1kiJs2vUjNfqMPHr++lpKpGfCuecO8KrOXh6BpPqb16JU+51Ptp7Xm2nOCYRKwQA7dz4LxrQM0C1gau8zKjI/Bp+2aM1W0EM3icZHqMPv3i2o/4enVXEZqKAzHY89V+AebYC8iTGBkrfmKv1xps= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568636260017319.65006213015124; Mon, 16 Sep 2019 05:17:40 -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 55DE810C093B; Mon, 16 Sep 2019 12:17: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 2F4B65D9E1; Mon, 16 Sep 2019 12:17: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 E0B6F83549; Mon, 16 Sep 2019 12:17:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8GCHQ3h024535 for ; Mon, 16 Sep 2019 08:17:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id 31F8B196AE; Mon, 16 Sep 2019 12:17:26 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE7D54115 for ; Mon, 16 Sep 2019 12:17:25 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Mon, 16 Sep 2019 14:17:09 +0200 Message-Id: <4db457c52ca8fad805c7547a515116558cf51a77.1568636165.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 6/9] conf: domain: Register VIR_AUTOPTR function for virDomainDef 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-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.6.2 (mx1.redhat.com [10.5.110.66]); Mon, 16 Sep 2019 12:17:38 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: Jiri Denemark --- src/conf/domain_conf.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index b688ee2b83..57ce5b95dc 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2892,6 +2892,7 @@ bool virDomainDefHasDeviceAddress(virDomainDefPtr def, ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; void virDomainDefFree(virDomainDefPtr vm); +VIR_DEFINE_AUTOPTR_FUNC(virDomainDef, virDomainDefFree); virDomainChrSourceDefPtr virDomainChrSourceDefNew(virDomainXMLOptionPtr xmlopt); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 23:09:08 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 ARC-Seal: i=1; a=rsa-sha256; t=1568636267; cv=none; d=zoho.com; s=zohoarc; b=Wcps280+JCQ5ATMnSb1IRp9p8ESfjJTCfP6JGe6tjOKAol1BhPCZxSb5/uOd100gZDRzqx4ikTytYvSTzOtFsSjgBFY5SgnW8rsZJ0bYbnw1nBb+41uYZBjhCeosvdX4gf2SvVHOD23++ek52eCSDwnbaNMDnoaMh1e/8X0Xpco= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568636267; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=3p29jSdeqP6ohwQiOTWfLGu6jTl1/IgncIwbmu74Kqk=; b=SFs90OKraHUsfFTQ3D3h4eLKYhvNHo4hU0LEPD2Vt8iB/fpdG+Hg7fUS66PMc+7zWJAYMAsZv53dp5RPd4n2b0FN70iUMzwWzMRx5gAMwyZJuJGhlSlV6K+8Zsx89osSPKtxEH/+69xh3x620EQHeNgtMZGvIrMz+Lfhym9d8aA= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568636267755956.1435582732112; Mon, 16 Sep 2019 05:17:47 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D08E9315C02B; Mon, 16 Sep 2019 12:17:45 +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 AF1351001947; Mon, 16 Sep 2019 12:17:45 +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 7048283550; Mon, 16 Sep 2019 12:17:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8GCHRxA024547 for ; Mon, 16 Sep 2019 08:17:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id 00C28196AE; Mon, 16 Sep 2019 12:17:27 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7F7FB4115 for ; Mon, 16 Sep 2019 12:17:26 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Mon, 16 Sep 2019 14:17:10 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 7/9] conf: domain: Refactor cleanup in virDomainDefParseNode 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-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.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Mon, 16 Sep 2019 12:17:46 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Use VIR_AUTOPTR for temporary locals and get rid of the cleanup label. Signed-off-by: Peter Krempa Reviewed-by: Jiri Denemark --- src/conf/domain_conf.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 5fec2e5220..35573c0aaf 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -21558,32 +21558,26 @@ virDomainDefParseNode(xmlDocPtr xml, void *parseOpaque, unsigned int flags) { - xmlXPathContextPtr ctxt =3D NULL; - virDomainDefPtr def =3D NULL; - virDomainDefPtr ret =3D NULL; + VIR_AUTOPTR(xmlXPathContext) ctxt =3D NULL; + VIR_AUTOPTR(virDomainDef) def =3D NULL; if (!(ctxt =3D virXMLXPathContextNew(xml))) - goto cleanup; + return NULL; ctxt->node =3D root; if (!(def =3D virDomainDefParseXML(xml, ctxt, caps, xmlopt, flags))) - goto cleanup; + return NULL; /* callback to fill driver specific domain aspects */ if (virDomainDefPostParse(def, caps, flags, xmlopt, parseOpaque) < 0) - goto cleanup; + return NULL; /* validate configuration */ if (virDomainDefValidate(def, caps, flags, xmlopt) < 0) - goto cleanup; - - VIR_STEAL_PTR(ret, def); + return NULL; - cleanup: - virDomainDefFree(def); - xmlXPathFreeContext(ctxt); - return ret; + VIR_RETURN_PTR(def); } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 23:09:08 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 ARC-Seal: i=1; a=rsa-sha256; t=1568636266; cv=none; d=zoho.com; s=zohoarc; b=MfvLCl2lkRWu9vEylXHPOJXp0g9jKNrAQAiDVGSyMbpcy/jPDkGxUolzQbqkiyzwdxrh6/LCkBWZdYf/CtAm4PYdrTZ6Xqq4LnZ5YIwlhvOFVb3A+U5oZYXyg2dxJMjHJZgNNQhwB/2lUfYwi75t2Tm+3Wuh6JIHheoEQ/bSeVk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568636266; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=AvHbYJbJwDi/v5EuLxkRLebK3Md2dy48pa1OCjyYjGg=; b=KejQn3Ko3yDeiszdgHyE3qw0BICythu1gKbJKCqtqTi0mDwJcfWwkIPAf8ynd9hNtz/zm7ihKEhh419zzYgwpPFB5BBBWLtCYPo58rczadtMHmY+R95gYH5pvXs/UCZ6yRxF66/rE3cLlWPZYaey9wfniWE1EgbzEq+UaBLiKTU= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568636266097494.38893504777354; Mon, 16 Sep 2019 05:17:46 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 10F718535D; Mon, 16 Sep 2019 12:17:44 +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 E012C5C22C; Mon, 16 Sep 2019 12:17:43 +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 A4DDA180BA98; Mon, 16 Sep 2019 12:17:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8GCHRGe024554 for ; Mon, 16 Sep 2019 08:17:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id C650A9938; Mon, 16 Sep 2019 12:17:27 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4F66C196AE for ; Mon, 16 Sep 2019 12:17:27 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Mon, 16 Sep 2019 14:17:11 +0200 Message-Id: <253701572fd2805b3c4979f7ee5e0705b6f99c91.1568636165.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 8/9] conf: secret: Register VIR_AUTOPTR function for virSecretDef 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-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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 16 Sep 2019 12:17:45 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: Jiri Denemark --- src/conf/secret_conf.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/conf/secret_conf.h b/src/conf/secret_conf.h index de1c28e187..7cfcfc8a60 100644 --- a/src/conf/secret_conf.h +++ b/src/conf/secret_conf.h @@ -35,6 +35,8 @@ struct _virSecretDef { }; void virSecretDefFree(virSecretDefPtr def); +VIR_DEFINE_AUTOPTR_FUNC(virSecretDef, virSecretDefFree); + virSecretDefPtr virSecretDefParseString(const char *xml); virSecretDefPtr virSecretDefParseFile(const char *filename); char *virSecretDefFormat(const virSecretDef *def); --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 23:09:08 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 ARC-Seal: i=1; a=rsa-sha256; t=1568636271; cv=none; d=zoho.com; s=zohoarc; b=X+6qSBVfWlpeHVxSzBxIIG6PoCGslDB+v1tztrfUlfcoOvNCKH/a+Zr7zq4XQbbBQpGOA87I2nbPKXct8Ja7SV+OomfCey/IAFyby3UYWNuUDIAjJEeDHw//JAJpcJwhmn6vJcqeo4/io1rqp7wwq4NEHK6Sk2OePZx/2U8vt2g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568636271; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=sMCkw9SzFnmC6ArAD/BocV51EI5m4vb8OKtPA/nj04Q=; b=ZS3OCiMHmXoZ9lPG0EmIy7ki4h42Ad/L16XrSoG1QuuX9UZz2xbmrvVjM7SPUGxjTtPUgJEIWHvgpy1ANv5rsUVgvYDByWfl7T457ef7nwedUh9CGqXjDHcbZPcKcQFJPaGa3nm7bbkskrxmB/SZ2KRzS1L/f3asB1A/M0ktQ/o= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1568636271371665.2392670943506; Mon, 16 Sep 2019 05:17:51 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3E29C8A1C95; Mon, 16 Sep 2019 12:17: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 183B56012C; Mon, 16 Sep 2019 12:17: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 CF749180BA9B; Mon, 16 Sep 2019 12:17:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8GCHSgh024562 for ; Mon, 16 Sep 2019 08:17:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9615F196AE; Mon, 16 Sep 2019 12:17:28 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1FAEE4115 for ; Mon, 16 Sep 2019 12:17:27 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Mon, 16 Sep 2019 14:17:12 +0200 Message-Id: <39e980ad75e4597282e1bee8a93fedb812feca07.1568636165.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 9/9] conf: secret: Refactor cleanup in secretXMLParseNode 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-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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.69]); Mon, 16 Sep 2019 12:17:50 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Use VIR_AUTO* for temporary locals and get rid of the 'cleanup' label. Signed-off-by: Peter Krempa Reviewed-by: Jiri Denemark --- src/conf/secret_conf.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/src/conf/secret_conf.c b/src/conf/secret_conf.c index a7691da7b5..da61c6917e 100644 --- a/src/conf/secret_conf.c +++ b/src/conf/secret_conf.c @@ -131,33 +131,33 @@ virSecretDefParseUsage(xmlXPathContextPtr ctxt, static virSecretDefPtr secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root) { - xmlXPathContextPtr ctxt =3D NULL; - virSecretDefPtr def =3D NULL, ret =3D NULL; - char *prop =3D NULL; - char *uuidstr =3D NULL; + VIR_AUTOPTR(xmlXPathContext) ctxt =3D NULL; + VIR_AUTOPTR(virSecretDef) def =3D NULL; + VIR_AUTOFREE(char *) prop =3D NULL; + VIR_AUTOFREE(char *) uuidstr =3D NULL; if (!virXMLNodeNameEqual(root, "secret")) { virReportError(VIR_ERR_XML_ERROR, _("unexpected root element <%s>, " "expecting "), root->name); - goto cleanup; + return NULL; } if (!(ctxt =3D virXMLXPathContextNew(xml))) - goto cleanup; + return NULL; ctxt->node =3D root; if (VIR_ALLOC(def) < 0) - goto cleanup; + return NULL; prop =3D virXPathString("string(./@ephemeral)", ctxt); if (prop !=3D NULL) { if (virStringParseYesNo(prop, &def->isephemeral) < 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("invalid value of 'ephemeral'")); - goto cleanup; + return NULL; } VIR_FREE(prop); } @@ -167,7 +167,7 @@ secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root) if (virStringParseYesNo(prop, &def->isprivate) < 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("invalid value of 'private'")); - goto cleanup; + return NULL; } VIR_FREE(prop); } @@ -177,13 +177,13 @@ secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root) if (virUUIDGenerate(def->uuid) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Failed to generate UUID")); - goto cleanup; + return NULL; } } else { if (virUUIDParse(uuidstr, def->uuid) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("malformed uuid element")); - goto cleanup; + return NULL; } VIR_FREE(uuidstr); } @@ -191,15 +191,9 @@ secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root) def->description =3D virXPathString("string(./description)", ctxt); if (virXPathNode("./usage", ctxt) !=3D NULL && virSecretDefParseUsage(ctxt, def) < 0) - goto cleanup; - VIR_STEAL_PTR(ret, def); - - cleanup: - VIR_FREE(prop); - VIR_FREE(uuidstr); - virSecretDefFree(def); - xmlXPathFreeContext(ctxt); - return ret; + return NULL; + + VIR_RETURN_PTR(def); } static virSecretDefPtr --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list