From nobody Tue May 7 12:17:38 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1550843600668402.31085816772963; Fri, 22 Feb 2019 05:53:20 -0800 (PST) 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 8FF6766986; Fri, 22 Feb 2019 13:53:18 +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 58CB1282FD; Fri, 22 Feb 2019 13:53:18 +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 09EB5247EF; Fri, 22 Feb 2019 13:53:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1KEl1Ff021318 for ; Wed, 20 Feb 2019 09:47:01 -0500 Received: by smtp.corp.redhat.com (Postfix) id 89F08183C8; Wed, 20 Feb 2019 14:47:01 +0000 (UTC) Received: from libvirt-fedora-29.redhat.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0C16E226F1; Wed, 20 Feb 2019 14:47:00 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Wed, 20 Feb 2019 09:46:56 -0500 Message-Id: <20190220144659.7445-2-jferlan@redhat.com> In-Reply-To: <20190220144659.7445-1-jferlan@redhat.com> References: <20190220144659.7445-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/4] conf: Use VIR_STEAL_PTR in domain_conf 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]); Fri, 22 Feb 2019 13:53:19 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Make usage of VIR_STEAL_PTR in preparation for some autofree mods. Signed-off-by: John Ferlan Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 162 ++++++++++++++--------------------------- 1 file changed, 55 insertions(+), 107 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 56c437ca0a..ceeb247ef4 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1596,8 +1596,7 @@ virDomainVcpuDefNew(virDomainXMLOptionPtr xmlopt) if (VIR_ALLOC(ret) < 0) goto cleanup; =20 - ret->privateData =3D priv; - priv =3D NULL; + VIR_STEAL_PTR(ret->privateData, priv); =20 cleanup: virObjectUnref(priv); @@ -6242,10 +6241,8 @@ virDomainDefValidateAliases(const virDomainDef *def, &data) < 0) goto cleanup; =20 - if (aliases) { - *aliases =3D data.aliases; - data.aliases =3D NULL; - } + if (aliases) + VIR_STEAL_PTR(*aliases, data.aliases); =20 ret =3D 0; cleanup: @@ -7798,8 +7795,7 @@ virDomainHostdevSubsysSCSIVHostDefParseXML(xmlNodePtr= sourcenode, virReportError(VIR_ERR_XML_ERROR, "%s", _("malformed 'wwpn' va= lue")); goto cleanup; } - hostsrc->wwpn =3D wwpn; - wwpn =3D NULL; + VIR_STEAL_PTR(hostsrc->wwpn, wwpn); break; case VIR_DOMAIN_HOSTDEV_SUBSYS_SCSI_HOST_PROTOCOL_TYPE_NONE: case VIR_DOMAIN_HOSTDEV_SUBSYS_SCSI_HOST_PROTOCOL_TYPE_LAST: @@ -8526,8 +8522,7 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt, goto error; } =20 - seclabel->label =3D p; - p =3D NULL; + VIR_STEAL_PTR(seclabel->label, p); } =20 /* Only parse imagelabel, if requested live XML with relabeling */ @@ -8541,16 +8536,14 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt, "%s", _("security imagelabel is missing")); goto error; } - seclabel->imagelabel =3D p; - p =3D NULL; + VIR_STEAL_PTR(seclabel->imagelabel, p); } =20 /* Only parse baselabel for dynamic label type */ if (seclabel->type =3D=3D VIR_DOMAIN_SECLABEL_DYNAMIC) { p =3D virXPathStringLimit("string(./baselabel[1])", VIR_SECURITY_LABEL_BUFLEN-1, ctxt); - seclabel->baselabel =3D p; - p =3D NULL; + VIR_STEAL_PTR(seclabel->baselabel, p); } =20 return seclabel; @@ -8844,10 +8837,9 @@ virDomainLeaseDefParseXML(xmlNodePtr node) goto error; } =20 - def->key =3D key; - def->lockspace =3D lockspace; - def->path =3D path; - path =3D key =3D lockspace =3D NULL; + VIR_STEAL_PTR(def->key, key); + VIR_STEAL_PTR(def->lockspace, lockspace); + VIR_STEAL_PTR(def->path, path); =20 cleanup: VIR_FREE(lockspace); @@ -8901,8 +8893,7 @@ virDomainDiskSourcePoolDefParse(xmlNodePtr node, goto cleanup; } =20 - *srcpool =3D source; - source =3D NULL; + VIR_STEAL_PTR(*srcpool, source); ret =3D 0; =20 cleanup: @@ -10144,22 +10135,16 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xm= lopt, def->startupPolicy =3D val; } =20 - def->dst =3D target; - target =3D NULL; + VIR_STEAL_PTR(def->dst, target); if (authdef) VIR_STEAL_PTR(def->src->auth, authdef); if (encryption) VIR_STEAL_PTR(def->src->encryption, encryption); - def->domain_name =3D domain_name; - domain_name =3D NULL; - def->serial =3D serial; - serial =3D NULL; - def->wwn =3D wwn; - wwn =3D NULL; - def->vendor =3D vendor; - vendor =3D NULL; - def->product =3D product; - product =3D NULL; + VIR_STEAL_PTR(def->domain_name, domain_name); + VIR_STEAL_PTR(def->serial, serial); + VIR_STEAL_PTR(def->wwn, wwn); + VIR_STEAL_PTR(def->vendor, vendor); + VIR_STEAL_PTR(def->product, product); =20 if (!(flags & VIR_DOMAIN_DEF_PARSE_DISK_SOURCE)) { if (virDomainDiskBackingStoreParse(ctxt, def->src, flags, xmlopt) = < 0) @@ -11004,10 +10989,8 @@ virDomainFSDefParseXML(virDomainXMLOptionPtr xmlop= t, goto error; } =20 - def->src->path =3D source; - source =3D NULL; - def->dst =3D target; - target =3D NULL; + VIR_STEAL_PTR(def->src->path, source); + VIR_STEAL_PTR(def->dst, target); =20 if (virDomainDeviceInfoParseXML(xmlopt, node, &def->info, flags) < 0) goto error; @@ -11196,8 +11179,7 @@ virDomainActualNetDefParseXML(xmlNodePtr node, if (vlanNode && virNetDevVlanParse(vlanNode, ctxt, &actual->vlan) < 0) goto error; =20 - *def =3D actual; - actual =3D NULL; + VIR_STEAL_PTR(*def, actual); ret =3D 0; error: VIR_FREE(type); @@ -11604,8 +11586,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlop= t, _("Model name contains invalid characters")); goto error; } - def->model =3D model; - model =3D NULL; + VIR_STEAL_PTR(def->model, model); } =20 switch (def->type) { @@ -11616,12 +11597,9 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlo= pt, "specified with = ")); goto error; } - def->data.network.name =3D network; - network =3D NULL; - def->data.network.portgroup =3D portgroup; - portgroup =3D NULL; - def->data.network.actual =3D actual; - actual =3D NULL; + VIR_STEAL_PTR(def->data.network.name, network); + VIR_STEAL_PTR(def->data.network.portgroup, portgroup); + VIR_STEAL_PTR(def->data.network.actual, actual); break; =20 case VIR_DOMAIN_NET_TYPE_VHOSTUSER: @@ -11667,8 +11645,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlop= t, goto error; =20 def->data.vhostuser->type =3D VIR_DOMAIN_CHR_TYPE_UNIX; - def->data.vhostuser->data.nix.path =3D vhostuser_path; - vhostuser_path =3D NULL; + VIR_STEAL_PTR(def->data.vhostuser->data.nix.path, vhostuser_path); =20 if (STREQ(vhostuser_mode, "server")) { def->data.vhostuser->data.nix.listen =3D true; @@ -11697,8 +11674,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlop= t, "specified with "= )); goto error; } - def->data.bridge.brname =3D bridge; - bridge =3D NULL; + VIR_STEAL_PTR(def->data.bridge.brname, bridge); break; =20 case VIR_DOMAIN_NET_TYPE_CLIENT: @@ -11728,8 +11704,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlop= t, goto error; } } else { - def->data.socket.address =3D address; - address =3D NULL; + VIR_STEAL_PTR(def->data.socket.address, address); } =20 if (def->type !=3D VIR_DOMAIN_NET_TYPE_UDP) @@ -11754,8 +11729,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlop= t, "specified with socket interface")); goto error; } else { - def->data.socket.localaddr =3D localaddr; - localaddr =3D NULL; + VIR_STEAL_PTR(def->data.socket.localaddr, localaddr); } break; =20 @@ -11766,8 +11740,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlop= t, "with ")); goto error; } - def->data.internal.name =3D internal; - internal =3D NULL; + VIR_STEAL_PTR(def->data.internal.name, internal); break; =20 case VIR_DOMAIN_NET_TYPE_DIRECT: @@ -11789,8 +11762,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlop= t, def->data.direct.mode =3D VIR_NETDEV_MACVLAN_MODE_VEPA; } =20 - def->data.direct.linkdev =3D dev; - dev =3D NULL; + VIR_STEAL_PTR(def->data.direct.linkdev, dev); =20 if (ifname && flags & VIR_DOMAIN_DEF_PARSE_INACTIVE && @@ -11832,26 +11804,16 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xml= opt, ctxt, &def->guestIP) < 0) goto error; =20 - if (script !=3D NULL) { - def->script =3D script; - script =3D NULL; - } - if (domain_name !=3D NULL) { - def->domain_name =3D domain_name; - domain_name =3D NULL; - } - if (ifname !=3D NULL) { - def->ifname =3D ifname; - ifname =3D NULL; - } - if (ifname_guest !=3D NULL) { - def->ifname_guest =3D ifname_guest; - ifname_guest =3D NULL; - } - if (ifname_guest_actual !=3D NULL) { - def->ifname_guest_actual =3D ifname_guest_actual; - ifname_guest_actual =3D NULL; - } + if (script !=3D NULL) + VIR_STEAL_PTR(def->script, script); + if (domain_name !=3D NULL) + VIR_STEAL_PTR(def->domain_name, domain_name); + if (ifname !=3D NULL) + VIR_STEAL_PTR(def->ifname, ifname); + if (ifname_guest !=3D NULL) + VIR_STEAL_PTR(def->ifname_guest, ifname_guest); + if (ifname_guest_actual !=3D NULL) + VIR_STEAL_PTR(def->ifname_guest_actual, ifname_guest_actual); =20 if (def->type !=3D VIR_DOMAIN_NET_TYPE_HOSTDEV && virDomainNetIsVirtioModel(def)) { @@ -12051,8 +12013,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlop= t, def->driver.virtio.guest.ufo =3D val; } } - def->backend.vhost =3D vhost_path; - vhost_path =3D NULL; + VIR_STEAL_PTR(def->backend.vhost, vhost_path); } =20 def->linkstate =3D VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DEFAULT; @@ -12070,10 +12031,8 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlo= pt, case VIR_DOMAIN_NET_TYPE_ETHERNET: case VIR_DOMAIN_NET_TYPE_NETWORK: case VIR_DOMAIN_NET_TYPE_BRIDGE: - def->filter =3D filter; - filter =3D NULL; - def->filterparams =3D filterparams; - filterparams =3D NULL; + VIR_STEAL_PTR(def->filter, filter); + VIR_STEAL_PTR(def->filterparams, filterparams); break; case VIR_DOMAIN_NET_TYPE_USER: case VIR_DOMAIN_NET_TYPE_VHOSTUSER: @@ -13127,9 +13086,8 @@ virDomainTPMDefParseXML(virDomainXMLOptionPtr xmlop= t, path =3D virXPathString("string(./backend/device/@path)", ctxt); if (!path && VIR_STRDUP(path, VIR_DOMAIN_TPM_DEFAULT_DEVICE) < 0) goto error; - def->data.passthrough.source.data.file.path =3D path; + VIR_STEAL_PTR(def->data.passthrough.source.data.file.path, path); def->data.passthrough.source.type =3D VIR_DOMAIN_CHR_TYPE_DEV; - path =3D NULL; break; case VIR_DOMAIN_TPM_TYPE_EMULATOR: break; @@ -13694,8 +13652,7 @@ virDomainGraphicsListenDefParseXML(virDomainGraphic= sListenDefPtr def, (def->type =3D=3D VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS || (def->type =3D=3D VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_NETWORK && !(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)))) { - def->address =3D address; - address =3D NULL; + VIR_STEAL_PTR(def->address, address); } =20 if (network && network[0]) { @@ -13705,8 +13662,7 @@ virDomainGraphicsListenDefParseXML(virDomainGraphic= sListenDefPtr def, "type 'network'")); goto error; } - def->network =3D network; - network =3D NULL; + VIR_STEAL_PTR(def->network, network); } =20 if (socketPath && socketPath[0]) { @@ -13716,8 +13672,7 @@ virDomainGraphicsListenDefParseXML(virDomainGraphic= sListenDefPtr def, "type 'socket'")); goto error; } - def->socket =3D socketPath; - socketPath =3D NULL; + VIR_STEAL_PTR(def->socket, socketPath); } =20 if (fromConfig && @@ -13805,8 +13760,7 @@ virDomainGraphicsListensParseXML(virDomainGraphicsD= efPtr def, =20 if (socketPath) { newListen.type =3D VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET; - newListen.socket =3D socketPath; - socketPath =3D NULL; + VIR_STEAL_PTR(newListen.socket, socketPath); } else { newListen.type =3D VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_ADDRESS; newListen.address =3D virXMLPropString(node, "listen"); @@ -14344,7 +14298,7 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphics= DefPtr def, VIR_FREE(enable); =20 def->data.spice.gl =3D enableVal; - def->data.spice.rendernode =3D rendernode; + VIR_STEAL_PTR(def->data.spice.rendernode, rendernode); =20 } else if (virXMLNodeNameEqual(cur, "mouse")) { char *mode =3D virXMLPropString(cur, "mode"); @@ -14993,8 +14947,7 @@ virSysinfoBIOSParseXML(xmlNodePtr node, def =3D NULL; } =20 - *bios =3D def; - def =3D NULL; + VIR_STEAL_PTR(*bios, def); ret =3D 0; cleanup: virSysinfoBIOSDefFree(def); @@ -15067,8 +15020,7 @@ virSysinfoSystemParseXML(xmlNodePtr node, def =3D NULL; } =20 - *sysdef =3D def; - def =3D NULL; + VIR_STEAL_PTR(*sysdef, def); ret =3D 0; cleanup: virSysinfoSystemDefFree(def); @@ -15119,9 +15071,8 @@ virSysinfoBaseBoardParseXML(xmlXPathContextPtr ctxt, } } =20 - *baseBoard =3D boards; + VIR_STEAL_PTR(*baseBoard, boards); *nbaseBoard =3D nboards; - boards =3D NULL; ret =3D 0; cleanup: VIR_FREE(boards); @@ -15157,8 +15108,7 @@ virSysinfoOEMStringsParseXML(xmlXPathContextPtr ctx= t, for (i =3D 0; i < nstrings; i++) def->values[i] =3D virXMLNodeContentString(strings[i]); =20 - *oem =3D def; - def =3D NULL; + VIR_STEAL_PTR(*oem, def); ret =3D 0; cleanup: VIR_FREE(strings); @@ -15201,8 +15151,7 @@ virSysinfoChassisParseXML(xmlNodePtr node, def =3D NULL; } =20 - *chassisdef =3D def; - def =3D NULL; + VIR_STEAL_PTR(*chassisdef, def); ret =3D 0; cleanup: virSysinfoChassisDefFree(def); @@ -18431,8 +18380,7 @@ virDomainIOThreadPinDefParseXML(xmlNodePtr node, goto cleanup; } =20 - iothrid->cpumask =3D cpumask; - cpumask =3D NULL; + VIR_STEAL_PTR(iothrid->cpumask, cpumask); ret =3D 0; =20 cleanup: --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 12:17:38 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1550674034468824.1530308335316; Wed, 20 Feb 2019 06:47:14 -0800 (PST) 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 B567DB8392; Wed, 20 Feb 2019 14:47:07 +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 3E5D05D706; Wed, 20 Feb 2019 14:47:07 +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 BB3B5181A00C; Wed, 20 Feb 2019 14:47:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1KEl2Wk021324 for ; Wed, 20 Feb 2019 09:47:02 -0500 Received: by smtp.corp.redhat.com (Postfix) id 63899611B6; Wed, 20 Feb 2019 14:47:02 +0000 (UTC) Received: from libvirt-fedora-29.redhat.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id C243F17976; Wed, 20 Feb 2019 14:47:01 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Wed, 20 Feb 2019 09:46:57 -0500 Message-Id: <20190220144659.7445-3-jferlan@redhat.com> In-Reply-To: <20190220144659.7445-1-jferlan@redhat.com> References: <20190220144659.7445-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/4] conf: Use VIR_AUTOPTR(virBitmap) in domain_conf 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.28]); Wed, 20 Feb 2019 14:47:11 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Let's make use of the auto __cleanup capabilities cleaning up any now unnecessary goto paths. Signed-off-by: John Ferlan --- src/conf/domain_conf.c | 53 ++++++++++++++++-------------------------- 1 file changed, 20 insertions(+), 33 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ceeb247ef4..ddcb76f05d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1803,8 +1803,8 @@ virDomainDefGetVcpuPinInfoHelper(virDomainDefPtr def, virBitmapPtr autoCpuset) { int maxvcpus =3D virDomainDefGetVcpusMax(def); - virBitmapPtr allcpumap =3D NULL; size_t i; + VIR_AUTOPTR(virBitmap) allcpumap =3D NULL; =20 if (hostcpus < 0) return -1; @@ -1831,7 +1831,6 @@ virDomainDefGetVcpuPinInfoHelper(virDomainDefPtr def, virBitmapToDataBuf(bitmap, VIR_GET_CPUMAP(cpumaps, maplen, i), map= len); } =20 - virBitmapFree(allcpumap); return i; } =20 @@ -2984,11 +2983,10 @@ static int virDomainIOThreadIDDefArrayInit(virDomainDefPtr def, unsigned int iothreads) { - int retval =3D -1; size_t i; ssize_t nxt =3D -1; virDomainIOThreadIDDefPtr iothrid =3D NULL; - virBitmapPtr thrmap =3D NULL; + VIR_AUTOPTR(virBitmap) thrmap =3D NULL; =20 /* Same value (either 0 or some number), then we have none to fill in = or * the iothreadid array was filled from the XML @@ -2998,7 +2996,7 @@ virDomainIOThreadIDDefArrayInit(virDomainDefPtr def, =20 /* iothread's are numbered starting at 1, account for that */ if (!(thrmap =3D virBitmapNew(iothreads + 1))) - goto error; + return -1; virBitmapSetAll(thrmap); =20 /* Clear 0 since we don't use it, then mark those which are @@ -3010,27 +3008,23 @@ virDomainIOThreadIDDefArrayInit(virDomainDefPtr def, =20 /* resize array */ if (VIR_REALLOC_N(def->iothreadids, iothreads) < 0) - goto error; + return -1; =20 /* Populate iothreadids[] using the set bit number from thrmap */ while (def->niothreadids < iothreads) { if ((nxt =3D virBitmapNextSetBit(thrmap, nxt)) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("failed to populate iothreadids")); - goto error; + return -1; } if (VIR_ALLOC(iothrid) < 0) - goto error; + return -1; iothrid->iothread_id =3D nxt; iothrid->autofill =3D true; def->iothreadids[def->niothreadids++] =3D iothrid; } =20 - retval =3D 0; - - error: - virBitmapFree(thrmap); - return retval; + return 0; } =20 =20 @@ -18327,9 +18321,9 @@ virDomainIOThreadPinDefParseXML(xmlNodePtr node, { int ret =3D -1; virDomainIOThreadIDDefPtr iothrid; - virBitmapPtr cpumask =3D NULL; unsigned int iothreadid; char *tmp =3D NULL; + VIR_AUTOPTR(virBitmap) cpumask =3D NULL; =20 if (!(tmp =3D virXMLPropString(node, "iothread"))) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -18385,7 +18379,6 @@ virDomainIOThreadPinDefParseXML(xmlNodePtr node, =20 cleanup: VIR_FREE(tmp); - virBitmapFree(cpumask); return ret; } =20 @@ -18397,8 +18390,9 @@ virDomainIOThreadPinDefParseXML(xmlNodePtr node, static virBitmapPtr virDomainEmulatorPinDefParseXML(xmlNodePtr node) { - virBitmapPtr def =3D NULL; + virBitmapPtr ret =3D NULL; char *tmp =3D NULL; + VIR_AUTOPTR(virBitmap) def =3D NULL; =20 if (!(tmp =3D virXMLPropString(node, "cpuset"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -18412,14 +18406,14 @@ virDomainEmulatorPinDefParseXML(xmlNodePtr node) if (virBitmapIsAllClear(def)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Invalid value of 'cpuset': %s"), tmp); - virBitmapFree(def); - def =3D NULL; goto cleanup; } =20 + VIR_STEAL_PTR(ret, def); + cleanup: VIR_FREE(tmp); - return def; + return ret; } =20 =20 @@ -18778,35 +18772,30 @@ virDomainThreadSchedParseHelper(xmlNodePtr node, virDomainDefPtr def) { ssize_t next =3D -1; - virBitmapPtr map =3D NULL; virDomainThreadSchedParamPtr sched; virProcessSchedPolicy policy; int priority; - int ret =3D -1; + VIR_AUTOPTR(virBitmap) map =3D NULL; =20 if (!(map =3D virDomainSchedulerParse(node, name, &policy, &priority))) - goto cleanup; + return -1; =20 while ((next =3D virBitmapNextSetBit(map, next)) > -1) { if (!(sched =3D func(def, next))) - goto cleanup; + return -1; =20 if (sched->policy !=3D VIR_PROC_POLICY_NONE) { virReportError(VIR_ERR_XML_DETAIL, _("%ssched attributes 'vcpus' must not overlap"= ), name); - goto cleanup; + return -1; } =20 sched->policy =3D policy; sched->priority =3D priority; } =20 - ret =3D 0; - - cleanup: - virBitmapFree(map); - return ret; + return 0; } =20 =20 @@ -19509,12 +19498,12 @@ virDomainCachetuneDefParse(virDomainDefPtr def, { xmlNodePtr oldnode =3D ctxt->node; xmlNodePtr *nodes =3D NULL; - virBitmapPtr vcpus =3D NULL; virResctrlAllocPtr alloc =3D NULL; virDomainResctrlDefPtr resctrl =3D NULL; ssize_t i =3D 0; int n; int ret =3D -1; + VIR_AUTOPTR(virBitmap) vcpus =3D NULL; =20 ctxt->node =3D node; =20 @@ -19574,7 +19563,6 @@ virDomainCachetuneDefParse(virDomainDefPtr def, ctxt->node =3D oldnode; virDomainResctrlDefFree(resctrl); virObjectUnref(alloc); - virBitmapFree(vcpus); VIR_FREE(nodes); return ret; } @@ -19728,9 +19716,9 @@ virDomainMemorytuneDefParse(virDomainDefPtr def, { xmlNodePtr oldnode =3D ctxt->node; xmlNodePtr *nodes =3D NULL; - virBitmapPtr vcpus =3D NULL; virResctrlAllocPtr alloc =3D NULL; virDomainResctrlDefPtr resctrl =3D NULL; + VIR_AUTOPTR(virBitmap) vcpus =3D NULL; =20 ssize_t i =3D 0; int n; @@ -19789,7 +19777,6 @@ virDomainMemorytuneDefParse(virDomainDefPtr def, ctxt->node =3D oldnode; virDomainResctrlDefFree(resctrl); virObjectUnref(alloc); - virBitmapFree(vcpus); VIR_FREE(nodes); return ret; } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 12:17:38 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1550674043994463.53840444158857; Wed, 20 Feb 2019 06:47:23 -0800 (PST) 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 DA8D013BAAD; Wed, 20 Feb 2019 14:47:21 +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 7B2E817B15; Wed, 20 Feb 2019 14:47:21 +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 29DC83D387; Wed, 20 Feb 2019 14:47:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1KEl2sw021332 for ; Wed, 20 Feb 2019 09:47:02 -0500 Received: by smtp.corp.redhat.com (Postfix) id D481D611B6; Wed, 20 Feb 2019 14:47:02 +0000 (UTC) Received: from libvirt-fedora-29.redhat.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6B526611C0; Wed, 20 Feb 2019 14:47:02 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Wed, 20 Feb 2019 09:46:58 -0500 Message-Id: <20190220144659.7445-4-jferlan@redhat.com> In-Reply-To: <20190220144659.7445-1-jferlan@redhat.com> References: <20190220144659.7445-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/4] conf: Fix XML ctxt swap in virDomainNetDefParseXML 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.39]); Wed, 20 Feb 2019 14:47:22 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Alter the logic to return @tmpnode to ctxt->node in both the error and non-error path when calling virDomainNetIPInfoParseXML. Signed-off-by: John Ferlan --- src/conf/domain_conf.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ddcb76f05d..d550b467f7 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11356,10 +11356,11 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xml= opt, xmlNodePtr tmpnode =3D ctxt->node; =20 ctxt->node =3D cur; - if (virDomainNetIPInfoParseXML(_("interface host IP"), - ctxt, &def->hostIP) < 0) - goto error; + rv =3D virDomainNetIPInfoParseXML(_("interface host IP"), + ctxt, &def->hostIP); ctxt->node =3D tmpnode; + if (rv < 0) + goto error; } if (!macaddr && virXMLNodeNameEqual(cur, "mac")) { macaddr =3D virXMLPropString(cur, "address"); --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 12:17:38 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1550843605789371.77004486461715; Fri, 22 Feb 2019 05:53:25 -0800 (PST) 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 068CD3001D5F; Fri, 22 Feb 2019 13:53:23 +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 C990C5D71D; Fri, 22 Feb 2019 13:53:22 +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 76B00247E3; Fri, 22 Feb 2019 13:53:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1KEl40w021366 for ; Wed, 20 Feb 2019 09:47:04 -0500 Received: by smtp.corp.redhat.com (Postfix) id 48EF56918D; Wed, 20 Feb 2019 14:47:04 +0000 (UTC) Received: from libvirt-fedora-29.redhat.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 32CBC691A5; Wed, 20 Feb 2019 14:47:02 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Wed, 20 Feb 2019 09:46:59 -0500 Message-Id: <20190220144659.7445-5-jferlan@redhat.com> In-Reply-To: <20190220144659.7445-1-jferlan@redhat.com> References: <20190220144659.7445-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/4] conf: Use VIR_AUTOFREE in domain_conf 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.42]); Fri, 22 Feb 2019 13:53:24 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Let's make use of the auto __cleanup capabilities cleaning up any now unnecessary goto paths. Signed-off-by: John Ferlan --- src/conf/domain_conf.c | 1890 ++++++++++++++-------------------------- 1 file changed, 660 insertions(+), 1230 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index d550b467f7..bd30943684 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1099,34 +1099,33 @@ static int virDomainKeyWrapCipherDefParseXML(virDomainKeyWrapDefPtr keywrap, xmlNodePtr node) { - char *name =3D NULL; - char *state =3D NULL; int state_type; int name_type; - int ret =3D -1; + VIR_AUTOFREE(char *) name =3D NULL; + VIR_AUTOFREE(char *) state =3D NULL; =20 if (!(name =3D virXMLPropString(node, "name"))) { virReportError(VIR_ERR_CONF_SYNTAX, "%s", _("missing name for cipher")); - goto cleanup; + return -1; } =20 if ((name_type =3D virDomainKeyWrapCipherNameTypeFromString(name)) < 0= ) { virReportError(VIR_ERR_CONF_SYNTAX, _("%s is not a supported cipher name"), name); - goto cleanup; + return -1; } =20 if (!(state =3D virXMLPropString(node, "state"))) { virReportError(VIR_ERR_CONF_SYNTAX, _("missing state for cipher named %s"), name); - goto cleanup; + return -1; } =20 if ((state_type =3D virTristateSwitchTypeFromString(state)) < 0) { virReportError(VIR_ERR_CONF_SYNTAX, _("%s is not a supported cipher state"), state); - goto cleanup; + return -1; } =20 switch ((virDomainKeyWrapCipherName) name_type) { @@ -1137,7 +1136,7 @@ virDomainKeyWrapCipherDefParseXML(virDomainKeyWrapDef= Ptr keywrap, "one cipher node with name %s"), virDomainKeyWrapCipherNameTypeToString(name_typ= e)); =20 - goto cleanup; + return -1; } keywrap->aes =3D state_type; break; @@ -1149,7 +1148,7 @@ virDomainKeyWrapCipherDefParseXML(virDomainKeyWrapDef= Ptr keywrap, "one cipher node with name %s"), virDomainKeyWrapCipherNameTypeToString(name_typ= e)); =20 - goto cleanup; + return -1; } keywrap->dea =3D state_type; break; @@ -1158,12 +1157,7 @@ virDomainKeyWrapCipherDefParseXML(virDomainKeyWrapDe= fPtr keywrap, break; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(name); - VIR_FREE(state); - return ret; + return 0; } =20 static int @@ -1171,8 +1165,8 @@ virDomainKeyWrapDefParseXML(virDomainDefPtr def, xmlX= PathContextPtr ctxt) { size_t i; int ret =3D -1; - xmlNodePtr *nodes =3D NULL; int n; + VIR_AUTOFREE(xmlNodePtr *) nodes =3D NULL; =20 if ((n =3D virXPathNodeSet("./keywrap/cipher", ctxt, &nodes)) < 0) return n; @@ -1194,7 +1188,6 @@ virDomainKeyWrapDefParseXML(virDomainDefPtr def, xmlX= PathContextPtr ctxt) cleanup: if (ret < 0) VIR_FREE(def->keywrap); - VIR_FREE(nodes); return ret; } =20 @@ -1267,10 +1260,9 @@ static int virDomainVirtioOptionsParseXML(xmlNodePtr driver, virDomainVirtioOptionsPtr *virtio) { - char *str =3D NULL; - int ret =3D -1; int val; virDomainVirtioOptionsPtr res; + VIR_AUTOFREE(char *) str =3D NULL; =20 if (*virtio || !driver) return 0; @@ -1284,7 +1276,7 @@ virDomainVirtioOptionsParseXML(xmlNodePtr driver, if ((val =3D virTristateSwitchTypeFromString(str)) <=3D 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("invalid iommu value")); - goto cleanup; + return -1; } res->iommu =3D val; } @@ -1294,16 +1286,12 @@ virDomainVirtioOptionsParseXML(xmlNodePtr driver, if ((val =3D virTristateSwitchTypeFromString(str)) <=3D 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("invalid ats value")); - goto cleanup; + return -1; } res->ats =3D val; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(str); - return ret; + return 0; } =20 =20 @@ -1344,8 +1332,8 @@ static int virDomainBlkioDeviceParseXML(xmlNodePtr root, virBlkioDevicePtr dev) { - char *c =3D NULL; xmlNodePtr node; + VIR_AUTOFREE(char *) c =3D NULL; =20 node =3D root->children; while (node) { @@ -1410,7 +1398,6 @@ virDomainBlkioDeviceParseXML(xmlNodePtr root, return 0; =20 error: - VIR_FREE(c); VIR_FREE(dev->path); return -1; } @@ -5338,8 +5325,7 @@ virDomainDefCollectBootOrder(virDomainDefPtr def ATTR= IBUTE_UNUSED, void *data) { virHashTablePtr bootHash =3D data; - char *order =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) order =3D NULL; =20 if (info->bootIndex =3D=3D 0) return 0; @@ -5353,23 +5339,19 @@ virDomainDefCollectBootOrder(virDomainDefPtr def AT= TRIBUTE_UNUSED, return 0; } if (virAsprintf(&order, "%u", info->bootIndex) < 0) - goto cleanup; + return -1; =20 if (virHashLookup(bootHash, order)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("boot order '%s' used for more than one device"), order); - goto cleanup; + return -1; } =20 if (virHashAddEntry(bootHash, order, (void *) 1) < 0) - goto cleanup; - - ret =3D 0; + return -1; =20 - cleanup: - VIR_FREE(order); - return ret; + return 0; } =20 =20 @@ -6889,8 +6871,7 @@ static int virDomainDeviceUSBMasterParseXML(xmlNodePtr node, virDomainDeviceUSBMasterPtr master) { - char *startport; - int ret =3D -1; + VIR_AUTOFREE(char *) startport =3D NULL; =20 memset(master, 0, sizeof(*master)); =20 @@ -6900,28 +6881,23 @@ virDomainDeviceUSBMasterParseXML(xmlNodePtr node, virStrToLong_ui(startport, NULL, 10, &master->startport) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot parse 'startport' attribute")); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(startport); - return ret; + return 0; } =20 static int virDomainDeviceBootParseXML(xmlNodePtr node, virDomainDeviceInfoPtr info) { - char *order; - char *loadparm =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) order =3D NULL; + VIR_AUTOFREE(char *) loadparm =3D NULL; =20 if (!(order =3D virXMLPropString(node, "order"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing boot order attribute")); - goto cleanup; + return -1; } =20 if (virStrToLong_uip(order, NULL, 10, &info->bootIndex) < 0 || @@ -6929,7 +6905,7 @@ virDomainDeviceBootParseXML(xmlNodePtr node, virReportError(VIR_ERR_INTERNAL_ERROR, _("incorrect boot order '%s', expecting positive in= teger"), order); - goto cleanup; + return -1; } =20 loadparm =3D virXMLPropString(node, "loadparm"); @@ -6938,30 +6914,24 @@ virDomainDeviceBootParseXML(xmlNodePtr node, virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to convert loadparm '%s' to upper cas= e"), loadparm); - goto cleanup; + return -1; } =20 if (!virDomainDeviceLoadparmIsValid(info->loadparm)) { VIR_FREE(info->loadparm); - goto cleanup; + return -1; } } =20 - ret =3D 0; - - cleanup: - VIR_FREE(order); - VIR_FREE(loadparm); - return ret; + return 0; } =20 static int virDomainDeviceISAAddressParseXML(xmlNodePtr node, virDomainDeviceISAAddressPtr addr) { - int ret =3D -1; - char *iobase; - char *irq; + VIR_AUTOFREE(char *) iobase =3D NULL; + VIR_AUTOFREE(char *) irq =3D NULL; =20 memset(addr, 0, sizeof(*addr)); =20 @@ -6972,21 +6942,17 @@ virDomainDeviceISAAddressParseXML(xmlNodePtr node, virStrToLong_uip(iobase, NULL, 16, &addr->iobase) < 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Cannot parse
'iobase' attribute")); - goto cleanup; + return -1; } =20 if (irq && virStrToLong_uip(irq, NULL, 16, &addr->irq) < 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Cannot parse
'irq' attribute")); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(iobase); - VIR_FREE(irq); - return ret; + return 0; } =20 =20 @@ -6994,15 +6960,14 @@ static int virDomainDeviceDimmAddressParseXML(xmlNodePtr node, virDomainDeviceDimmAddressPtr addr) { - int ret =3D -1; - char *tmp =3D NULL; + VIR_AUTOFREE(char *) tmp =3D NULL; =20 if (!(tmp =3D virXMLPropString(node, "slot")) || virStrToLong_uip(tmp, NULL, 10, &addr->slot) < 0) { virReportError(VIR_ERR_XML_ERROR, _("invalid or missing dimm slot id '%s'"), NULLSTR(tmp)); - goto cleanup; + return -1; } VIR_FREE(tmp); =20 @@ -7010,18 +6975,11 @@ virDomainDeviceDimmAddressParseXML(xmlNodePtr node, if (virStrToLong_ullp(tmp, NULL, 16, &addr->base) < 0) { virReportError(VIR_ERR_XML_ERROR, _("invalid dimm base address '%s'"), tmp); - goto cleanup; + return -1; } - - VIR_FREE(tmp); } =20 - ret =3D 0; - - cleanup: - VIR_FREE(tmp); - - return ret; + return 0; } =20 =20 @@ -7029,57 +6987,56 @@ static int virDomainDeviceAddressParseXML(xmlNodePtr address, virDomainDeviceInfoPtr info) { - int ret =3D -1; - char *type =3D virXMLPropString(address, "type"); + VIR_AUTOFREE(char *) type =3D virXMLPropString(address, "type"); =20 if (type) { if ((info->type =3D virDomainDeviceAddressTypeFromString(type)) <= =3D 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown address type '%s'"), type); - goto cleanup; + return -1; } } else { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("No type specified for device address")); - goto cleanup; + return -1; } =20 switch ((virDomainDeviceAddressType) info->type) { case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI: if (virPCIDeviceAddressParseXML(address, &info->addr.pci) < 0) - goto cleanup; + return -1; break; =20 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE: if (virDomainDeviceDriveAddressParseXML(address, &info->addr.drive= ) < 0) - goto cleanup; + return -1; break; =20 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_SERIAL: if (virDomainDeviceVirtioSerialAddressParseXML (address, &info->addr.vioserial) < 0) - goto cleanup; + return -1; break; =20 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCID: if (virDomainDeviceCcidAddressParseXML(address, &info->addr.ccid) = < 0) - goto cleanup; + return -1; break; =20 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB: if (virDomainDeviceUSBAddressParseXML(address, &info->addr.usb) < = 0) - goto cleanup; + return -1; break; =20 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO: if (virDomainDeviceSpaprVioAddressParseXML(address, &info->addr.sp= aprvio) < 0) - goto cleanup; + return -1; break; =20 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW: if (virDomainDeviceCCWAddressParseXML (address, &info->addr.ccw) < 0) - goto cleanup; + return -1; break; =20 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO: @@ -7087,17 +7044,17 @@ virDomainDeviceAddressParseXML(xmlNodePtr address, =20 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA: if (virDomainDeviceISAAddressParseXML(address, &info->addr.isa) < = 0) - goto cleanup; + return -1; break; =20 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_S390: virReportError(VIR_ERR_XML_ERROR, "%s", _("virtio-s390 bus doesn't have an address")); - goto cleanup; + return -1; =20 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM: if (virDomainDeviceDimmAddressParseXML(address, &info->addr.dimm) = < 0) - goto cleanup; + return -1; break; =20 case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE: @@ -7105,10 +7062,7 @@ virDomainDeviceAddressParseXML(xmlNodePtr address, break; } =20 - ret =3D 0; - cleanup: - VIR_FREE(type); - return ret; + return 0; } =20 =20 @@ -7138,11 +7092,11 @@ virDomainDeviceInfoParseXML(virDomainXMLOptionPtr x= mlopt ATTRIBUTE_UNUSED, xmlNodePtr alias =3D NULL; xmlNodePtr boot =3D NULL; xmlNodePtr rom =3D NULL; - char *type =3D NULL; - char *romenabled =3D NULL; - char *rombar =3D NULL; - char *aliasStr =3D NULL; int ret =3D -1; + VIR_AUTOFREE(char *) type =3D NULL; + VIR_AUTOFREE(char *) romenabled =3D NULL; + VIR_AUTOFREE(char *) rombar =3D NULL; + VIR_AUTOFREE(char *) aliasStr =3D NULL; =20 virDomainDeviceInfoClear(info); =20 @@ -7224,10 +7178,6 @@ virDomainDeviceInfoParseXML(virDomainXMLOptionPtr xm= lopt ATTRIBUTE_UNUSED, cleanup: if (ret < 0) virDomainDeviceInfoClear(info); - VIR_FREE(type); - VIR_FREE(rombar); - VIR_FREE(romenabled); - VIR_FREE(aliasStr); return ret; } =20 @@ -7256,9 +7206,9 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr node, int ret =3D -1; bool got_product, got_vendor; xmlNodePtr cur; - char *startupPolicy =3D NULL; - char *autoAddress; virDomainHostdevSubsysUSBPtr usbsrc =3D &def->source.subsys.u.usb; + VIR_AUTOFREE(char *) startupPolicy =3D NULL; + VIR_AUTOFREE(char *) autoAddress =3D NULL; =20 if ((startupPolicy =3D virXMLPropString(node, "startupPolicy"))) { def->startupPolicy =3D @@ -7267,16 +7217,13 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr nod= e, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unknown startup policy '%s'"), startupPolicy); - VIR_FREE(startupPolicy); goto out; } - VIR_FREE(startupPolicy); } =20 if ((autoAddress =3D virXMLPropString(node, "autoAddress"))) { if (STREQ(autoAddress, "yes")) usbsrc->autoAddress =3D true; - VIR_FREE(autoAddress); } =20 /* Product can validly be 0, so we need some extra help to determine @@ -7288,24 +7235,22 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr nod= e, while (cur !=3D NULL) { if (cur->type =3D=3D XML_ELEMENT_NODE) { if (virXMLNodeNameEqual(cur, "vendor")) { - char *vendor =3D virXMLPropString(cur, "id"); + VIR_AUTOFREE(char *) vendor =3D virXMLPropString(cur, "id"= ); =20 if (vendor) { got_vendor =3D true; if (virStrToLong_ui(vendor, NULL, 0, &usbsrc->vendor) = < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse vendor id %s"), ven= dor); - VIR_FREE(vendor); goto out; } - VIR_FREE(vendor); } else { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("usb vendor needs id")); goto out; } } else if (virXMLNodeNameEqual(cur, "product")) { - char* product =3D virXMLPropString(cur, "id"); + VIR_AUTOFREE(char *) product =3D virXMLPropString(cur, "id= "); =20 if (product) { got_product =3D true; @@ -7314,27 +7259,24 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr nod= e, virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse product %s"), product); - VIR_FREE(product); goto out; } - VIR_FREE(product); } else { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("usb product needs id")); goto out; } } else if (virXMLNodeNameEqual(cur, "address")) { - char *bus, *device; + VIR_AUTOFREE(char *) bus =3D NULL; + VIR_AUTOFREE(char *) device =3D NULL; =20 bus =3D virXMLPropString(cur, "bus"); if (bus) { if (virStrToLong_ui(bus, NULL, 0, &usbsrc->bus) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse bus %s"), bus); - VIR_FREE(bus); goto out; } - VIR_FREE(bus); } else { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("usb address needs bus id")); @@ -7347,10 +7289,8 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr node, virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse device %s"), device); - VIR_FREE(device); goto out; } - VIR_FREE(device); } else { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("usb address needs device id")); @@ -7444,14 +7384,13 @@ virDomainHostdevSubsysPCIDefParseXML(xmlNodePtr nod= e, } else if ((flags & VIR_DOMAIN_DEF_PARSE_STATUS) && virXMLNodeNameEqual(cur, "state")) { /* Legacy back-compat. Don't add any more attributes here = */ - char *devaddr =3D virXMLPropString(cur, "devaddr"); + VIR_AUTOFREE(char *) devaddr =3D virXMLPropString(cur, "de= vaddr"); if (devaddr && virDomainParseLegacyDeviceAddress(devaddr, &def->info->addr.pci= ) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse devaddr parameter '%= s'"), devaddr); - VIR_FREE(devaddr); goto out; } def->info->type =3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI; @@ -7482,9 +7421,9 @@ virDomainStorageNetworkParseHost(xmlNodePtr hostnode, size_t *nhosts) { int ret =3D -1; - char *transport =3D NULL; - char *port =3D NULL; virStorageNetHostDef host; + VIR_AUTOFREE(char *) transport =3D NULL; + VIR_AUTOFREE(char *) port =3D NULL; =20 memset(&host, 0, sizeof(host)); host.transport =3D VIR_STORAGE_NET_HOST_TRANS_TCP; @@ -7538,8 +7477,6 @@ virDomainStorageNetworkParseHost(xmlNodePtr hostnode, =20 cleanup: virStorageNetHostDefClear(&host); - VIR_FREE(transport); - VIR_FREE(port); return ret; } =20 @@ -7568,11 +7505,12 @@ static int virDomainHostdevSubsysSCSIHostDefParseXML(xmlNodePtr sourcenode, virDomainHostdevSubsysSCSIPtr sc= sisrc) { - int ret =3D -1; bool got_address =3D false, got_adapter =3D false; xmlNodePtr cur; - char *bus =3D NULL, *target =3D NULL, *unit =3D NULL; virDomainHostdevSubsysSCSIHostPtr scsihostsrc =3D &scsisrc->u.host; + VIR_AUTOFREE(char *) bus =3D NULL; + VIR_AUTOFREE(char *) target =3D NULL; + VIR_AUTOFREE(char *) unit =3D NULL; =20 cur =3D sourcenode->children; while (cur !=3D NULL) { @@ -7582,7 +7520,7 @@ virDomainHostdevSubsysSCSIHostDefParseXML(xmlNodePtr = sourcenode, virReportError(VIR_ERR_XML_ERROR, "%s", _("more than one source addresses is " "specified for scsi hostdev")); - goto cleanup; + return -1; } =20 if (!(bus =3D virXMLPropString(cur, "bus")) || @@ -7591,26 +7529,26 @@ virDomainHostdevSubsysSCSIHostDefParseXML(xmlNodePt= r sourcenode, virReportError(VIR_ERR_XML_ERROR, "%s", _("'bus', 'target', and 'unit' must be = specified " "for scsi hostdev source address")); - goto cleanup; + return -1; } =20 if (virStrToLong_uip(bus, NULL, 0, &scsihostsrc->bus) < 0)= { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse bus '%s'"), bus); - goto cleanup; + return -1; } =20 if (virStrToLong_uip(target, NULL, 0, &scsihostsrc->target) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse target '%s'"), target); - goto cleanup; + return -1; } =20 if (virStrToLong_ullp(unit, NULL, 0, &scsihostsrc->unit) <= 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse unit '%s'"), unit); - goto cleanup; + return -1; } =20 got_address =3D true; @@ -7619,12 +7557,12 @@ virDomainHostdevSubsysSCSIHostDefParseXML(xmlNodePt= r sourcenode, virReportError(VIR_ERR_XML_ERROR, "%s", _("more than one adapters is specified " "for scsi hostdev source")); - goto cleanup; + return -1; } if (!(scsihostsrc->adapter =3D virXMLPropString(cur, "name= "))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("'adapter' must be specified for scsi= hostdev source")); - goto cleanup; + return -1; } =20 got_adapter =3D true; @@ -7632,7 +7570,7 @@ virDomainHostdevSubsysSCSIHostDefParseXML(xmlNodePtr = sourcenode, virReportError(VIR_ERR_XML_ERROR, _("unsupported element '%s' of scsi hostdev= source"), cur->name); - goto cleanup; + return -1; } } cur =3D cur->next; @@ -7642,15 +7580,10 @@ virDomainHostdevSubsysSCSIHostDefParseXML(xmlNodePt= r sourcenode, virReportError(VIR_ERR_XML_ERROR, "%s", _("'adapter' and 'address' must be specified for sc= si " "hostdev source")); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(bus); - VIR_FREE(target); - VIR_FREE(unit); - return ret; + return 0; } =20 static int @@ -7729,8 +7662,7 @@ virDomainHostdevSubsysSCSIDefParseXML(xmlNodePtr sour= cenode, virDomainHostdevSubsysSCSIPtr scsisr= c, xmlXPathContextPtr ctxt) { - char *protocol =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) protocol =3D NULL; =20 if ((protocol =3D virXMLPropString(sourcenode, "protocol"))) { scsisrc->protocol =3D @@ -7739,33 +7671,28 @@ virDomainHostdevSubsysSCSIDefParseXML(xmlNodePtr so= urcenode, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unknown SCSI subsystem protocol '%s'"), protocol); - goto cleanup; + return -1; } } =20 if (scsisrc->protocol =3D=3D VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISC= SI) - ret =3D virDomainHostdevSubsysSCSIiSCSIDefParseXML(sourcenode, scs= isrc, ctxt); - else - ret =3D virDomainHostdevSubsysSCSIHostDefParseXML(sourcenode, scsi= src); + return virDomainHostdevSubsysSCSIiSCSIDefParseXML(sourcenode, scsi= src, ctxt); =20 - cleanup: - VIR_FREE(protocol); - return ret; + return virDomainHostdevSubsysSCSIHostDefParseXML(sourcenode, scsisrc); } =20 static int virDomainHostdevSubsysSCSIVHostDefParseXML(xmlNodePtr sourcenode, virDomainHostdevDefPtr def) { - char *protocol =3D NULL; - char *wwpn =3D NULL; virDomainHostdevSubsysSCSIVHostPtr hostsrc =3D &def->source.subsys.u.s= csi_host; - int ret =3D -1; + VIR_AUTOFREE(char *) protocol =3D NULL; + VIR_AUTOFREE(char *) wwpn =3D NULL; =20 if (!(protocol =3D virXMLPropString(sourcenode, "protocol"))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing scsi_host subsystem protocol")); - return ret; + return -1; } =20 if ((hostsrc->protocol =3D @@ -7773,7 +7700,7 @@ virDomainHostdevSubsysSCSIVHostDefParseXML(xmlNodePtr= sourcenode, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unknown scsi_host subsystem protocol '%s'"), protocol); - goto cleanup; + return -1; } =20 switch ((virDomainHostdevSubsysSCSIHostProtocolType) hostsrc->protocol= ) { @@ -7781,13 +7708,13 @@ virDomainHostdevSubsysSCSIVHostDefParseXML(xmlNodeP= tr sourcenode, if (!(wwpn =3D virXMLPropString(sourcenode, "wwpn"))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing vhost-scsi hostdev source wwpn")); - goto cleanup; + return -1; } =20 if (!STRPREFIX(wwpn, "naa.") || !virValidateWWN(wwpn + 4)) { virReportError(VIR_ERR_XML_ERROR, "%s", _("malformed 'wwpn' va= lue")); - goto cleanup; + return -1; } VIR_STEAL_PTR(hostsrc->wwpn, wwpn); break; @@ -7796,51 +7723,43 @@ virDomainHostdevSubsysSCSIVHostDefParseXML(xmlNodeP= tr sourcenode, virReportError(VIR_ERR_XML_ERROR, _("Invalid hostdev protocol '%s'"), virDomainHostdevSubsysSCSIHostProtocolTypeToString(= hostsrc->protocol)); - goto cleanup; + return -1; break; } =20 - ret =3D 0; - cleanup: - VIR_FREE(wwpn); - VIR_FREE(protocol); - return ret; + return 0; } =20 static int virDomainHostdevSubsysMediatedDevDefParseXML(virDomainHostdevDefPtr def, xmlXPathContextPtr ctxt) { - int ret =3D -1; unsigned char uuid[VIR_UUID_BUFLEN] =3D {0}; - char *uuidxml =3D NULL; xmlNodePtr node =3D NULL; virDomainHostdevSubsysMediatedDevPtr mdevsrc =3D &def->source.subsys.u= .mdev; + VIR_AUTOFREE(char *) uuidxml =3D NULL; =20 if (!(node =3D virXPathNode("./source/address", ctxt))) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Missing
element")); - goto cleanup; + return -1; } =20 if (!(uuidxml =3D virXMLPropString(node, "uuid"))) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Missing 'uuid' attribute for element
")= ); - goto cleanup; + return -1; } =20 if (virUUIDParse(uuidxml, uuid) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Cannot parse uuid attribute of element
= ")); - goto cleanup; + return -1; } =20 virUUIDFormat(uuid, mdevsrc->uuidstr); - ret =3D 0; - cleanup: - VIR_FREE(uuidxml); - return ret; + return 0; } =20 static int @@ -7851,17 +7770,16 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, unsigned int flags) { xmlNodePtr sourcenode; - char *managed =3D NULL; - char *sgio =3D NULL; - char *rawio =3D NULL; - char *backendStr =3D NULL; - char *model =3D NULL; - char *display =3D NULL; int backend; - int ret =3D -1; virDomainHostdevSubsysPCIPtr pcisrc =3D &def->source.subsys.u.pci; virDomainHostdevSubsysSCSIPtr scsisrc =3D &def->source.subsys.u.scsi; virDomainHostdevSubsysMediatedDevPtr mdevsrc =3D &def->source.subsys.u= .mdev; + VIR_AUTOFREE(char *) managed =3D NULL; + VIR_AUTOFREE(char *) sgio =3D NULL; + VIR_AUTOFREE(char *) rawio =3D NULL; + VIR_AUTOFREE(char *) backendStr =3D NULL; + VIR_AUTOFREE(char *) model =3D NULL; + VIR_AUTOFREE(char *) display =3D NULL; =20 /* @managed can be read from the xml document - it is always an * attribute of the toplevel element, no matter what type of @@ -7892,18 +7810,18 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown host device source address type '%s'= "), type); - goto cleanup; + return -1; } } else { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing source address type")); - goto cleanup; + return -1; } =20 if (!(sourcenode =3D virXPathNode("./source", ctxt))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing element in hostdev device")); - goto cleanup; + return -1; } =20 if (def->source.subsys.type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB && @@ -7911,20 +7829,20 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Setting startupPolicy is only allowed for USB" " devices")); - goto cleanup; + return -1; } =20 if (sgio) { if (def->source.subsys.type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SC= SI) { virReportError(VIR_ERR_XML_ERROR, "%s", _("sgio is only supported for scsi host device"= )); - goto cleanup; + return -1; } =20 if ((scsisrc->sgio =3D virDomainDeviceSGIOTypeFromString(sgio)) <= =3D 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown sgio mode '%s'"), sgio); - goto cleanup; + return -1; } } =20 @@ -7932,14 +7850,14 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, if (def->source.subsys.type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SC= SI) { virReportError(VIR_ERR_XML_ERROR, "%s", _("rawio is only supported for scsi host device= ")); - goto cleanup; + return -1; } =20 if ((scsisrc->rawio =3D virTristateBoolTypeFromString(rawio)) <=3D= 0) { virReportError(VIR_ERR_XML_ERROR, _("unknown hostdev rawio setting '%s'"), rawio); - goto cleanup; + return -1; } } =20 @@ -7948,21 +7866,21 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, virReportError(VIR_ERR_XML_ERROR, "%s", _("'model' attribute in is only suppo= rted " "when type=3D'mdev'")); - goto cleanup; + return -1; } } else { if (!model) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing 'model' attribute in mediated device= 's " " element")); - goto cleanup; + return -1; } =20 if ((mdevsrc->model =3D virMediatedDeviceModelTypeFromString(model= )) < 0) { virReportError(VIR_ERR_XML_ERROR, _("unknown hostdev model '%s'"), model); - goto cleanup; + return -1; } =20 if (display && @@ -7971,14 +7889,14 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, _("unknown value '%s' for attribute " "'display'"), display); - goto cleanup; + return -1; } } =20 switch (def->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: if (virDomainHostdevSubsysPCIDefParseXML(sourcenode, def, flags) <= 0) - goto cleanup; + return -1; =20 backend =3D VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT; if ((backendStr =3D virXPathString("string(./driver/@name)", ctxt)= ) && @@ -7987,7 +7905,7 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unknown PCI device " "has been specified"), backendStr); - goto cleanup; + return -1; } pcisrc->backend =3D backend; =20 @@ -7995,56 +7913,50 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: if (virDomainHostdevSubsysUSBDefParseXML(sourcenode, def) < 0) - goto cleanup; + return -1; break; =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: if (virDomainHostdevSubsysSCSIDefParseXML(sourcenode, scsisrc, ctx= t) < 0) - goto cleanup; + return -1; break; =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST: if (virDomainHostdevSubsysSCSIVHostDefParseXML(sourcenode, def) < = 0) - goto cleanup; + return -1; break; case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: if (virDomainHostdevSubsysMediatedDevDefParseXML(def, ctxt) < 0) - goto cleanup; + return -1; break; =20 default: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("address type=3D'%s' not supported in hostdev int= erfaces"), virDomainHostdevSubsysTypeToString(def->source.subs= ys.type)); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(managed); - VIR_FREE(sgio); - VIR_FREE(rawio); - VIR_FREE(backendStr); - VIR_FREE(model); - VIR_FREE(display); - return ret; + return 0; } =20 static virNetDevIPAddrPtr virDomainNetIPParseXML(xmlNodePtr node) { /* Parse the prefix in every case */ - virNetDevIPAddrPtr ip =3D NULL, ret =3D NULL; - char *prefixStr =3D NULL; + virNetDevIPAddrPtr ret =3D NULL; unsigned int prefixValue =3D 0; - char *familyStr =3D NULL; int family =3D AF_UNSPEC; - char *address =3D NULL, *peer =3D NULL; + VIR_AUTOFREE(virNetDevIPAddrPtr) ip =3D NULL; + VIR_AUTOFREE(char *) prefixStr =3D NULL; + VIR_AUTOFREE(char *) familyStr =3D NULL; + VIR_AUTOFREE(char *) address =3D NULL; + VIR_AUTOFREE(char *) peer =3D NULL; =20 if (!(address =3D virXMLPropString(node, "address"))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing required address in ")); - goto cleanup; + return NULL; } =20 familyStr =3D virXMLPropString(node, "family"); @@ -8056,13 +7968,13 @@ virDomainNetIPParseXML(xmlNodePtr node) family =3D virSocketAddrNumericFamily(address); =20 if (VIR_ALLOC(ip) < 0) - goto cleanup; + return NULL; =20 if (virSocketAddrParse(&ip->address, address, family) < 0) { virReportError(VIR_ERR_XML_ERROR, _("Invalid address '%s' in "), address); - goto cleanup; + return NULL; } =20 prefixStr =3D virXMLPropString(node, "prefix"); @@ -8073,7 +7985,7 @@ virDomainNetIPParseXML(xmlNodePtr node) virReportError(VIR_ERR_XML_ERROR, _("Invalid prefix value '%s' in "), prefixStr); - goto cleanup; + return NULL; } ip->prefix =3D prefixValue; =20 @@ -8081,17 +7993,10 @@ virDomainNetIPParseXML(xmlNodePtr node) virSocketAddrParse(&ip->peer, peer, family) < 0) { virReportError(VIR_ERR_INVALID_ARG, _("Invalid peer '%s' in "), peer); - goto cleanup; + return NULL; } =20 VIR_STEAL_PTR(ret, ip); - - cleanup: - VIR_FREE(prefixStr); - VIR_FREE(familyStr); - VIR_FREE(address); - VIR_FREE(peer); - VIR_FREE(ip); return ret; } =20 @@ -8106,12 +8011,12 @@ virDomainNetIPInfoParseXML(const char *source, xmlXPathContextPtr ctxt, virNetDevIPInfoPtr def) { - xmlNodePtr *nodes =3D NULL; - virNetDevIPAddrPtr ip =3D NULL; virNetDevIPRoutePtr route =3D NULL; int nnodes; int ret =3D -1; size_t i; + VIR_AUTOFREE(xmlNodePtr *) nodes =3D NULL; + VIR_AUTOFREE(virNetDevIPAddrPtr) ip =3D NULL; =20 if ((nnodes =3D virXPathNodeSet("./ip", ctxt, &nodes)) < 0) goto cleanup; @@ -8136,9 +8041,7 @@ virDomainNetIPInfoParseXML(const char *source, cleanup: if (ret < 0) virNetDevIPInfoClear(def); - VIR_FREE(ip); virNetDevIPRouteFree(route); - VIR_FREE(nodes); return ret; } =20 @@ -8149,8 +8052,8 @@ virDomainNetDefCoalesceParseXML(xmlNodePtr node, { virNetDevCoalescePtr ret =3D NULL; xmlNodePtr save =3D NULL; - char *str =3D NULL; unsigned long long tmp =3D 0; + VIR_AUTOFREE(char *) str =3D NULL; =20 save =3D ctxt->node; ctxt->node =3D node; @@ -8166,10 +8069,8 @@ virDomainNetDefCoalesceParseXML(xmlNodePtr node, virReportError(VIR_ERR_XML_DETAIL, _("cannot parse value '%s' for coalesce parameter"), str); - VIR_FREE(str); goto error; } - VIR_FREE(str); =20 if (tmp > UINT32_MAX) { virReportError(VIR_ERR_OVERFLOW, @@ -8181,7 +8082,6 @@ virDomainNetDefCoalesceParseXML(xmlNodePtr node, ret->rx_max_coalesced_frames =3D tmp; =20 cleanup: - VIR_FREE(str); ctxt->node =3D save; return ret; =20 @@ -8556,8 +8456,9 @@ virSecurityLabelDefsParseXML(virDomainDefPtr def, { size_t i =3D 0, j; int n; - xmlNodePtr *list =3D NULL, saved_node; + xmlNodePtr saved_node; virCapsHostPtr host =3D &caps->host; + VIR_AUTOFREE(xmlNodePtr *) list =3D NULL; =20 /* Check args and save context */ if (def =3D=3D NULL || ctxt =3D=3D NULL) @@ -8595,7 +8496,6 @@ virSecurityLabelDefsParseXML(virDomainDefPtr def, } def->nseclabels =3D n; ctxt->node =3D saved_node; - VIR_FREE(list); =20 /* libvirt versions prior to 0.10.0 support just a single seclabel ele= ment * in guest's XML and model attribute can be suppressed if type is non= e or @@ -8650,7 +8550,6 @@ virSecurityLabelDefsParseXML(virDomainDefPtr def, virSecurityLabelDefFree(def->seclabels[i - 1]); VIR_FREE(def->seclabels); def->nseclabels =3D 0; - VIR_FREE(list); return -1; } =20 @@ -8665,8 +8564,8 @@ virSecurityDeviceLabelDefParseXML(virSecurityDeviceLa= belDefPtr **seclabels_rtn, size_t nseclabels =3D 0; int n; size_t i, j; - xmlNodePtr *list =3D NULL; char *model, *relabel, *label, *labelskip; + VIR_AUTOFREE(xmlNodePtr *) list =3D NULL; =20 if ((n =3D virXPathNodeSet("./seclabel", ctxt, &list)) < 0) goto error; @@ -8734,7 +8633,6 @@ virSecurityDeviceLabelDefParseXML(virSecurityDeviceLa= belDefPtr **seclabels_rtn, goto error; } } - VIR_FREE(list); =20 *nseclabels_rtn =3D nseclabels; *seclabels_rtn =3D seclabels; @@ -8745,7 +8643,6 @@ virSecurityDeviceLabelDefParseXML(virSecurityDeviceLa= belDefPtr **seclabels_rtn, for (i =3D 0; i < nseclabels; i++) virSecurityDeviceLabelDefFree(seclabels[i]); VIR_FREE(seclabels); - VIR_FREE(list); return -1; } =20 @@ -8788,10 +8685,10 @@ virDomainLeaseDefParseXML(xmlNodePtr node) { virDomainLeaseDefPtr def; xmlNodePtr cur; - char *lockspace =3D NULL; - char *key =3D NULL; - char *path =3D NULL; - char *offset =3D NULL; + VIR_AUTOFREE(char *) lockspace =3D NULL; + VIR_AUTOFREE(char *) key =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; + VIR_AUTOFREE(char *) offset =3D NULL; =20 if (VIR_ALLOC(def) < 0) return NULL; @@ -8836,11 +8733,6 @@ virDomainLeaseDefParseXML(xmlNodePtr node) VIR_STEAL_PTR(def->path, path); =20 cleanup: - VIR_FREE(lockspace); - VIR_FREE(key); - VIR_FREE(path); - VIR_FREE(offset); - return def; =20 error: @@ -8853,9 +8745,9 @@ static int virDomainDiskSourcePoolDefParse(xmlNodePtr node, virStorageSourcePoolDefPtr *srcpool) { - char *mode =3D NULL; virStorageSourcePoolDefPtr source; int ret =3D -1; + VIR_AUTOFREE(char *) mode =3D NULL; =20 *srcpool =3D NULL; =20 @@ -8892,7 +8784,6 @@ virDomainDiskSourcePoolDefParse(xmlNodePtr node, =20 cleanup: virStorageSourcePoolDefFree(source); - VIR_FREE(mode); return ret; } =20 @@ -8903,36 +8794,35 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node, virStorageSourcePtr src, unsigned int flags) { - char *protocol =3D NULL; - char *haveTLS =3D NULL; - char *tlsCfg =3D NULL; int tlsCfgVal; - int ret =3D -1; + VIR_AUTOFREE(char *) protocol =3D NULL; + VIR_AUTOFREE(char *) haveTLS =3D NULL; + VIR_AUTOFREE(char *) tlsCfg =3D NULL; =20 if (!(protocol =3D virXMLPropString(node, "protocol"))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing network source protocol type")); - goto cleanup; + return -1; } =20 if ((src->protocol =3D virStorageNetProtocolTypeFromString(protocol)) = <=3D 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown protocol type '%s'"), protocol); - goto cleanup; + return -1; } =20 if (!(src->path =3D virXMLPropString(node, "name")) && src->protocol !=3D VIR_STORAGE_NET_PROTOCOL_NBD) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing name for disk source")); - goto cleanup; + return -1; } =20 if ((haveTLS =3D virXMLPropString(node, "tls")) && (src->haveTLS =3D virTristateBoolTypeFromString(haveTLS)) <=3D 0) { virReportError(VIR_ERR_XML_ERROR, _("unknown disk source 'tls' setting '%s'"), haveTLS); - goto cleanup; + return -1; } =20 if ((flags & VIR_DOMAIN_DEF_PARSE_STATUS) && @@ -8941,7 +8831,7 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node, virReportError(VIR_ERR_XML_ERROR, _("Invalid tlsFromConfig value: %s"), tlsCfg); - goto cleanup; + return -1; } src->tlsFromConfig =3D !!tlsCfgVal; } @@ -8957,13 +8847,13 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node, virReportError(VIR_ERR_XML_ERROR, _("can't split path '%s' into pool name and ima= ge " "name"), src->path); - goto cleanup; + return -1; } =20 src->volume =3D src->path; =20 if (VIR_STRDUP(src->path, tmp + 1) < 0) - goto cleanup; + return -1; =20 tmp[0] =3D '\0'; } @@ -8975,19 +8865,13 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node, src->configFile =3D virXPathString("string(./config/@file)", ctxt); =20 if (virDomainStorageNetworkParseHosts(node, &src->hosts, &src->nhosts)= < 0) - goto cleanup; + return -1; =20 virStorageSourceNetworkAssignDefaultPorts(src); =20 virStorageSourceInitiatorParseXML(ctxt, &src->initiator); =20 - ret =3D 0; - - cleanup: - VIR_FREE(tlsCfg); - VIR_FREE(haveTLS); - VIR_FREE(protocol); - return ret; + return 0; } =20 =20 @@ -9141,11 +9025,11 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr c= txt, { xmlNodePtr save_ctxt =3D ctxt->node; xmlNodePtr source; - char *type =3D NULL; - char *format =3D NULL; - char *idx =3D NULL; int ret =3D -1; VIR_AUTOUNREF(virStorageSourcePtr) backingStore =3D NULL; + VIR_AUTOFREE(char *) type =3D NULL; + VIR_AUTOFREE(char *) format =3D NULL; + VIR_AUTOFREE(char *) idx =3D NULL; =20 if (!(ctxt->node =3D virXPathNode("./backingStore", ctxt))) { ret =3D 0; @@ -9206,9 +9090,6 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctx= t, ret =3D 0; =20 cleanup: - VIR_FREE(type); - VIR_FREE(format); - VIR_FREE(idx); ctxt->node =3D save_ctxt; return ret; } @@ -9304,20 +9185,19 @@ virDomainDiskDefMirrorParse(virDomainDiskDefPtr def, virDomainXMLOptionPtr xmlopt) { xmlNodePtr mirrorNode; - char *mirrorFormat =3D NULL; - char *mirrorType =3D NULL; - char *ready =3D NULL; - char *blockJob =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) mirrorFormat =3D NULL; + VIR_AUTOFREE(char *) mirrorType =3D NULL; + VIR_AUTOFREE(char *) ready =3D NULL; + VIR_AUTOFREE(char *) blockJob =3D NULL; =20 if (!(def->mirror =3D virStorageSourceNew())) - goto cleanup; + return -1; =20 if ((blockJob =3D virXMLPropString(cur, "job"))) { if ((def->mirrorJob =3D virDomainBlockJobTypeFromString(blockJob))= <=3D 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown mirror job type '%s'"), blockJob); - goto cleanup; + return -1; } } else { def->mirrorJob =3D VIR_DOMAIN_BLOCK_JOB_TYPE_COPY; @@ -9328,7 +9208,7 @@ virDomainDiskDefMirrorParse(virDomainDiskDefPtr def, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown mirror backing store type '%s'"), mirrorType); - goto cleanup; + return -1; } =20 mirrorFormat =3D virXPathString("string(./mirror/format/@type)", c= txt); @@ -9336,12 +9216,12 @@ virDomainDiskDefMirrorParse(virDomainDiskDefPtr def, if (!(mirrorNode =3D virXPathNode("./mirror/source", ctxt))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("mirror requires source element")); - goto cleanup; + return -1; } =20 if (virDomainDiskSourceParse(mirrorNode, ctxt, def->mirror, flags, xmlopt) < 0) - goto cleanup; + return -1; } else { /* For back-compat reasons, we handle a file name * encoded as attributes, even though we prefer @@ -9351,13 +9231,13 @@ virDomainDiskDefMirrorParse(virDomainDiskDefPtr def, if (!def->mirror->path) { virReportError(VIR_ERR_XML_ERROR, "%s", _("mirror requires file name")); - goto cleanup; + return -1; } if (def->mirrorJob !=3D VIR_DOMAIN_BLOCK_JOB_TYPE_COPY) { virReportError(VIR_ERR_XML_ERROR, "%s", _("mirror without type only supported " "by copy job")); - goto cleanup; + return -1; } mirrorFormat =3D virXMLPropString(cur, "format"); } @@ -9367,7 +9247,7 @@ virDomainDiskDefMirrorParse(virDomainDiskDefPtr def, if (def->mirror->format <=3D 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown mirror format value '%s'"), mirrorFo= rmat); - goto cleanup; + return -1; } } =20 @@ -9375,17 +9255,10 @@ virDomainDiskDefMirrorParse(virDomainDiskDefPtr def, (def->mirrorState =3D virDomainDiskMirrorStateTypeFromString(ready= )) < 0) { virReportError(VIR_ERR_XML_ERROR, _("unknown mirror ready state %s"), ready); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(ready); - VIR_FREE(blockJob); - VIR_FREE(mirrorType); - VIR_FREE(mirrorFormat); - return ret; + return 0; } =20 =20 @@ -9393,13 +9266,13 @@ static int virDomainDiskDefGeometryParse(virDomainDiskDefPtr def, xmlNodePtr cur) { - char *tmp; + VIR_AUTOFREE(char *) tmp =3D NULL; =20 if ((tmp =3D virXMLPropString(cur, "cyls"))) { if (virStrToLong_ui(tmp, NULL, 10, &def->geometry.cylinders) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("invalid geometry settings (cyls)")); - goto error; + return -1; } VIR_FREE(tmp); } @@ -9408,7 +9281,7 @@ virDomainDiskDefGeometryParse(virDomainDiskDefPtr def, if (virStrToLong_ui(tmp, NULL, 10, &def->geometry.heads) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("invalid geometry settings (heads)")); - goto error; + return -1; } VIR_FREE(tmp); } @@ -9417,7 +9290,7 @@ virDomainDiskDefGeometryParse(virDomainDiskDefPtr def, if (virStrToLong_ui(tmp, NULL, 10, &def->geometry.sectors) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("invalid geometry settings (secs)")); - goto error; + return -1; } VIR_FREE(tmp); } @@ -9428,16 +9301,11 @@ virDomainDiskDefGeometryParse(virDomainDiskDefPtr d= ef, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("invalid translation value '%s'"), tmp); - goto error; + return -1; } - VIR_FREE(tmp); } =20 return 0; - - error: - VIR_FREE(tmp); - return -1; } =20 =20 @@ -9581,8 +9449,7 @@ static int virDomainDiskDefDriverParseXML(virDomainDiskDefPtr def, xmlNodePtr cur) { - char *tmp =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) tmp =3D NULL; =20 def->driverName =3D virXMLPropString(cur, "name"); =20 @@ -9590,7 +9457,7 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr de= f, (def->cachemode =3D virDomainDiskCacheTypeFromString(tmp)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown disk cache mode '%s'"), tmp); - goto cleanup; + return -1; } VIR_FREE(tmp); =20 @@ -9598,7 +9465,7 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr de= f, (def->error_policy =3D virDomainDiskErrorPolicyTypeFromString(tmp)= ) <=3D 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown disk error policy '%s'"), tmp); - goto cleanup; + return -1; } VIR_FREE(tmp); =20 @@ -9607,7 +9474,7 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr de= f, (def->rerror_policy =3D=3D VIR_DOMAIN_DISK_ERROR_POLICY_ENOSPACE)= )) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown disk read error policy '%s'"), tmp); - goto cleanup; + return -1; } VIR_FREE(tmp); =20 @@ -9615,7 +9482,7 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr de= f, (def->iomode =3D virDomainDiskIoTypeFromString(tmp)) <=3D 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown disk io mode '%s'"), tmp); - goto cleanup; + return -1; } VIR_FREE(tmp); =20 @@ -9623,7 +9490,7 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr de= f, (def->ioeventfd =3D virTristateSwitchTypeFromString(tmp)) <=3D 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown disk ioeventfd mode '%s'"), tmp); - goto cleanup; + return -1; } VIR_FREE(tmp); =20 @@ -9631,7 +9498,7 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr de= f, (def->event_idx =3D virTristateSwitchTypeFromString(tmp)) <=3D 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown disk event_idx mode '%s'"), tmp); - goto cleanup; + return -1; } VIR_FREE(tmp); =20 @@ -9639,7 +9506,7 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr de= f, (def->copy_on_read =3D virTristateSwitchTypeFromString(tmp)) <=3D = 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown disk copy_on_read mode '%s'"), tmp); - goto cleanup; + return -1; } VIR_FREE(tmp); =20 @@ -9647,7 +9514,7 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr de= f, (def->discard =3D virDomainDiskDiscardTypeFromString(tmp)) <=3D 0)= { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown disk discard mode '%s'"), tmp); - goto cleanup; + return -1; } VIR_FREE(tmp); =20 @@ -9657,7 +9524,7 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr de= f, virReportError(VIR_ERR_XML_ERROR, _("Invalid iothread attribute in disk driver elemen= t: %s"), tmp); - goto cleanup; + return -1; } VIR_FREE(tmp); =20 @@ -9669,7 +9536,7 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr de= f, if ((def->src->format =3D virStorageFileFormatTypeFromString(t= mp)) <=3D 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown driver format value '%s'"), tmp); - goto cleanup; + return -1; } } =20 @@ -9680,7 +9547,7 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr de= f, (def->detect_zeroes =3D virDomainDiskDetectZeroesTypeFromString(tm= p)) <=3D 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown driver detect_zeroes value '%s'"), tmp); - goto cleanup; + return -1; } VIR_FREE(tmp); =20 @@ -9689,16 +9556,10 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr = def, virReportError(VIR_ERR_XML_ERROR, _("'queues' attribute must be positive number: %s"), tmp); - goto cleanup; + return -1; } - VIR_FREE(tmp); - - ret =3D 0; =20 - cleanup: - VIR_FREE(tmp); - - return ret; + return 0; } =20 =20 @@ -9746,26 +9607,26 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlo= pt, virDomainDiskDefPtr def; xmlNodePtr cur; xmlNodePtr save_ctxt =3D ctxt->node; - char *tmp =3D NULL; - char *snapshot =3D NULL; - char *rawio =3D NULL; - char *sgio =3D NULL; bool source =3D false; - char *target =3D NULL; - char *bus =3D NULL; - char *devaddr =3D NULL; virStorageEncryptionPtr encryption =3D NULL; - char *serial =3D NULL; - char *startupPolicy =3D NULL; - char *tray =3D NULL; - char *removable =3D NULL; - char *logical_block_size =3D NULL; - char *physical_block_size =3D NULL; - char *wwn =3D NULL; - char *vendor =3D NULL; - char *product =3D NULL; - char *domain_name =3D NULL; VIR_AUTOPTR(virStorageAuthDef) authdef =3D NULL; + VIR_AUTOFREE(char *) tmp =3D NULL; + VIR_AUTOFREE(char *) snapshot =3D NULL; + VIR_AUTOFREE(char *) rawio =3D NULL; + VIR_AUTOFREE(char *) sgio =3D NULL; + VIR_AUTOFREE(char *) target =3D NULL; + VIR_AUTOFREE(char *) bus =3D NULL; + VIR_AUTOFREE(char *) devaddr =3D NULL; + VIR_AUTOFREE(char *) serial =3D NULL; + VIR_AUTOFREE(char *) startupPolicy =3D NULL; + VIR_AUTOFREE(char *) tray =3D NULL; + VIR_AUTOFREE(char *) removable =3D NULL; + VIR_AUTOFREE(char *) logical_block_size =3D NULL; + VIR_AUTOFREE(char *) physical_block_size =3D NULL; + VIR_AUTOFREE(char *) wwn =3D NULL; + VIR_AUTOFREE(char *) vendor =3D NULL; + VIR_AUTOFREE(char *) product =3D NULL; + VIR_AUTOFREE(char *) domain_name =3D NULL; =20 if (!(def =3D virDomainDiskDefNew(xmlopt))) return NULL; @@ -10153,25 +10014,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xml= opt, goto error; =20 cleanup: - VIR_FREE(tmp); - VIR_FREE(bus); - VIR_FREE(snapshot); - VIR_FREE(rawio); - VIR_FREE(sgio); - VIR_FREE(target); - VIR_FREE(tray); - VIR_FREE(removable); - VIR_FREE(devaddr); - VIR_FREE(serial); virStorageEncryptionFree(encryption); - VIR_FREE(startupPolicy); - VIR_FREE(logical_block_size); - VIR_FREE(physical_block_size); - VIR_FREE(wwn); - VIR_FREE(vendor); - VIR_FREE(product); - VIR_FREE(domain_name); - ctxt->node =3D save_ctxt; return def; =20 @@ -10212,26 +10055,23 @@ virDomainParseScaledValue(const char *xpath, unsigned long long max, bool required) { - char *xpath_full =3D NULL; - char *unit =3D NULL; - char *bytes_str =3D NULL; - int ret =3D -1; unsigned long long bytes; + VIR_AUTOFREE(char *) xpath_full =3D NULL; + VIR_AUTOFREE(char *) unit =3D NULL; + VIR_AUTOFREE(char *) bytes_str =3D NULL; =20 *val =3D 0; if (virAsprintf(&xpath_full, "string(%s)", xpath) < 0) - goto cleanup; + return -1; =20 bytes_str =3D virXPathString(xpath_full, ctxt); if (!bytes_str) { - if (!required) { - ret =3D 0; - } else { - virReportError(VIR_ERR_XML_ERROR, - _("missing element or attribute '%s'"), - xpath); - } - goto cleanup; + if (!required) + return 0; + virReportError(VIR_ERR_XML_ERROR, + _("missing element or attribute '%s'"), + xpath); + return -1; } VIR_FREE(xpath_full); =20 @@ -10239,26 +10079,21 @@ virDomainParseScaledValue(const char *xpath, virReportError(VIR_ERR_XML_ERROR, _("Invalid value '%s' for element or attribute '%s'= "), bytes_str, xpath); - goto cleanup; + return -1; } =20 if ((units_xpath && virAsprintf(&xpath_full, "string(%s)", units_xpath) < 0) || (!units_xpath && virAsprintf(&xpath_full, "string(%s/@unit)", xpath) < 0)) - goto cleanup; + return -1; unit =3D virXPathString(xpath_full, ctxt); =20 if (virScaleInteger(&bytes, unit, scale, max) < 0) - goto cleanup; + return -1; =20 *val =3D bytes; - ret =3D 1; - cleanup: - VIR_FREE(bytes_str); - VIR_FREE(xpath_full); - VIR_FREE(unit); - return ret; + return 1; } =20 =20 @@ -10458,27 +10293,27 @@ virDomainControllerDefParseXML(virDomainXMLOption= Ptr xmlopt, virDomainControllerDefPtr def =3D NULL; int type =3D 0; xmlNodePtr cur =3D NULL; - char *typeStr =3D NULL; - char *idx =3D NULL; - char *model =3D NULL; - char *queues =3D NULL; - char *cmd_per_lun =3D NULL; - char *max_sectors =3D NULL; bool processedModel =3D false; - char *modelName =3D NULL; bool processedTarget =3D false; - char *chassisNr =3D NULL; - char *chassis =3D NULL; - char *port =3D NULL; - char *busNr =3D NULL; - char *targetIndex =3D NULL; int numaNode =3D -1; - char *ioeventfd =3D NULL; - char *portsStr =3D NULL; int ports =3D -1; - char *iothread =3D NULL; xmlNodePtr saved =3D ctxt->node; int rc; + VIR_AUTOFREE(char *) typeStr =3D NULL; + VIR_AUTOFREE(char *) idx =3D NULL; + VIR_AUTOFREE(char *) model =3D NULL; + VIR_AUTOFREE(char *) queues =3D NULL; + VIR_AUTOFREE(char *) cmd_per_lun =3D NULL; + VIR_AUTOFREE(char *) max_sectors =3D NULL; + VIR_AUTOFREE(char *) modelName =3D NULL; + VIR_AUTOFREE(char *) chassisNr =3D NULL; + VIR_AUTOFREE(char *) chassis =3D NULL; + VIR_AUTOFREE(char *) port =3D NULL; + VIR_AUTOFREE(char *) busNr =3D NULL; + VIR_AUTOFREE(char *) targetIndex =3D NULL; + VIR_AUTOFREE(char *) ioeventfd =3D NULL; + VIR_AUTOFREE(char *) portsStr =3D NULL; + VIR_AUTOFREE(char *) iothread =3D NULL; =20 ctxt->node =3D node; =20 @@ -10617,20 +10452,18 @@ virDomainControllerDefParseXML(virDomainXMLOption= Ptr xmlopt, =20 switch (def->type) { case VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL: { - def->opts.vioserial.ports =3D ports; + VIR_AUTOFREE(char *) vectors =3D virXMLPropString(node, "vectors"); =20 - char *vectors =3D virXMLPropString(node, "vectors"); + def->opts.vioserial.ports =3D ports; if (vectors) { int r =3D virStrToLong_i(vectors, NULL, 10, &def->opts.vioserial.vectors); if (r !=3D 0 || def->opts.vioserial.vectors < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Invalid vectors: %s"), vectors); - VIR_FREE(vectors); goto error; } } - VIR_FREE(vectors); break; } case VIR_DOMAIN_CONTROLLER_TYPE_USB: { @@ -10793,22 +10626,6 @@ virDomainControllerDefParseXML(virDomainXMLOptionP= tr xmlopt, =20 cleanup: ctxt->node =3D saved; - VIR_FREE(typeStr); - VIR_FREE(idx); - VIR_FREE(model); - VIR_FREE(queues); - VIR_FREE(cmd_per_lun); - VIR_FREE(max_sectors); - VIR_FREE(modelName); - VIR_FREE(chassisNr); - VIR_FREE(chassis); - VIR_FREE(port); - VIR_FREE(busNr); - VIR_FREE(targetIndex); - VIR_FREE(ioeventfd); - VIR_FREE(portsStr); - VIR_FREE(iothread); - return def; =20 error: @@ -10837,15 +10654,15 @@ virDomainFSDefParseXML(virDomainXMLOptionPtr xmlo= pt, { virDomainFSDefPtr def; xmlNodePtr cur, save_node =3D ctxt->node; - char *type =3D NULL; - char *fsdriver =3D NULL; - char *source =3D NULL; - char *target =3D NULL; - char *format =3D NULL; - char *accessmode =3D NULL; - char *wrpolicy =3D NULL; - char *usage =3D NULL; - char *units =3D NULL; + VIR_AUTOFREE(char *) type =3D NULL; + VIR_AUTOFREE(char *) fsdriver =3D NULL; + VIR_AUTOFREE(char *) source =3D NULL; + VIR_AUTOFREE(char *) target =3D NULL; + VIR_AUTOFREE(char *) format =3D NULL; + VIR_AUTOFREE(char *) accessmode =3D NULL; + VIR_AUTOFREE(char *) wrpolicy =3D NULL; + VIR_AUTOFREE(char *) usage =3D NULL; + VIR_AUTOFREE(char *) units =3D NULL; =20 ctxt->node =3D node; =20 @@ -10991,16 +10808,6 @@ virDomainFSDefParseXML(virDomainXMLOptionPtr xmlop= t, =20 cleanup: ctxt->node =3D save_node; - VIR_FREE(type); - VIR_FREE(fsdriver); - VIR_FREE(target); - VIR_FREE(source); - VIR_FREE(accessmode); - VIR_FREE(wrpolicy); - VIR_FREE(usage); - VIR_FREE(units); - VIR_FREE(format); - return def; =20 error: @@ -11022,11 +10829,11 @@ virDomainActualNetDefParseXML(xmlNodePtr node, xmlNodePtr bandwidth_node =3D NULL; xmlNodePtr vlanNode; xmlNodePtr virtPortNode; - char *type =3D NULL; - char *mode =3D NULL; - char *addrtype =3D NULL; - char *trustGuestRxFilters =3D NULL; - char *macTableManager =3D NULL; + VIR_AUTOFREE(char *) type =3D NULL; + VIR_AUTOFREE(char *) mode =3D NULL; + VIR_AUTOFREE(char *) addrtype =3D NULL; + VIR_AUTOFREE(char *) trustGuestRxFilters =3D NULL; + VIR_AUTOFREE(char *) macTableManager =3D NULL; =20 if (VIR_ALLOC(actual) < 0) return -1; @@ -11125,16 +10932,16 @@ virDomainActualNetDefParseXML(xmlNodePtr node, goto error; } } else if (actual->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { - char *class_id =3D virXPathString("string(./class/@id)", ctxt); + VIR_AUTOFREE(char *) class_id =3D NULL; + + class_id =3D virXPathString("string(./class/@id)", ctxt); if (class_id && virStrToLong_ui(class_id, NULL, 10, &actual->class_id) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse class id '%s'"), class_id); - VIR_FREE(class_id); goto error; } - VIR_FREE(class_id); } if (actual->type =3D=3D VIR_DOMAIN_NET_TYPE_BRIDGE || actual->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { @@ -11176,11 +10983,6 @@ virDomainActualNetDefParseXML(xmlNodePtr node, VIR_STEAL_PTR(*def, actual); ret =3D 0; error: - VIR_FREE(type); - VIR_FREE(mode); - VIR_FREE(addrtype); - VIR_FREE(trustGuestRxFilters); - VIR_FREE(macTableManager); virDomainActualNetDefFree(actual); =20 ctxt->node =3D save_ctxt; @@ -11223,9 +11025,9 @@ virDomainChrSourceReconnectDefParseXML(virDomainChr= SourceReconnectDefPtr def, { int ret =3D -1; int tmpVal; - char *tmp =3D NULL; xmlNodePtr saveNode =3D ctxt->node; xmlNodePtr cur; + VIR_AUTOFREE(char *) tmp =3D NULL; =20 ctxt->node =3D node; =20 @@ -11249,7 +11051,6 @@ virDomainChrSourceReconnectDefParseXML(virDomainChr= SourceReconnectDefPtr def, tmp); goto cleanup; } - VIR_FREE(tmp); } else { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing timeout for chardev with " @@ -11262,7 +11063,6 @@ virDomainChrSourceReconnectDefParseXML(virDomainChr= SourceReconnectDefPtr def, ret =3D 0; cleanup: ctxt->node =3D saveNode; - VIR_FREE(tmp); return ret; } =20 @@ -11282,46 +11082,46 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xml= opt, virDomainHostdevDefPtr hostdev; xmlNodePtr cur; xmlNodePtr tmpNode; - char *macaddr =3D NULL; - char *type =3D NULL; - char *network =3D NULL; - char *portgroup =3D NULL; - char *bridge =3D NULL; - char *dev =3D NULL; - char *ifname =3D NULL; - char *ifname_guest =3D NULL; - char *ifname_guest_actual =3D NULL; - char *script =3D NULL; - char *address =3D NULL; - char *port =3D NULL; - char *localaddr =3D NULL; - char *localport =3D NULL; - char *model =3D NULL; - char *backend =3D NULL; - char *txmode =3D NULL; - char *ioeventfd =3D NULL; - char *event_idx =3D NULL; - char *queues =3D NULL; - char *rx_queue_size =3D NULL; - char *tx_queue_size =3D NULL; - char *str =3D NULL; - char *filter =3D NULL; - char *internal =3D NULL; - char *devaddr =3D NULL; - char *mode =3D NULL; - char *linkstate =3D NULL; - char *addrtype =3D NULL; - char *domain_name =3D NULL; - char *vhostuser_mode =3D NULL; - char *vhostuser_path =3D NULL; - char *vhostuser_type =3D NULL; - char *trustGuestRxFilters =3D NULL; - char *vhost_path =3D NULL; virHashTablePtr filterparams =3D NULL; virDomainActualNetDefPtr actual =3D NULL; xmlNodePtr oldnode =3D ctxt->node; virDomainChrSourceReconnectDef reconnect =3D {0}; int rv, val; + VIR_AUTOFREE(char *) macaddr =3D NULL; + VIR_AUTOFREE(char *) type =3D NULL; + VIR_AUTOFREE(char *) network =3D NULL; + VIR_AUTOFREE(char *) portgroup =3D NULL; + VIR_AUTOFREE(char *) bridge =3D NULL; + VIR_AUTOFREE(char *) dev =3D NULL; + VIR_AUTOFREE(char *) ifname =3D NULL; + VIR_AUTOFREE(char *) ifname_guest =3D NULL; + VIR_AUTOFREE(char *) ifname_guest_actual =3D NULL; + VIR_AUTOFREE(char *) script =3D NULL; + VIR_AUTOFREE(char *) address =3D NULL; + VIR_AUTOFREE(char *) port =3D NULL; + VIR_AUTOFREE(char *) localaddr =3D NULL; + VIR_AUTOFREE(char *) localport =3D NULL; + VIR_AUTOFREE(char *) model =3D NULL; + VIR_AUTOFREE(char *) backend =3D NULL; + VIR_AUTOFREE(char *) txmode =3D NULL; + VIR_AUTOFREE(char *) ioeventfd =3D NULL; + VIR_AUTOFREE(char *) event_idx =3D NULL; + VIR_AUTOFREE(char *) queues =3D NULL; + VIR_AUTOFREE(char *) rx_queue_size =3D NULL; + VIR_AUTOFREE(char *) tx_queue_size =3D NULL; + VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) filter =3D NULL; + VIR_AUTOFREE(char *) internal =3D NULL; + VIR_AUTOFREE(char *) devaddr =3D NULL; + VIR_AUTOFREE(char *) mode =3D NULL; + VIR_AUTOFREE(char *) linkstate =3D NULL; + VIR_AUTOFREE(char *) addrtype =3D NULL; + VIR_AUTOFREE(char *) domain_name =3D NULL; + VIR_AUTOFREE(char *) vhostuser_mode =3D NULL; + VIR_AUTOFREE(char *) vhostuser_path =3D NULL; + VIR_AUTOFREE(char *) vhostuser_type =3D NULL; + VIR_AUTOFREE(char *) trustGuestRxFilters =3D NULL; + VIR_AUTOFREE(char *) vhost_path =3D NULL; =20 if (VIR_ALLOC(def) < 0) return NULL; @@ -12070,44 +11870,8 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlo= pt, =20 cleanup: ctxt->node =3D oldnode; - VIR_FREE(macaddr); - VIR_FREE(network); - VIR_FREE(portgroup); - VIR_FREE(address); - VIR_FREE(port); - VIR_FREE(vhostuser_type); - VIR_FREE(vhostuser_path); - VIR_FREE(vhostuser_mode); - VIR_FREE(ifname); - VIR_FREE(ifname_guest); - VIR_FREE(ifname_guest_actual); - VIR_FREE(dev); virDomainActualNetDefFree(actual); - VIR_FREE(script); - VIR_FREE(bridge); - VIR_FREE(model); - VIR_FREE(backend); - VIR_FREE(txmode); - VIR_FREE(ioeventfd); - VIR_FREE(event_idx); - VIR_FREE(queues); - VIR_FREE(rx_queue_size); - VIR_FREE(tx_queue_size); - VIR_FREE(str); - VIR_FREE(filter); - VIR_FREE(type); - VIR_FREE(internal); - VIR_FREE(devaddr); - VIR_FREE(mode); - VIR_FREE(linkstate); - VIR_FREE(addrtype); - VIR_FREE(domain_name); - VIR_FREE(trustGuestRxFilters); - VIR_FREE(vhost_path); - VIR_FREE(localaddr); - VIR_FREE(localport); virHashFree(filterparams); - return def; =20 error: @@ -12204,14 +11968,13 @@ virDomainChrDefParseTargetXML(virDomainChrDefPtr = def, xmlNodePtr cur, unsigned int flags) { - int ret =3D -1; xmlNodePtr child; unsigned int port; - char *targetType =3D virXMLPropString(cur, "type"); - char *targetModel =3D NULL; - char *addrStr =3D NULL; - char *portStr =3D NULL; - char *stateStr =3D NULL; + VIR_AUTOFREE(char *) targetType =3D virXMLPropString(cur, "type"); + VIR_AUTOFREE(char *) targetModel =3D NULL; + VIR_AUTOFREE(char *) addrStr =3D NULL; + VIR_AUTOFREE(char *) portStr =3D NULL; + VIR_AUTOFREE(char *) stateStr =3D NULL; =20 if ((def->targetType =3D virDomainChrTargetTypeFromString(def->deviceType, @@ -12219,7 +11982,7 @@ virDomainChrDefParseTargetXML(virDomainChrDefPtr de= f, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown target type '%s' specified for character= device"), targetType); - goto error; + return -1; } =20 child =3D cur->children; @@ -12237,7 +12000,7 @@ virDomainChrDefParseTargetXML(virDomainChrDefPtr de= f, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown target model '%s' specified for characte= r device"), targetModel); - goto error; + return -1; } =20 switch (def->deviceType) { @@ -12248,37 +12011,37 @@ virDomainChrDefParseTargetXML(virDomainChrDefPtr = def, portStr =3D virXMLPropString(cur, "port"); =20 if (VIR_ALLOC(def->target.addr) < 0) - goto error; + return -1; =20 if (addrStr =3D=3D NULL) { virReportError(VIR_ERR_XML_ERROR, "%s", _("guestfwd channel does not " "define a target address")); - goto error; + return -1; } =20 if (virSocketAddrParse(def->target.addr, addrStr, AF_UNSPEC) <= 0) - goto error; + return -1; =20 if (def->target.addr->data.stor.ss_family !=3D AF_INET) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("guestfwd channel only supports " "IPv4 addresses")); - goto error; + return -1; } =20 if (portStr =3D=3D NULL) { virReportError(VIR_ERR_XML_ERROR, "%s", _("guestfwd channel does " "not define a target port")); - goto error; + return -1; } =20 if (virStrToLong_ui(portStr, NULL, 10, &port) < 0) { virReportError(VIR_ERR_XML_ERROR, _("Invalid port number: %s"), portStr); - goto error; + return -1; } =20 virSocketAddrSetPort(def->target.addr, port); @@ -12297,7 +12060,7 @@ virDomainChrDefParseTargetXML(virDomainChrDefPtr de= f, virReportError(VIR_ERR_XML_ERROR, _("invalid channel state value '%s'"), stateStr); - goto error; + return -1; } =20 def->state =3D tmp; @@ -12318,22 +12081,13 @@ virDomainChrDefParseTargetXML(virDomainChrDefPtr = def, virReportError(VIR_ERR_XML_ERROR, _("Invalid port number: %s"), portStr); - goto error; + return -1; } def->target.port =3D port; break; } =20 - - ret =3D 0; - error: - VIR_FREE(targetType); - VIR_FREE(targetModel); - VIR_FREE(addrStr); - VIR_FREE(portStr); - VIR_FREE(stateStr); - - return ret; + return 0; } =20 typedef enum { @@ -12352,20 +12106,17 @@ typedef enum { static int virDomainChrSourceDefParseMode(xmlNodePtr source) { - char *mode =3D virXMLPropString(source, "mode"); - int ret =3D -1; + VIR_AUTOFREE(char *) mode =3D virXMLPropString(source, "mode"); =20 if (!mode || STREQ(mode, "connect")) { - ret =3D VIR_DOMAIN_CHR_SOURCE_MODE_CONNECT; + return VIR_DOMAIN_CHR_SOURCE_MODE_CONNECT; } else if (STREQ(mode, "bind")) { - ret =3D VIR_DOMAIN_CHR_SOURCE_MODE_BIND; - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unknown source mode '%s'"), mode); + return VIR_DOMAIN_CHR_SOURCE_MODE_BIND; } =20 - VIR_FREE(mode); - return ret; + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unknown source mode '%s'"), mode); + return -1; } =20 =20 @@ -12376,11 +12127,11 @@ virDomainChrSourceDefParseTCP(virDomainChrSourceD= efPtr def, unsigned int flags) { int mode; - char *tmp =3D NULL; int tmpVal; + VIR_AUTOFREE(char *) tmp =3D NULL; =20 if ((mode =3D virDomainChrSourceDefParseMode(source)) < 0) - goto error; + return -1; =20 def->data.tcp.listen =3D mode =3D=3D VIR_DOMAIN_CHR_SOURCE_MODE_BIND; def->data.tcp.host =3D virXMLPropString(source, "host"); @@ -12391,7 +12142,7 @@ virDomainChrSourceDefParseTCP(virDomainChrSourceDef= Ptr def, virReportError(VIR_ERR_XML_ERROR, _("unknown chardev 'tls' setting '%s'"), tmp); - goto error; + return -1; } VIR_FREE(tmp); } @@ -12402,23 +12153,18 @@ virDomainChrSourceDefParseTCP(virDomainChrSourceD= efPtr def, virReportError(VIR_ERR_XML_ERROR, _("Invalid tlsFromConfig value: %s"), tmp); - goto error; + return -1; } def->data.tcp.tlsFromConfig =3D !!tmpVal; - VIR_FREE(tmp); } =20 if (virDomainChrSourceReconnectDefParseXML(&def->data.tcp.reconnect, source, ctxt) < 0) { - goto error; + return -1; } =20 return 0; - - error: - VIR_FREE(tmp); - return -1; } =20 =20 @@ -12472,7 +12218,7 @@ static int virDomainChrSourceDefParseFile(virDomainChrSourceDefPtr def, xmlNodePtr source) { - char *append =3D NULL; + VIR_AUTOFREE(char *) append =3D NULL; =20 def->data.file.path =3D virXMLPropString(source, "path"); =20 @@ -12481,11 +12227,9 @@ virDomainChrSourceDefParseFile(virDomainChrSourceD= efPtr def, virReportError(VIR_ERR_INTERNAL_ERROR, _("Invalid append attribute value '%s'"), append); - VIR_FREE(append); return -1; } =20 - VIR_FREE(append); return 0; } =20 @@ -12494,7 +12238,7 @@ static int virDomainChrSourceDefParseProtocol(virDomainChrSourceDefPtr def, xmlNodePtr protocol) { - char *prot =3D NULL; + VIR_AUTOFREE(char *)prot =3D NULL; =20 if (def->type !=3D VIR_DOMAIN_CHR_TYPE_TCP) return 0; @@ -12504,11 +12248,9 @@ virDomainChrSourceDefParseProtocol(virDomainChrSou= rceDefPtr def, virDomainChrTcpProtocolTypeFromString(prot)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unknown protocol '%s'"), prot); - VIR_FREE(prot); return -1; } =20 - VIR_FREE(prot); return 0; } =20 @@ -12517,7 +12259,7 @@ static int virDomainChrSourceDefParseLog(virDomainChrSourceDefPtr def, xmlNodePtr log) { - char *append =3D NULL; + VIR_AUTOFREE(char *)append =3D NULL; =20 def->logfile =3D virXMLPropString(log, "file"); =20 @@ -12526,11 +12268,9 @@ virDomainChrSourceDefParseLog(virDomainChrSourceDe= fPtr def, virReportError(VIR_ERR_INTERNAL_ERROR, _("Invalid append attribute value '%s'"), append); - VIR_FREE(append); return -1; } =20 - VIR_FREE(append); return 0; } =20 @@ -12778,10 +12518,10 @@ virDomainChrDefParseXML(virDomainXMLOptionPtr xml= opt, unsigned int flags) { xmlNodePtr cur; - char *type =3D NULL; const char *nodeName; virDomainChrDefPtr def; bool seenTarget =3D false; + VIR_AUTOFREE(char *) type =3D NULL; =20 if (!(def =3D virDomainChrDefNew(xmlopt))) return NULL; @@ -12848,8 +12588,6 @@ virDomainChrDefParseXML(virDomainXMLOptionPtr xmlop= t, } =20 cleanup: - VIR_FREE(type); - return def; =20 error: @@ -12865,10 +12603,10 @@ virDomainSmartcardDefParseXML(virDomainXMLOptionP= tr xmlopt, unsigned int flags) { xmlNodePtr cur; - char *mode =3D NULL; - char *type =3D NULL; virDomainSmartcardDefPtr def; size_t i; + VIR_AUTOFREE(char *) mode =3D NULL; + VIR_AUTOFREE(char *) type =3D NULL; =20 if (VIR_ALLOC(def) < 0) return NULL; @@ -12980,9 +12718,6 @@ virDomainSmartcardDefParseXML(virDomainXMLOptionPtr= xmlopt, } =20 cleanup: - VIR_FREE(mode); - VIR_FREE(type); - return def; =20 error: @@ -13013,15 +12748,15 @@ virDomainTPMDefParseXML(virDomainXMLOptionPtr xml= opt, xmlXPathContextPtr ctxt, unsigned int flags) { - char *type =3D NULL; - char *path =3D NULL; - char *model =3D NULL; - char *backend =3D NULL; - char *version =3D NULL; virDomainTPMDefPtr def; xmlNodePtr save =3D ctxt->node; - xmlNodePtr *backends =3D NULL; int nbackends; + VIR_AUTOFREE(char *) type =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; + VIR_AUTOFREE(char *) model =3D NULL; + VIR_AUTOFREE(char *) backend =3D NULL; + VIR_AUTOFREE(char *) version =3D NULL; + VIR_AUTOFREE(xmlNodePtr *) backends =3D NULL; =20 if (VIR_ALLOC(def) < 0) return NULL; @@ -13094,12 +12829,6 @@ virDomainTPMDefParseXML(virDomainXMLOptionPtr xmlo= pt, goto error; =20 cleanup: - VIR_FREE(type); - VIR_FREE(path); - VIR_FREE(model); - VIR_FREE(backend); - VIR_FREE(backends); - VIR_FREE(version); ctxt->node =3D save; return def; =20 @@ -13115,7 +12844,7 @@ virDomainPanicDefParseXML(virDomainXMLOptionPtr xml= opt, unsigned int flags) { virDomainPanicDefPtr panic; - char *model =3D NULL; + VIR_AUTOFREE(char *) model =3D NULL; =20 if (VIR_ALLOC(panic) < 0) return NULL; @@ -13133,7 +12862,6 @@ virDomainPanicDefParseXML(virDomainXMLOptionPtr xml= opt, } =20 cleanup: - VIR_FREE(model); return panic; =20 error: @@ -13152,9 +12880,9 @@ virDomainInputDefParseXML(virDomainXMLOptionPtr xml= opt, { xmlNodePtr save =3D ctxt->node; virDomainInputDefPtr def; - char *evdev =3D NULL; - char *type =3D NULL; - char *bus =3D NULL; + VIR_AUTOFREE(char *) evdev =3D NULL; + VIR_AUTOFREE(char *) type =3D NULL; + VIR_AUTOFREE(char *) bus =3D NULL; =20 if (VIR_ALLOC(def) < 0) return NULL; @@ -13282,10 +13010,6 @@ virDomainInputDefParseXML(virDomainXMLOptionPtr xm= lopt, goto error; =20 cleanup: - VIR_FREE(evdev); - VIR_FREE(type); - VIR_FREE(bus); - ctxt->node =3D save; return def; =20 @@ -13303,7 +13027,7 @@ virDomainHubDefParseXML(virDomainXMLOptionPtr xmlop= t, unsigned int flags) { virDomainHubDefPtr def; - char *type =3D NULL; + VIR_AUTOFREE(char *) type =3D NULL; =20 if (VIR_ALLOC(def) < 0) return NULL; @@ -13326,8 +13050,6 @@ virDomainHubDefParseXML(virDomainXMLOptionPtr xmlop= t, goto error; =20 cleanup: - VIR_FREE(type); - return def; =20 error: @@ -13342,16 +13064,15 @@ static virDomainTimerDefPtr virDomainTimerDefParseXML(xmlNodePtr node, xmlXPathContextPtr ctxt) { - char *name =3D NULL; - char *present =3D NULL; - char *tickpolicy =3D NULL; - char *track =3D NULL; - char *mode =3D NULL; - virDomainTimerDefPtr def; xmlNodePtr oldnode =3D ctxt->node; xmlNodePtr catchup; int ret; + VIR_AUTOFREE(char *) name =3D NULL; + VIR_AUTOFREE(char *) present =3D NULL; + VIR_AUTOFREE(char *) tickpolicy =3D NULL; + VIR_AUTOFREE(char *) track =3D NULL; + VIR_AUTOFREE(char *) mode =3D NULL; =20 if (VIR_ALLOC(def) < 0) return NULL; @@ -13454,11 +13175,6 @@ virDomainTimerDefParseXML(xmlNodePtr node, } =20 cleanup: - VIR_FREE(name); - VIR_FREE(present); - VIR_FREE(tickpolicy); - VIR_FREE(track); - VIR_FREE(mode); ctxt->node =3D oldnode; =20 return def; @@ -13474,8 +13190,8 @@ virDomainGraphicsAuthDefParseXML(xmlNodePtr node, virDomainGraphicsAuthDefPtr def, int type) { - char *validTo =3D NULL; - char *connected =3D virXMLPropString(node, "connected"); + VIR_AUTOFREE(char *) validTo =3D NULL; + VIR_AUTOFREE(char *) connected =3D virXMLPropString(node, "connected"); =20 def->passwd =3D virXMLPropString(node, "passwd"); =20 @@ -13503,11 +13219,9 @@ virDomainGraphicsAuthDefParseXML(xmlNodePtr node, virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse password validity time '%s', ex= pect YYYY-MM-DDTHH:MM:SS"), validTo); - VIR_FREE(validTo); VIR_FREE(def->passwd); return -1; } - VIR_FREE(validTo); =20 tm.tm_year -=3D 1900; /* Human epoch starts at 0 BC, not 1900BC */ tm.tm_mon--; /* Humans start months at 1, computers at 0 */ @@ -13522,10 +13236,8 @@ virDomainGraphicsAuthDefParseXML(xmlNodePtr node, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown connected value %s"), connected); - VIR_FREE(connected); return -1; } - VIR_FREE(connected); =20 /* VNC supports connected=3D'keep' only */ if (type =3D=3D VIR_DOMAIN_GRAPHICS_TYPE_VNC && @@ -13563,16 +13275,16 @@ virDomainGraphicsListenDefParseXML(virDomainGraph= icsListenDefPtr def, unsigned int flags) { int ret =3D -1; - char *type =3D virXMLPropString(node, "type"); - char *address =3D virXMLPropString(node, "address"); - char *network =3D virXMLPropString(node, "network"); - char *socketPath =3D virXMLPropString(node, "socket"); - char *fromConfig =3D virXMLPropString(node, "fromConfig"); - char *autoGenerated =3D virXMLPropString(node, "autoGenerated"); - char *addressCompat =3D NULL; - char *socketCompat =3D NULL; const char *graphicsType =3D virDomainGraphicsTypeToString(graphics->t= ype); int tmp, typeVal; + VIR_AUTOFREE(char *) type =3D virXMLPropString(node, "type"); + VIR_AUTOFREE(char *) address =3D virXMLPropString(node, "address"); + VIR_AUTOFREE(char *) network =3D virXMLPropString(node, "network"); + VIR_AUTOFREE(char *) socketPath =3D virXMLPropString(node, "socket"); + VIR_AUTOFREE(char *) fromConfig =3D virXMLPropString(node, "fromConfig= "); + VIR_AUTOFREE(char *) autoGenerated =3D virXMLPropString(node, "autoGen= erated"); + VIR_AUTOFREE(char *) addressCompat =3D NULL; + VIR_AUTOFREE(char *) socketCompat =3D NULL; =20 if (parent) { addressCompat =3D virXMLPropString(parent, "listen"); @@ -13697,14 +13409,6 @@ virDomainGraphicsListenDefParseXML(virDomainGraphi= csListenDefPtr def, error: if (ret < 0) virDomainGraphicsListenDefClear(def); - VIR_FREE(type); - VIR_FREE(address); - VIR_FREE(network); - VIR_FREE(socketPath); - VIR_FREE(fromConfig); - VIR_FREE(autoGenerated); - VIR_FREE(addressCompat); - VIR_FREE(socketCompat); return ret; } =20 @@ -13715,12 +13419,12 @@ virDomainGraphicsListensParseXML(virDomainGraphic= sDefPtr def, xmlXPathContextPtr ctxt, unsigned int flags) { - xmlNodePtr *listenNodes =3D NULL; xmlNodePtr save =3D ctxt->node; virDomainGraphicsListenDef newListen =3D {0}; - char *socketPath =3D NULL; int nListens; int ret =3D -1; + VIR_AUTOFREE(xmlNodePtr *) listenNodes =3D NULL; + VIR_AUTOFREE(char *) socketPath =3D NULL; =20 ctxt->node =3D node; =20 @@ -13744,7 +13448,6 @@ virDomainGraphicsListensParseXML(virDomainGraphicsD= efPtr def, =20 def->nListens++; } - VIR_FREE(listenNodes); } =20 /* If no element was found in XML for backward compatibility @@ -13787,8 +13490,6 @@ virDomainGraphicsListensParseXML(virDomainGraphicsD= efPtr def, ret =3D 0; cleanup: virDomainGraphicsListenDefClear(&newListen); - VIR_FREE(listenNodes); - VIR_FREE(socketPath); ctxt->node =3D save; return ret; } @@ -13800,21 +13501,20 @@ virDomainGraphicsDefParseXMLVNC(virDomainGraphics= DefPtr def, xmlXPathContextPtr ctxt, unsigned int flags) { - char *port =3D virXMLPropString(node, "port"); - char *websocket =3D virXMLPropString(node, "websocket"); - char *websocketGenerated =3D virXMLPropString(node, "websocketGenerate= d"); - char *sharePolicy =3D virXMLPropString(node, "sharePolicy"); - char *autoport =3D virXMLPropString(node, "autoport"); - int ret =3D -1; + VIR_AUTOFREE(char *) port =3D virXMLPropString(node, "port"); + VIR_AUTOFREE(char *) websocket =3D virXMLPropString(node, "websocket"); + VIR_AUTOFREE(char *) websocketGenerated =3D virXMLPropString(node, "we= bsocketGenerated"); + VIR_AUTOFREE(char *) sharePolicy =3D virXMLPropString(node, "sharePoli= cy"); + VIR_AUTOFREE(char *) autoport =3D virXMLPropString(node, "autoport"); =20 if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0) - goto cleanup; + return -1; =20 if (port) { if (virStrToLong_i(port, NULL, 10, &def->data.vnc.port) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse vnc port %s"), port); - goto cleanup; + return -1; } /* Legacy compat syntax, used -1 for auto-port */ if (def->data.vnc.port =3D=3D -1) { @@ -13843,7 +13543,7 @@ virDomainGraphicsDefParseXMLVNC(virDomainGraphicsDe= fPtr def, &def->data.vnc.websocket) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse vnc WebSocket port %s"), websoc= ket); - goto cleanup; + return -1; } } =20 @@ -13858,7 +13558,7 @@ virDomainGraphicsDefParseXMLVNC(virDomainGraphicsDe= fPtr def, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown vnc display sharing policy '%s'"), sharePolicy); - goto cleanup; + return -1; } else { def->data.vnc.sharePolicy =3D policy; } @@ -13868,16 +13568,9 @@ virDomainGraphicsDefParseXMLVNC(virDomainGraphicsD= efPtr def, =20 if (virDomainGraphicsAuthDefParseXML(node, &def->data.vnc.auth, def->type) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - VIR_FREE(port); - VIR_FREE(autoport); - VIR_FREE(websocket); - VIR_FREE(websocketGenerated); - VIR_FREE(sharePolicy); - return ret; + return 0; } =20 =20 @@ -13887,11 +13580,11 @@ virDomainGraphicsDefParseXMLSDL(virDomainGraphics= DefPtr def, xmlXPathContextPtr ctxt) { xmlNodePtr save =3D ctxt->node; - char *enable =3D NULL; int enableVal; xmlNodePtr glNode; - char *fullscreen =3D virXMLPropString(node, "fullscreen"); int ret =3D -1; + VIR_AUTOFREE(char *) fullscreen =3D virXMLPropString(node, "fullscreen= "); + VIR_AUTOFREE(char *) enable =3D NULL; =20 ctxt->node =3D node; =20 @@ -13932,8 +13625,6 @@ virDomainGraphicsDefParseXMLSDL(virDomainGraphicsDe= fPtr def, =20 ret =3D 0; cleanup: - VIR_FREE(fullscreen); - VIR_FREE(enable); ctxt->node =3D save; return ret; } @@ -13945,20 +13636,19 @@ virDomainGraphicsDefParseXMLRDP(virDomainGraphics= DefPtr def, xmlXPathContextPtr ctxt, unsigned int flags) { - char *port =3D virXMLPropString(node, "port"); - char *autoport =3D virXMLPropString(node, "autoport"); - char *replaceUser =3D virXMLPropString(node, "replaceUser"); - char *multiUser =3D virXMLPropString(node, "multiUser"); - int ret =3D -1; + VIR_AUTOFREE(char *) port =3D virXMLPropString(node, "port"); + VIR_AUTOFREE(char *) autoport =3D virXMLPropString(node, "autoport"); + VIR_AUTOFREE(char *) replaceUser =3D virXMLPropString(node, "replaceUs= er"); + VIR_AUTOFREE(char *) multiUser =3D virXMLPropString(node, "multiUser"); =20 if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0) - goto error; + return -1; =20 if (port) { if (virStrToLong_i(port, NULL, 10, &def->data.rdp.port) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse rdp port %s"), port); - goto error; + return -1; } /* Legacy compat syntax, used -1 for auto-port */ if (def->data.rdp.port =3D=3D -1) @@ -13981,13 +13671,7 @@ virDomainGraphicsDefParseXMLRDP(virDomainGraphicsD= efPtr def, if (STREQ_NULLABLE(multiUser, "yes")) def->data.rdp.multiUser =3D true; =20 - ret =3D 0; - error: - VIR_FREE(port); - VIR_FREE(autoport); - VIR_FREE(replaceUser); - VIR_FREE(multiUser); - return ret; + return 0; } =20 =20 @@ -13995,8 +13679,7 @@ static int virDomainGraphicsDefParseXMLDesktop(virDomainGraphicsDefPtr def, xmlNodePtr node) { - char *fullscreen =3D virXMLPropString(node, "fullscreen"); - int ret =3D -1; + VIR_AUTOFREE(char *) fullscreen =3D virXMLPropString(node, "fullscreen= "); =20 if (fullscreen !=3D NULL) { if (STREQ(fullscreen, "yes")) { @@ -14006,7 +13689,7 @@ virDomainGraphicsDefParseXMLDesktop(virDomainGraphi= csDefPtr def, } else { virReportError(VIR_ERR_INTERNAL_ERROR, _("unknown fullscreen value '%s'"), fullscreen); - goto cleanup; + return -1; } } else { def->data.desktop.fullscreen =3D false; @@ -14014,10 +13697,7 @@ virDomainGraphicsDefParseXMLDesktop(virDomainGraph= icsDefPtr def, =20 def->data.desktop.display =3D virXMLPropString(node, "display"); =20 - ret =3D 0; - cleanup: - VIR_FREE(fullscreen); - return ret; + return 0; } =20 =20 @@ -14028,21 +13708,20 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphi= csDefPtr def, unsigned int flags) { xmlNodePtr cur; - char *port =3D virXMLPropString(node, "port"); - char *tlsPort =3D virXMLPropString(node, "tlsPort"); - char *autoport =3D virXMLPropString(node, "autoport"); - char *defaultMode =3D virXMLPropString(node, "defaultMode"); int defaultModeVal; - int ret =3D -1; + VIR_AUTOFREE(char *) port =3D virXMLPropString(node, "port"); + VIR_AUTOFREE(char *) tlsPort =3D virXMLPropString(node, "tlsPort"); + VIR_AUTOFREE(char *) autoport =3D virXMLPropString(node, "autoport"); + VIR_AUTOFREE(char *) defaultMode =3D virXMLPropString(node, "defaultMo= de"); =20 if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0) - goto error; + return -1; =20 if (port) { if (virStrToLong_i(port, NULL, 10, &def->data.spice.port) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse spice port %s"), port); - goto error; + return -1; } } else { def->data.spice.port =3D 0; @@ -14052,7 +13731,7 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphics= DefPtr def, if (virStrToLong_i(tlsPort, NULL, 10, &def->data.spice.tlsPort) < = 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse spice tlsPort %s"), tlsPort); - goto error; + return -1; } } else { def->data.spice.tlsPort =3D 0; @@ -14068,7 +13747,7 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphics= DefPtr def, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown default spice channel mode %s"), defaultMode); - goto error; + return -1; } def->data.spice.defaultMode =3D defaultModeVal; } @@ -14087,53 +13766,47 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphi= csDefPtr def, =20 if (virDomainGraphicsAuthDefParseXML(node, &def->data.spice.auth, def->type) < 0) - goto error; + return -1; =20 cur =3D node->children; while (cur !=3D NULL) { if (cur->type =3D=3D XML_ELEMENT_NODE) { if (virXMLNodeNameEqual(cur, "channel")) { - char *name, *mode; int nameval, modeval; + VIR_AUTOFREE(char *) name =3D NULL; + VIR_AUTOFREE(char *) mode =3D NULL; + name =3D virXMLPropString(cur, "name"); mode =3D virXMLPropString(cur, "mode"); =20 if (!name || !mode) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("spice channel missing name/mode")); - VIR_FREE(name); - VIR_FREE(mode); - goto error; + return -1; } =20 if ((nameval =3D virDomainGraphicsSpiceChannelNameTypeFrom= String(name)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown spice channel name %s"), name); - VIR_FREE(name); - VIR_FREE(mode); - goto error; + return -1; } if ((modeval =3D virDomainGraphicsSpiceChannelModeTypeFrom= String(mode)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown spice channel mode %s"), mode); - VIR_FREE(name); - VIR_FREE(mode); - goto error; + return -1; } - VIR_FREE(name); - VIR_FREE(mode); =20 def->data.spice.channels[nameval] =3D modeval; } else if (virXMLNodeNameEqual(cur, "image")) { - char *compression =3D virXMLPropString(cur, "compression"); int compressionVal; + VIR_AUTOFREE(char *) compression =3D virXMLPropString(cur,= "compression"); =20 if (!compression) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("spice image missing compression")); - goto error; + return -1; } =20 if ((compressionVal =3D @@ -14141,20 +13814,18 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphi= csDefPtr def, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown spice image compression %s"), compression); - VIR_FREE(compression); - goto error; + return -1; } - VIR_FREE(compression); =20 def->data.spice.image =3D compressionVal; } else if (virXMLNodeNameEqual(cur, "jpeg")) { - char *compression =3D virXMLPropString(cur, "compression"); int compressionVal; + VIR_AUTOFREE(char *) compression =3D virXMLPropString(cur,= "compression"); =20 if (!compression) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("spice jpeg missing compression")); - goto error; + return -1; } =20 if ((compressionVal =3D @@ -14162,20 +13833,18 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphi= csDefPtr def, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown spice jpeg compression %s"), compression); - VIR_FREE(compression); - goto error; + return -1; } - VIR_FREE(compression); =20 def->data.spice.jpeg =3D compressionVal; } else if (virXMLNodeNameEqual(cur, "zlib")) { - char *compression =3D virXMLPropString(cur, "compression"); int compressionVal; + VIR_AUTOFREE(char *) compression =3D virXMLPropString(cur,= "compression"); =20 if (!compression) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("spice zlib missing compression")); - goto error; + return -1; } =20 if ((compressionVal =3D @@ -14183,136 +13852,118 @@ virDomainGraphicsDefParseXMLSpice(virDomainGrap= hicsDefPtr def, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown spice zlib compression %s"), compression); - VIR_FREE(compression); - goto error; + return -1; } - VIR_FREE(compression); =20 def->data.spice.zlib =3D compressionVal; } else if (virXMLNodeNameEqual(cur, "playback")) { - char *compression =3D virXMLPropString(cur, "compression"); int compressionVal; + VIR_AUTOFREE(char *) compression =3D virXMLPropString(cur,= "compression"); =20 if (!compression) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("spice playback missing compression")= ); - goto error; + return -1; } =20 if ((compressionVal =3D virTristateSwitchTypeFromString(compression)) <=3D 0)= { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("unknown spice playback compression")= ); - VIR_FREE(compression); - goto error; - + return -1; } - VIR_FREE(compression); =20 def->data.spice.playback =3D compressionVal; } else if (virXMLNodeNameEqual(cur, "streaming")) { - char *mode =3D virXMLPropString(cur, "mode"); int modeVal; + VIR_AUTOFREE(char *) mode =3D virXMLPropString(cur, "mode"= ); =20 if (!mode) { virReportError(VIR_ERR_XML_ERROR, "%s", _("spice streaming missing mode")); - goto error; + return -1; } if ((modeVal =3D virDomainGraphicsSpiceStreamingModeTypeFromString(mod= e)) <=3D 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("unknown spice streaming mode")); - VIR_FREE(mode); - goto error; - + return -1; } - VIR_FREE(mode); =20 def->data.spice.streaming =3D modeVal; } else if (virXMLNodeNameEqual(cur, "clipboard")) { - char *copypaste =3D virXMLPropString(cur, "copypaste"); int copypasteVal; + VIR_AUTOFREE(char *) copypaste =3D virXMLPropString(cur, "= copypaste"); =20 if (!copypaste) { virReportError(VIR_ERR_XML_ERROR, "%s", _("spice clipboard missing copypaste")); - goto error; + return -1; } =20 if ((copypasteVal =3D virTristateBoolTypeFromString(copypaste)) <=3D 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown copypaste value '%s'"), copy= paste); - VIR_FREE(copypaste); - goto error; + return -1; } - VIR_FREE(copypaste); =20 def->data.spice.copypaste =3D copypasteVal; } else if (virXMLNodeNameEqual(cur, "filetransfer")) { - char *enable =3D virXMLPropString(cur, "enable"); int enableVal; + VIR_AUTOFREE(char *) enable =3D virXMLPropString(cur, "ena= ble"); =20 if (!enable) { virReportError(VIR_ERR_XML_ERROR, "%s", _("spice filetransfer missing enable")); - goto error; + return -1; } =20 if ((enableVal =3D virTristateBoolTypeFromString(enable)) <=3D 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown enable value '%s'"), enable); - VIR_FREE(enable); - goto error; + return -1; } - VIR_FREE(enable); =20 def->data.spice.filetransfer =3D enableVal; } else if (virXMLNodeNameEqual(cur, "gl")) { - char *enable =3D virXMLPropString(cur, "enable"); - char *rendernode =3D virXMLPropString(cur, "rendernode"); int enableVal; + VIR_AUTOFREE(char *) enable =3D virXMLPropString(cur, "ena= ble"); + VIR_AUTOFREE(char *) rendernode =3D virXMLPropString(cur, = "rendernode"); =20 if (!enable) { virReportError(VIR_ERR_XML_ERROR, "%s", _("spice gl element missing enable")); - VIR_FREE(rendernode); - goto error; + return -1; } =20 if ((enableVal =3D virTristateBoolTypeFromString(enable)) <=3D 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown enable value '%s'"), enable); - VIR_FREE(enable); - VIR_FREE(rendernode); - goto error; + return -1; } - VIR_FREE(enable); =20 def->data.spice.gl =3D enableVal; VIR_STEAL_PTR(def->data.spice.rendernode, rendernode); =20 } else if (virXMLNodeNameEqual(cur, "mouse")) { - char *mode =3D virXMLPropString(cur, "mode"); int modeVal; + VIR_AUTOFREE(char *) mode =3D virXMLPropString(cur, "mode"= ); =20 if (!mode) { virReportError(VIR_ERR_XML_ERROR, "%s", _("spice mouse missing mode")); - goto error; + return -1; } =20 if ((modeVal =3D virDomainGraphicsSpiceMouseModeTypeFromSt= ring(mode)) <=3D 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown mouse mode value '%s'"), mode); - VIR_FREE(mode); - goto error; + return -1; } - VIR_FREE(mode); =20 def->data.spice.mousemode =3D modeVal; } @@ -14320,13 +13971,7 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphic= sDefPtr def, cur =3D cur->next; } =20 - ret =3D 0; - error: - VIR_FREE(port); - VIR_FREE(tlsPort); - VIR_FREE(autoport); - VIR_FREE(defaultMode); - return ret; + return 0; } =20 =20 @@ -14374,8 +14019,8 @@ virDomainGraphicsDefParseXML(virDomainXMLOptionPtr = xmlopt, unsigned int flags) { virDomainGraphicsDefPtr def; - char *type =3D NULL; int typeVal; + VIR_AUTOFREE(char *) type =3D NULL; =20 if (!(def =3D virDomainGraphicsDefNew(xmlopt))) return NULL; @@ -14424,8 +14069,6 @@ virDomainGraphicsDefParseXML(virDomainXMLOptionPtr = xmlopt, } =20 cleanup: - VIR_FREE(type); - return def; =20 error: @@ -14438,8 +14081,8 @@ virDomainGraphicsDefParseXML(virDomainXMLOptionPtr = xmlopt, static virDomainSoundCodecDefPtr virDomainSoundCodecDefParseXML(xmlNodePtr node) { - char *type; virDomainSoundCodecDefPtr def; + VIR_AUTOFREE(char *) type =3D NULL; =20 if (VIR_ALLOC(def) < 0) return NULL; @@ -14452,8 +14095,6 @@ virDomainSoundCodecDefParseXML(xmlNodePtr node) } =20 cleanup: - VIR_FREE(type); - return def; =20 error: @@ -14469,9 +14110,9 @@ virDomainSoundDefParseXML(virDomainXMLOptionPtr xml= opt, xmlXPathContextPtr ctxt, unsigned int flags) { - char *model; virDomainSoundDefPtr def; xmlNodePtr save =3D ctxt->node; + VIR_AUTOFREE(char *) model =3D NULL; =20 if (VIR_ALLOC(def) < 0) return NULL; @@ -14488,7 +14129,7 @@ virDomainSoundDefParseXML(virDomainXMLOptionPtr xml= opt, if (def->model =3D=3D VIR_DOMAIN_SOUND_MODEL_ICH6 || def->model =3D=3D VIR_DOMAIN_SOUND_MODEL_ICH9) { int ncodecs; - xmlNodePtr *codecNodes =3D NULL; + VIR_AUTOFREE(xmlNodePtr *) codecNodes =3D NULL; =20 /* parse the subelements for sound models that support it = */ ncodecs =3D virXPathNodeSet("./codec", ctxt, &codecNodes); @@ -14498,22 +14139,17 @@ virDomainSoundDefParseXML(virDomainXMLOptionPtr x= mlopt, if (ncodecs > 0) { size_t i; =20 - if (VIR_ALLOC_N(def->codecs, ncodecs) < 0) { - VIR_FREE(codecNodes); + if (VIR_ALLOC_N(def->codecs, ncodecs) < 0) goto error; - } =20 for (i =3D 0; i < ncodecs; i++) { virDomainSoundCodecDefPtr codec =3D virDomainSoundCodecDef= ParseXML(codecNodes[i]); - if (codec =3D=3D NULL) { - VIR_FREE(codecNodes); + if (codec =3D=3D NULL) goto error; - } =20 codec->cad =3D def->ncodecs; /* that will do for now */ def->codecs[def->ncodecs++] =3D codec; } - VIR_FREE(codecNodes); } } =20 @@ -14521,8 +14157,6 @@ virDomainSoundDefParseXML(virDomainXMLOptionPtr xml= opt, goto error; =20 cleanup: - VIR_FREE(model); - ctxt->node =3D save; return def; =20 @@ -14538,9 +14172,9 @@ virDomainWatchdogDefParseXML(virDomainXMLOptionPtr = xmlopt, xmlNodePtr node, unsigned int flags) { - char *model =3D NULL; - char *action =3D NULL; virDomainWatchdogDefPtr def; + VIR_AUTOFREE(char *) model =3D NULL; + VIR_AUTOFREE(char *) action =3D NULL; =20 if (VIR_ALLOC(def) < 0) return NULL; @@ -14574,9 +14208,6 @@ virDomainWatchdogDefParseXML(virDomainXMLOptionPtr = xmlopt, goto error; =20 cleanup: - VIR_FREE(action); - VIR_FREE(model); - return def; =20 error: @@ -14592,13 +14223,13 @@ virDomainRNGDefParseXML(virDomainXMLOptionPtr xml= opt, xmlXPathContextPtr ctxt, unsigned int flags) { - char *model =3D NULL; - char *backend =3D NULL; - char *type =3D NULL; virDomainRNGDefPtr def; xmlNodePtr save =3D ctxt->node; - xmlNodePtr *backends =3D NULL; int nbackends; + VIR_AUTOFREE(xmlNodePtr *) backends =3D NULL; + VIR_AUTOFREE(char *) model =3D NULL; + VIR_AUTOFREE(char *) backend =3D NULL; + VIR_AUTOFREE(char *) type =3D NULL; =20 if (VIR_ALLOC(def) < 0) return NULL; @@ -14690,10 +14321,6 @@ virDomainRNGDefParseXML(virDomainXMLOptionPtr xmlo= pt, goto error; =20 cleanup: - VIR_FREE(model); - VIR_FREE(backend); - VIR_FREE(type); - VIR_FREE(backends); ctxt->node =3D save; return def; =20 @@ -14710,11 +14337,11 @@ virDomainMemballoonDefParseXML(virDomainXMLOption= Ptr xmlopt, xmlXPathContextPtr ctxt, unsigned int flags) { - char *model; - char *deflate =3D NULL; virDomainMemballoonDefPtr def; xmlNodePtr save =3D ctxt->node; unsigned int period =3D 0; + VIR_AUTOFREE(char *) model =3D NULL; + VIR_AUTOFREE(char *) deflate =3D NULL; =20 if (VIR_ALLOC(def) < 0) return NULL; @@ -14761,9 +14388,6 @@ virDomainMemballoonDefParseXML(virDomainXMLOptionPt= r xmlopt, goto error; =20 cleanup: - VIR_FREE(model); - VIR_FREE(deflate); - ctxt->node =3D save; return def; =20 @@ -14799,13 +14423,12 @@ virDomainShmemDefParseXML(virDomainXMLOptionPtr x= mlopt, xmlXPathContextPtr ctxt, unsigned int flags) { - char *tmp =3D NULL; virDomainShmemDefPtr def =3D NULL; virDomainShmemDefPtr ret =3D NULL; xmlNodePtr msi =3D NULL; xmlNodePtr save =3D ctxt->node; xmlNodePtr server =3D NULL; - + VIR_AUTOFREE(char *) tmp =3D NULL; =20 if (VIR_ALLOC(def) < 0) return NULL; @@ -14869,7 +14492,6 @@ virDomainShmemDefParseXML(virDomainXMLOptionPtr xml= opt, } def->msi.ioeventfd =3D val; } - VIR_FREE(tmp); } =20 /* msi option is only relevant with a server */ @@ -14886,7 +14508,6 @@ virDomainShmemDefParseXML(virDomainXMLOptionPtr xml= opt, VIR_STEAL_PTR(ret, def); cleanup: ctxt->node =3D save; - VIR_FREE(tmp); virDomainShmemDefFree(def); return ret; } @@ -14958,7 +14579,7 @@ virSysinfoSystemParseXML(xmlNodePtr node, { int ret =3D -1; virSysinfoSystemDefPtr def; - char *tmpUUID =3D NULL; + VIR_AUTOFREE(char *) tmpUUID =3D NULL; =20 if (!virXMLNodeNameEqual(node, "system")) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -15019,7 +14640,6 @@ virSysinfoSystemParseXML(xmlNodePtr node, ret =3D 0; cleanup: virSysinfoSystemDefFree(def); - VIR_FREE(tmpUUID); return ret; } =20 @@ -15029,10 +14649,11 @@ virSysinfoBaseBoardParseXML(xmlXPathContextPtr ct= xt, size_t *nbaseBoard) { int ret =3D -1; - virSysinfoBaseBoardDefPtr boards =3D NULL; size_t i, nboards =3D 0; - xmlNodePtr *nodes =3D NULL, oldnode =3D ctxt->node; + xmlNodePtr oldnode =3D ctxt->node; int n; + VIR_AUTOFREE(virSysinfoBaseBoardDefPtr) boards =3D NULL; + VIR_AUTOFREE(xmlNodePtr *) nodes =3D NULL; =20 if ((n =3D virXPathNodeSet("./baseBoard", ctxt, &nodes)) < 0) return ret; @@ -15070,8 +14691,6 @@ virSysinfoBaseBoardParseXML(xmlXPathContextPtr ctxt, *nbaseBoard =3D nboards; ret =3D 0; cleanup: - VIR_FREE(boards); - VIR_FREE(nodes); ctxt->node =3D oldnode; return ret; } @@ -15083,9 +14702,9 @@ virSysinfoOEMStringsParseXML(xmlXPathContextPtr ctx= t, { int ret =3D -1; virSysinfoOEMStringsDefPtr def; - xmlNodePtr *strings =3D NULL; int nstrings; size_t i; + VIR_AUTOFREE(xmlNodePtr *) strings =3D NULL; =20 nstrings =3D virXPathNodeSet("./entry", ctxt, &strings); if (nstrings < 0) @@ -15106,7 +14725,6 @@ virSysinfoOEMStringsParseXML(xmlXPathContextPtr ctx= t, VIR_STEAL_PTR(*oem, def); ret =3D 0; cleanup: - VIR_FREE(strings); virSysinfoOEMStringsDefFree(def); return ret; } @@ -15162,7 +14780,7 @@ virSysinfoParseXML(xmlNodePtr node, { virSysinfoDefPtr def; xmlNodePtr oldnode, tmpnode; - char *type; + VIR_AUTOFREE(char *) type =3D NULL; =20 if (!virXMLNodeNameEqual(node, "sysinfo")) { virReportError(VIR_ERR_XML_ERROR, "%s", @@ -15235,7 +14853,6 @@ virSysinfoParseXML(xmlNodePtr node, } =20 cleanup: - VIR_FREE(type); return def; =20 error: @@ -15329,9 +14946,9 @@ virDomainVideoAccelDefParseXML(xmlNodePtr node) { xmlNodePtr cur; virDomainVideoAccelDefPtr def; - char *accel2d =3D NULL; - char *accel3d =3D NULL; int val; + VIR_AUTOFREE(char *) accel2d =3D NULL; + VIR_AUTOFREE(char *) accel3d =3D NULL; =20 cur =3D node->children; while (cur !=3D NULL) { @@ -15370,8 +14987,6 @@ virDomainVideoAccelDefParseXML(xmlNodePtr node) } =20 cleanup: - VIR_FREE(accel2d); - VIR_FREE(accel3d); return def; } =20 @@ -15380,8 +14995,8 @@ virDomainVideoDriverDefParseXML(xmlNodePtr node) { xmlNodePtr cur; virDomainVideoDriverDefPtr def; - char *vgaconf =3D NULL; int val; + VIR_AUTOFREE(char *) vgaconf =3D NULL; =20 cur =3D node->children; while (cur !=3D NULL) { @@ -15408,7 +15023,6 @@ virDomainVideoDriverDefParseXML(xmlNodePtr node) def->vgaconf =3D val; =20 cleanup: - VIR_FREE(vgaconf); return def; } =20 @@ -15422,13 +15036,13 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr x= mlopt, virDomainVideoDefPtr def; xmlNodePtr cur; xmlNodePtr saved =3D ctxt->node; - char *type =3D NULL; - char *heads =3D NULL; - char *vram =3D NULL; - char *vram64 =3D NULL; - char *ram =3D NULL; - char *vgamem =3D NULL; - char *primary =3D NULL; + VIR_AUTOFREE(char *) type =3D NULL; + VIR_AUTOFREE(char *) heads =3D NULL; + VIR_AUTOFREE(char *) vram =3D NULL; + VIR_AUTOFREE(char *) vram64 =3D NULL; + VIR_AUTOFREE(char *) ram =3D NULL; + VIR_AUTOFREE(char *) vgamem =3D NULL; + VIR_AUTOFREE(char *) primary =3D NULL; =20 if (!(def =3D virDomainVideoDefNew())) return NULL; @@ -15535,14 +15149,6 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xm= lopt, =20 cleanup: ctxt->node =3D saved; - - VIR_FREE(type); - VIR_FREE(ram); - VIR_FREE(vram); - VIR_FREE(vram64); - VIR_FREE(vgamem); - VIR_FREE(heads); - return def; =20 error: @@ -15559,8 +15165,8 @@ virDomainHostdevDefParseXML(virDomainXMLOptionPtr x= mlopt, { virDomainHostdevDefPtr def; xmlNodePtr save =3D ctxt->node; - char *mode =3D virXMLPropString(node, "mode"); - char *type =3D virXMLPropString(node, "type"); + VIR_AUTOFREE(char *) mode =3D virXMLPropString(node, "mode"); + VIR_AUTOFREE(char *) type =3D virXMLPropString(node, "type"); =20 ctxt->node =3D node; =20 @@ -15619,8 +15225,6 @@ virDomainHostdevDefParseXML(virDomainXMLOptionPtr x= mlopt, } =20 cleanup: - VIR_FREE(type); - VIR_FREE(mode); ctxt->node =3D save; return def; =20 @@ -15639,7 +15243,8 @@ virDomainRedirdevDefParseXML(virDomainXMLOptionPtr = xmlopt, { xmlNodePtr cur; virDomainRedirdevDefPtr def; - char *bus =3D NULL, *type =3D NULL; + VIR_AUTOFREE(char *) bus =3D NULL; + VIR_AUTOFREE(char *) type =3D NULL; =20 if (VIR_ALLOC(def) < 0) return NULL; @@ -15695,8 +15300,6 @@ virDomainRedirdevDefParseXML(virDomainXMLOptionPtr = xmlopt, =20 =20 cleanup: - VIR_FREE(bus); - VIR_FREE(type); return def; =20 error: @@ -15746,10 +15349,12 @@ virDomainRedirFilterUSBVersionHelper(const char *= version, static virDomainRedirFilterUSBDevDefPtr virDomainRedirFilterUSBDevDefParseXML(xmlNodePtr node) { - char *class; - char *vendor =3D NULL, *product =3D NULL; - char *version =3D NULL, *allow =3D NULL; virDomainRedirFilterUSBDevDefPtr def; + VIR_AUTOFREE(char *) class =3D NULL; + VIR_AUTOFREE(char *) vendor =3D NULL; + VIR_AUTOFREE(char *) product =3D NULL; + VIR_AUTOFREE(char *) version =3D NULL; + VIR_AUTOFREE(char *) allow =3D NULL; =20 if (VIR_ALLOC(def) < 0) return NULL; @@ -15821,11 +15426,6 @@ virDomainRedirFilterUSBDevDefParseXML(xmlNodePtr n= ode) } =20 cleanup: - VIR_FREE(class); - VIR_FREE(vendor); - VIR_FREE(product); - VIR_FREE(version); - VIR_FREE(allow); return def; =20 error: @@ -15840,9 +15440,9 @@ virDomainRedirFilterDefParseXML(xmlNodePtr node, { int n; size_t i; - xmlNodePtr *nodes =3D NULL; xmlNodePtr save =3D ctxt->node; virDomainRedirFilterDefPtr def =3D NULL; + VIR_AUTOFREE(xmlNodePtr *) nodes =3D NULL; =20 if (VIR_ALLOC(def) < 0) goto error; @@ -15862,13 +15462,11 @@ virDomainRedirFilterDefParseXML(xmlNodePtr node, goto error; def->usbdevs[def->nusbdevs++] =3D usbdev; } - VIR_FREE(nodes); =20 ctxt->node =3D save; return def; =20 error: - VIR_FREE(nodes); virDomainRedirFilterDefFree(def); return NULL; } @@ -15881,7 +15479,8 @@ virDomainEventActionParseXML(xmlXPathContextPtr ctx= t, int defaultVal, virEventActionFromStringFunc convFunc) { - char *tmp =3D virXPathString(xpath, ctxt); + VIR_AUTOFREE(char *) tmp =3D virXPathString(xpath, ctxt); + if (tmp =3D=3D NULL) { *val =3D defaultVal; } else { @@ -15889,10 +15488,8 @@ virDomainEventActionParseXML(xmlXPathContextPtr ct= xt, if (*val < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown %s action: %s"), name, tmp); - VIR_FREE(tmp); return -1; } - VIR_FREE(tmp); } return 0; } @@ -15902,21 +15499,18 @@ virDomainPMStateParseXML(xmlXPathContextPtr ctxt, const char *xpath, int *val) { - int ret =3D -1; - char *tmp =3D virXPathString(xpath, ctxt); + VIR_AUTOFREE(char *) tmp =3D virXPathString(xpath, ctxt); + if (tmp) { *val =3D virTristateBoolTypeFromString(tmp); if (*val < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown PM state value %s"), tmp); - goto cleanup; + return -1; } } =20 - ret =3D 0; - cleanup: - VIR_FREE(tmp); - return ret; + return 0; } =20 =20 @@ -15924,47 +15518,41 @@ static int virDomainPerfEventDefParseXML(virDomainPerfDefPtr perf, xmlNodePtr node) { - char *name =3D NULL; - char *enabled =3D NULL; int event; - int ret =3D -1; + VIR_AUTOFREE(char *) name =3D NULL; + VIR_AUTOFREE(char *) enabled =3D NULL; =20 if (!(name =3D virXMLPropString(node, "name"))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing perf event name= ")); - goto cleanup; + return -1; } =20 if ((event =3D virPerfEventTypeFromString(name)) < 0) { virReportError(VIR_ERR_XML_ERROR, _("'unsupported perf event '%s'"), name); - goto cleanup; + return -1; } =20 if (perf->events[event] !=3D VIR_TRISTATE_BOOL_ABSENT) { virReportError(VIR_ERR_XML_ERROR, _("perf event '%s' was already specified"), name); - goto cleanup; + return -1; } =20 if (!(enabled =3D virXMLPropString(node, "enabled"))) { virReportError(VIR_ERR_XML_ERROR, _("missing state of perf event '%s'"), name); - goto cleanup; + return -1; } =20 if ((perf->events[event] =3D virTristateBoolTypeFromString(enabled)) <= 0) { virReportError(VIR_ERR_XML_ERROR, _("invalid state '%s' of perf event '%s'"), enabled, name); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(name); - VIR_FREE(enabled); - return ret; + return 0; } =20 static int @@ -15972,23 +15560,18 @@ virDomainPerfDefParseXML(virDomainDefPtr def, xmlXPathContextPtr ctxt) { size_t i; - int ret =3D -1; - xmlNodePtr *nodes =3D NULL; int n; + VIR_AUTOFREE(xmlNodePtr *) nodes =3D NULL; =20 if ((n =3D virXPathNodeSet("./perf/event", ctxt, &nodes)) < 0) return n; =20 for (i =3D 0; i < n; i++) { if (virDomainPerfEventDefParseXML(&def->perf, nodes[i]) < 0) - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(nodes); - return ret; + return 0; } =20 static int @@ -15997,9 +15580,9 @@ virDomainMemorySourceDefParseXML(xmlNodePtr node, virDomainMemoryDefPtr def) { int ret =3D -1; - char *nodemask =3D NULL; xmlNodePtr save =3D ctxt->node; ctxt->node =3D node; + VIR_AUTOFREE(char *) nodemask =3D NULL; =20 switch ((virDomainMemoryModel) def->model) { case VIR_DOMAIN_MEMORY_MODEL_DIMM: @@ -16044,7 +15627,6 @@ virDomainMemorySourceDefParseXML(xmlNodePtr node, ret =3D 0; =20 cleanup: - VIR_FREE(nodemask); ctxt->node =3D save; return ret; } @@ -16107,10 +15689,10 @@ static virDomainSEVDefPtr virDomainSEVDefParseXML(xmlNodePtr sevNode, xmlXPathContextPtr ctxt) { - char *type =3D NULL; xmlNodePtr save =3D ctxt->node; virDomainSEVDefPtr def; unsigned long policy; + VIR_AUTOFREE(char *) type =3D NULL; =20 if (VIR_ALLOC(def) < 0) return NULL; @@ -16160,7 +15742,6 @@ virDomainSEVDefParseXML(xmlNodePtr sevNode, def->session =3D virXPathString("string(./session)", ctxt); =20 cleanup: - VIR_FREE(type); ctxt->node =3D save; return def; =20 @@ -16176,11 +15757,11 @@ virDomainMemoryDefParseXML(virDomainXMLOptionPtr = xmlopt, xmlXPathContextPtr ctxt, unsigned int flags) { - char *tmp =3D NULL; xmlNodePtr save =3D ctxt->node; xmlNodePtr node; virDomainMemoryDefPtr def; int val; + VIR_AUTOFREE(char *) tmp =3D NULL; =20 if (VIR_ALLOC(def) < 0) return NULL; @@ -16220,7 +15801,6 @@ virDomainMemoryDefParseXML(virDomainXMLOptionPtr xm= lopt, =20 def->discard =3D val; } - VIR_FREE(tmp); =20 /* source */ if ((node =3D virXPathNode("./source", ctxt)) && @@ -16245,7 +15825,6 @@ virDomainMemoryDefParseXML(virDomainXMLOptionPtr xm= lopt, return def; =20 error: - VIR_FREE(tmp); virDomainMemoryDefFree(def); ctxt->node =3D save; return NULL; @@ -16256,11 +15835,12 @@ static virDomainIOMMUDefPtr virDomainIOMMUDefParseXML(xmlNodePtr node, xmlXPathContextPtr ctxt) { - virDomainIOMMUDefPtr iommu =3D NULL, ret =3D NULL; + virDomainIOMMUDefPtr ret =3D NULL; xmlNodePtr save =3D ctxt->node; xmlNodePtr driver; - char *tmp =3D NULL; int val; + VIR_AUTOFREE(char *) tmp =3D NULL; + VIR_AUTOFREE(virDomainIOMMUDefPtr) iommu =3D NULL; =20 ctxt->node =3D node; =20 @@ -16321,8 +15901,6 @@ virDomainIOMMUDefParseXML(xmlNodePtr node, =20 cleanup: ctxt->node =3D save; - VIR_FREE(iommu); - VIR_FREE(tmp); return ret; } =20 @@ -16333,11 +15911,12 @@ virDomainVsockDefParseXML(virDomainXMLOptionPtr x= mlopt, xmlXPathContextPtr ctxt, unsigned int flags) { - virDomainVsockDefPtr vsock =3D NULL, ret =3D NULL; + virDomainVsockDefPtr ret =3D NULL; xmlNodePtr save =3D ctxt->node; xmlNodePtr cid; - char *tmp =3D NULL; int val; + VIR_AUTOFREE(char *) tmp =3D NULL; + VIR_AUTOFREE(virDomainVsockDefPtr) vsock =3D NULL; =20 ctxt->node =3D node; =20 @@ -16386,8 +15965,6 @@ virDomainVsockDefParseXML(virDomainXMLOptionPtr xml= opt, =20 cleanup: ctxt->node =3D save; - VIR_FREE(vsock); - VIR_FREE(tmp); return ret; } =20 @@ -17981,17 +17558,14 @@ virDomainDefGetDefaultEmulator(virDomainDefPtr de= f, virCapsPtr caps) { char *retemu; - virCapsDomainDataPtr capsdata; + VIR_AUTOFREE(virCapsDomainDataPtr) capsdata =3D NULL; =20 if (!(capsdata =3D virCapabilitiesDomainDataLookup(caps, def->os.type, def->os.arch, def->virtType, NULL, NULL))) return NULL; =20 - if (VIR_STRDUP(retemu, capsdata->emulator) < 0) { - VIR_FREE(capsdata); + if (VIR_STRDUP(retemu, capsdata->emulator) < 0) return NULL; - } - VIR_FREE(capsdata); return retemu; } =20 @@ -17999,16 +17573,15 @@ static int virDomainDefParseBootXML(xmlXPathContextPtr ctxt, virDomainDefPtr def) { - xmlNodePtr *nodes =3D NULL; xmlNodePtr node; size_t i; int n; - char *tmp =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) tmp =3D NULL; + VIR_AUTOFREE(xmlNodePtr *) nodes =3D NULL; =20 /* analysis of the boot devices */ if ((n =3D virXPathNodeSet("./os/boot", ctxt, &nodes)) < 0) - goto cleanup; + return -1; =20 for (i =3D 0; i < n && i < VIR_DOMAIN_BOOT_LAST; i++) { int val; @@ -18016,14 +17589,14 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt, if (!dev) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing boot device")); - goto cleanup; + return -1; } if ((val =3D virDomainBootTypeFromString(dev)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown boot device '%s'"), dev); VIR_FREE(dev); - goto cleanup; + return -1; } VIR_FREE(dev); def->os.bootDevs[def->os.nBootDevs++] =3D val; @@ -18051,7 +17624,7 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("invalid value for boot menu timeout, " "must be in range [0,65535]")); - goto cleanup; + return -1; } def->os.bm_timeout_set =3D true; } @@ -18077,18 +17650,13 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("invalid value for rebootTimeout, " "must be in range [-1,65535]")); - goto cleanup; + return -1; } def->os.bios.rt_set =3D true; } } =20 - ret =3D 0; - - cleanup: - VIR_FREE(tmp); - VIR_FREE(nodes); - return ret; + return 0; } =20 =20 @@ -18168,7 +17736,7 @@ static virDomainIOThreadIDDefPtr virDomainIOThreadIDDefParseXML(xmlNodePtr node) { virDomainIOThreadIDDefPtr iothrid; - char *tmp =3D NULL; + VIR_AUTOFREE(char *) tmp =3D NULL; =20 if (VIR_ALLOC(iothrid) < 0) return NULL; @@ -18186,7 +17754,6 @@ virDomainIOThreadIDDefParseXML(xmlNodePtr node) } =20 cleanup: - VIR_FREE(tmp); return iothrid; =20 error: @@ -18201,53 +17768,44 @@ virDomainDefParseIOThreads(virDomainDefPtr def, xmlXPathContextPtr ctxt) { size_t i; - char *tmp; int n =3D 0; unsigned int iothreads =3D 0; - xmlNodePtr *nodes =3D NULL; + VIR_AUTOFREE(char *) tmp =3D NULL; + VIR_AUTOFREE(xmlNodePtr *) nodes =3D NULL; =20 tmp =3D virXPathString("string(./iothreads[1])", ctxt); if (tmp && virStrToLong_uip(tmp, NULL, 10, &iothreads) < 0) { virReportError(VIR_ERR_XML_ERROR, _("invalid iothreads count '%s'"), tmp); - goto error; + return -1; } - VIR_FREE(tmp); =20 /* Extract any iothread id's defined */ if ((n =3D virXPathNodeSet("./iothreadids/iothread", ctxt, &nodes)) < = 0) - goto error; + return -1; =20 if (n > iothreads) iothreads =3D n; =20 if (n && VIR_ALLOC_N(def->iothreadids, n) < 0) - goto error; + return -1; =20 for (i =3D 0; i < n; i++) { virDomainIOThreadIDDefPtr iothrid =3D NULL; if (!(iothrid =3D virDomainIOThreadIDDefParseXML(nodes[i]))) - goto error; + return -1; =20 if (virDomainIOThreadIDFind(def, iothrid->iothread_id)) { virReportError(VIR_ERR_XML_ERROR, _("duplicate iothread id '%u' found"), iothrid->iothread_id); virDomainIOThreadIDDefFree(iothrid); - goto error; + return -1; } def->iothreadids[def->niothreadids++] =3D iothrid; } - VIR_FREE(nodes); - - if (virDomainIOThreadIDDefArrayInit(def, iothreads) < 0) - goto error; - - return 0; =20 - error: - VIR_FREE(nodes); - return -1; + return virDomainIOThreadIDDefArrayInit(def, iothreads); } =20 =20 @@ -18262,53 +17820,47 @@ virDomainVcpuPinDefParseXML(virDomainDefPtr def, { virDomainVcpuDefPtr vcpu; unsigned int vcpuid; - char *tmp =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) tmp =3D NULL; =20 if (!(tmp =3D virXMLPropString(node, "vcpu"))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing vcpu id in vcpu= pin")); - goto cleanup; + return -1; } =20 if (virStrToLong_uip(tmp, NULL, 10, &vcpuid) < 0) { virReportError(VIR_ERR_XML_ERROR, _("invalid setting for vcpu '%s'"), tmp); - goto cleanup; + return -1; } VIR_FREE(tmp); =20 if (!(vcpu =3D virDomainDefGetVcpu(def, vcpuid))) { VIR_WARN("Ignoring vcpupin for missing vcpus"); - ret =3D 0; - goto cleanup; + return 0; } =20 if (!(tmp =3D virXMLPropString(node, "cpuset"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing cpuset for vcpupin")); - goto cleanup; + return -1; } =20 if (vcpu->cpumask) { virReportError(VIR_ERR_INTERNAL_ERROR, _("duplicate vcpupin for vcpu '%d'"), vcpuid); - goto cleanup; + return -1; } =20 if (virBitmapParse(tmp, &vcpu->cpumask, VIR_DOMAIN_CPUMASK_LEN) < 0) - goto cleanup; + return -1; =20 if (virBitmapIsAllClear(vcpu->cpumask)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Invalid value of 'cpuset': %s"), tmp); - goto cleanup; - } - - ret =3D 0; + return -1; + } =20 - cleanup: - VIR_FREE(tmp); - return ret; + return 0; } =20 =20 @@ -18320,67 +17872,62 @@ static int virDomainIOThreadPinDefParseXML(xmlNodePtr node, virDomainDefPtr def) { - int ret =3D -1; virDomainIOThreadIDDefPtr iothrid; unsigned int iothreadid; - char *tmp =3D NULL; + VIR_AUTOFREE(char *) tmp =3D NULL; VIR_AUTOPTR(virBitmap) cpumask =3D NULL; =20 if (!(tmp =3D virXMLPropString(node, "iothread"))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing iothread id in iothreadpin")); - goto cleanup; + return -1; } =20 if (virStrToLong_uip(tmp, NULL, 10, &iothreadid) < 0) { virReportError(VIR_ERR_XML_ERROR, _("invalid setting for iothread '%s'"), tmp); - goto cleanup; + return -1; } VIR_FREE(tmp); =20 if (iothreadid =3D=3D 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("zero is an invalid iothread id value")); - goto cleanup; + return -1; } =20 if (!(iothrid =3D virDomainIOThreadIDFind(def, iothreadid))) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Cannot find 'iothread' : %u"), iothreadid); - goto cleanup; + return -1; } =20 if (!(tmp =3D virXMLPropString(node, "cpuset"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing cpuset for iothreadpin")); - goto cleanup; + return -1; } =20 if (virBitmapParse(tmp, &cpumask, VIR_DOMAIN_CPUMASK_LEN) < 0) - goto cleanup; + return -1; =20 if (virBitmapIsAllClear(cpumask)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Invalid value of 'cpuset': %s"), tmp); - goto cleanup; + return -1; } =20 if (iothrid->cpumask) { virReportError(VIR_ERR_INTERNAL_ERROR, _("duplicate iothreadpin for same iothread '%u'"), iothreadid); - goto cleanup; + return -1; } =20 VIR_STEAL_PTR(iothrid->cpumask, cpumask); - ret =3D 0; - - cleanup: - VIR_FREE(tmp); - return ret; + return 0; } =20 =20 @@ -18392,7 +17939,7 @@ static virBitmapPtr virDomainEmulatorPinDefParseXML(xmlNodePtr node) { virBitmapPtr ret =3D NULL; - char *tmp =3D NULL; + VIR_AUTOFREE(char *) tmp =3D NULL; VIR_AUTOPTR(virBitmap) def =3D NULL; =20 if (!(tmp =3D virXMLPropString(node, "cpuset"))) { @@ -18402,18 +17949,15 @@ virDomainEmulatorPinDefParseXML(xmlNodePtr node) } =20 if (virBitmapParse(tmp, &def, VIR_DOMAIN_CPUMASK_LEN) < 0) - goto cleanup; + return NULL; =20 if (virBitmapIsAllClear(def)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Invalid value of 'cpuset': %s"), tmp); - goto cleanup; + return NULL; } =20 VIR_STEAL_PTR(ret, def); - - cleanup: - VIR_FREE(tmp); return ret; } =20 @@ -18549,7 +18093,8 @@ virDomainHugepagesParseXML(xmlNodePtr node, { int ret =3D -1; xmlNodePtr oldnode =3D ctxt->node; - char *unit =3D NULL, *nodeset =3D NULL; + VIR_AUTOFREE(char *) unit =3D NULL; + VIR_AUTOFREE(char *) nodeset =3D NULL; =20 ctxt->node =3D node; =20 @@ -18577,8 +18122,6 @@ virDomainHugepagesParseXML(xmlNodePtr node, =20 ret =3D 0; cleanup: - VIR_FREE(unit); - VIR_FREE(nodeset); ctxt->node =3D oldnode; return ret; } @@ -18654,10 +18197,9 @@ static int virDomainLoaderDefParseXML(xmlNodePtr node, virDomainLoaderDefPtr loader) { - int ret =3D -1; - char *readonly_str =3D NULL; - char *secure_str =3D NULL; - char *type_str =3D NULL; + VIR_AUTOFREE(char *) readonly_str =3D NULL; + VIR_AUTOFREE(char *) secure_str =3D NULL; + VIR_AUTOFREE(char *) type_str =3D NULL; =20 readonly_str =3D virXMLPropString(node, "readonly"); secure_str =3D virXMLPropString(node, "secure"); @@ -18668,14 +18210,14 @@ virDomainLoaderDefParseXML(xmlNodePtr node, (loader->readonly =3D virTristateBoolTypeFromString(readonly_str))= <=3D 0) { virReportError(VIR_ERR_XML_DETAIL, _("unknown readonly value: %s"), readonly_str); - goto cleanup; + return -1; } =20 if (secure_str && (loader->secure =3D virTristateBoolTypeFromString(secure_str)) <= =3D 0) { virReportError(VIR_ERR_XML_DETAIL, _("unknown secure value: %s"), secure_str); - goto cleanup; + return -1; } =20 if (type_str) { @@ -18683,17 +18225,12 @@ virDomainLoaderDefParseXML(xmlNodePtr node, if ((type =3D virDomainLoaderTypeFromString(type_str)) < 0) { virReportError(VIR_ERR_XML_DETAIL, _("unknown type value: %s"), type_str); - goto cleanup; + return -1; } loader->type =3D type; } =20 - ret =3D 0; - cleanup: - VIR_FREE(readonly_str); - VIR_FREE(secure_str); - VIR_FREE(type_str); - return ret; + return 0; } =20 =20 @@ -18704,8 +18241,8 @@ virDomainSchedulerParse(xmlNodePtr node, int *priority) { virBitmapPtr ret =3D NULL; - char *tmp =3D NULL; int pol =3D 0; + VIR_AUTOFREE(char *) tmp =3D NULL; =20 if (!(tmp =3D virXMLPropString(node, name))) { virReportError(VIR_ERR_XML_ERROR, @@ -18754,13 +18291,11 @@ virDomainSchedulerParse(xmlNodePtr node, _("Invalid value for element priority")); goto error; } - VIR_FREE(tmp); } =20 return ret; =20 error: - VIR_FREE(tmp); virBitmapFree(ret); return NULL; } @@ -18843,13 +18378,12 @@ virDomainVcpuParse(virDomainDefPtr def, virDomainXMLOptionPtr xmlopt) { int n; - xmlNodePtr *nodes =3D NULL; xmlNodePtr vcpuNode; size_t i; - char *tmp =3D NULL; unsigned int maxvcpus; unsigned int vcpus; - int ret =3D -1; + VIR_AUTOFREE(char *) tmp =3D NULL; + VIR_AUTOFREE(xmlNodePtr *) nodes =3D NULL; =20 vcpus =3D maxvcpus =3D 1; =20 @@ -18858,7 +18392,7 @@ virDomainVcpuParse(virDomainDefPtr def, if (virStrToLong_ui(tmp, NULL, 10, &maxvcpus) < 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("maximum vcpus count must be an integer")= ); - goto cleanup; + return -1; } VIR_FREE(tmp); } @@ -18867,7 +18401,7 @@ virDomainVcpuParse(virDomainDefPtr def, if (virStrToLong_ui(tmp, NULL, 10, &vcpus) < 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("current vcpus count must be an integer")= ); - goto cleanup; + return -1; } VIR_FREE(tmp); } else { @@ -18881,7 +18415,7 @@ virDomainVcpuParse(virDomainDefPtr def, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported CPU placement mode '%s'"), tmp); - goto cleanup; + return -1; } VIR_FREE(tmp); } else { @@ -18892,12 +18426,12 @@ virDomainVcpuParse(virDomainDefPtr def, tmp =3D virXMLPropString(vcpuNode, "cpuset"); if (tmp) { if (virBitmapParse(tmp, &def->cpumask, VIR_DOMAIN_CPUMASK_= LEN) < 0) - goto cleanup; + return -1; =20 if (virBitmapIsAllClear(def->cpumask)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Invalid value of 'cpuset': %s"), tmp= ); - goto cleanup; + return -1; } =20 VIR_FREE(tmp); @@ -18906,10 +18440,10 @@ virDomainVcpuParse(virDomainDefPtr def, } =20 if (virDomainDefSetVcpusMax(def, maxvcpus, xmlopt) < 0) - goto cleanup; + return -1; =20 if ((n =3D virXPathNodeSet("./vcpus/vcpu", ctxt, &nodes)) < 0) - goto cleanup; + return -1; =20 if (n) { /* if individual vcpu states are provided take them as master */ @@ -18925,7 +18459,7 @@ virDomainVcpuParse(virDomainDefPtr def, virStrToLong_uip(tmp, NULL, 10, &id) < 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing or invalid vcpu id")); - goto cleanup; + return -1; } =20 VIR_FREE(tmp); @@ -18934,7 +18468,7 @@ virDomainVcpuParse(virDomainDefPtr def, virReportError(VIR_ERR_XML_ERROR, _("vcpu id '%u' is out of range of maximum " "vcpu count"), id); - goto cleanup; + return -1; } =20 vcpu =3D virDomainDefGetVcpu(def, id); @@ -18942,13 +18476,13 @@ virDomainVcpuParse(virDomainDefPtr def, if (!(tmp =3D virXMLPropString(nodes[i], "enabled"))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing vcpu enabled state")); - goto cleanup; + return -1; } =20 if ((state =3D virTristateBoolTypeFromString(tmp)) < 0) { virReportError(VIR_ERR_XML_ERROR, _("invalid vcpu 'enabled' value '%s'"), tmp= ); - goto cleanup; + return -1; } VIR_FREE(tmp); =20 @@ -18959,7 +18493,7 @@ virDomainVcpuParse(virDomainDefPtr def, if ((hotpluggable =3D virTristateBoolTypeFromString(tmp)) = < 0) { virReportError(VIR_ERR_XML_ERROR, _("invalid vcpu 'hotpluggable' value '%= s'"), tmp); - goto cleanup; + return -1; } vcpu->hotpluggable =3D hotpluggable; VIR_FREE(tmp); @@ -18969,7 +18503,7 @@ virDomainVcpuParse(virDomainDefPtr def, if (virStrToLong_uip(tmp, NULL, 10, &order) < 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("invalid vcpu order")); - goto cleanup; + return -1; } vcpu->order =3D order; VIR_FREE(tmp); @@ -18977,16 +18511,10 @@ virDomainVcpuParse(virDomainDefPtr def, } } else { if (virDomainDefSetVcpus(def, vcpus) < 0) - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(nodes); - VIR_FREE(tmp); - - return ret; + return 0; } =20 =20 @@ -18994,12 +18522,11 @@ static int virDomainDefParseBootOptions(virDomainDefPtr def, xmlXPathContextPtr ctxt) { - xmlNodePtr *nodes =3D NULL; - char *tmp =3D NULL; char *name =3D NULL; - int ret =3D -1; size_t i; int n; + VIR_AUTOFREE(xmlNodePtr *) nodes =3D NULL; + VIR_AUTOFREE(char *) tmp =3D NULL; =20 /* * Booting options for different OS types.... @@ -19018,34 +18545,34 @@ virDomainDefParseBootOptions(virDomainDefPtr def, def->os.initgroup =3D virXPathString("string(./os/initgroup[1])", = ctxt); =20 if ((n =3D virXPathNodeSet("./os/initarg", ctxt, &nodes)) < 0) - goto error; + return -1; =20 if (VIR_ALLOC_N(def->os.initargv, n+1) < 0) - goto error; + return -1; for (i =3D 0; i < n; i++) { if (!nodes[i]->children || !nodes[i]->children->content) { virReportError(VIR_ERR_XML_ERROR, "%s", _("No data supplied for element")= ); - goto error; + return -1; } if (VIR_STRDUP(def->os.initargv[i], (const char*) nodes[i]->children->content) < 0) - goto error; + return -1; } def->os.initargv[n] =3D NULL; VIR_FREE(nodes); =20 if ((n =3D virXPathNodeSet("./os/initenv", ctxt, &nodes)) < 0) - goto error; + return -1; =20 if (VIR_ALLOC_N(def->os.initenv, n+1) < 0) - goto error; + return -1; for (i =3D 0; i < n; i++) { if (!(name =3D virXMLPropString(nodes[i], "name"))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("No name supplied for element"= )); - goto error; + return -1; } =20 if (!nodes[i]->children || @@ -19053,16 +18580,16 @@ virDomainDefParseBootOptions(virDomainDefPtr def, virReportError(VIR_ERR_XML_ERROR, _("No value supplied for element"), name); - goto error; + return -1; } =20 if (VIR_ALLOC(def->os.initenv[i]) < 0) - goto error; + return -1; =20 def->os.initenv[i]->name =3D name; if (VIR_STRDUP(def->os.initenv[i]->value, (const char*) nodes[i]->children->content) < 0) - goto error; + return -1; } def->os.initenv[n] =3D NULL; VIR_FREE(nodes); @@ -19081,10 +18608,10 @@ virDomainDefParseBootOptions(virDomainDefPtr def, def->os.root =3D virXPathString("string(./os/root[1])", ctxt); if ((loader_node =3D virXPathNode("./os/loader[1]", ctxt))) { if (VIR_ALLOC(def->os.loader) < 0) - goto error; + return -1; =20 if (virDomainLoaderDefParseXML(loader_node, def->os.loader) < = 0) - goto error; + return -1; =20 def->os.loader->nvram =3D virXPathString("string(./os/nvram[1]= )", ctxt); def->os.loader->templt =3D virXPathString("string(./os/nvram[1= ]/@template)", ctxt); @@ -19093,12 +18620,12 @@ virDomainDefParseBootOptions(virDomainDefPtr def, =20 if (def->os.type =3D=3D VIR_DOMAIN_OSTYPE_HVM) { if ((n =3D virXPathNodeSet("./os/acpi/table", ctxt, &nodes)) < 0) - goto error; + return -1; =20 if (n > 1) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Only one acpi table is supported")); - goto error; + return -1; } =20 if (n =3D=3D 1) { @@ -19107,32 +18634,26 @@ virDomainDefParseBootOptions(virDomainDefPtr def, if (!tmp) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing acpi table type")); - goto error; + return -1; } =20 if (STREQ_NULLABLE(tmp, "slic")) { VIR_FREE(tmp); tmp =3D virXMLNodeContentString(nodes[0]); def->os.slic_table =3D virFileSanitizePath(tmp); - VIR_FREE(tmp); } else { virReportError(VIR_ERR_XML_ERROR, _("Unknown acpi table type: %s"), tmp); - goto error; + return -1; } } =20 if (virDomainDefParseBootXML(ctxt, def) < 0) - goto error; + return -1; } =20 - ret =3D 0; - - error: - VIR_FREE(nodes); - VIR_FREE(tmp); - return ret; + return 0; } =20 =20 @@ -19141,30 +18662,26 @@ virDomainResctrlParseVcpus(virDomainDefPtr def, xmlNodePtr node, virBitmapPtr *vcpus) { - char *vcpus_str =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) vcpus_str =3D NULL; =20 vcpus_str =3D virXMLPropString(node, "vcpus"); if (!vcpus_str) { virReportError(VIR_ERR_XML_ERROR, _("Missing %s attribute 'vcpus'"= ), node->name); - goto cleanup; + return -1; } if (virBitmapParse(vcpus_str, vcpus, VIR_DOMAIN_CPUMASK_LEN) < 0) { virReportError(VIR_ERR_XML_ERROR, _("Invalid %s attribute 'vcpus' value '%s'"), node->name, vcpus_str); - goto cleanup; + return -1; } =20 /* We need to limit the bitmap to number of vCPUs. If there's nothing= left, * then we can just clean up and return 0 immediately */ virBitmapShrink(*vcpus, def->maxvcpus); =20 - ret =3D 0; - cleanup: - VIR_FREE(vcpus_str); - return ret; + return 0; } =20 =20 @@ -19203,8 +18720,8 @@ virDomainCachetuneDefParseCache(xmlXPathContextPtr = ctxt, unsigned int cache; int type; unsigned long long size; - char *tmp =3D NULL; int ret =3D -1; + VIR_AUTOFREE(char *) tmp =3D NULL; =20 ctxt->node =3D node; =20 @@ -19249,7 +18766,6 @@ virDomainCachetuneDefParseCache(xmlXPathContextPtr = ctxt, tmp); goto cleanup; } - VIR_FREE(tmp); =20 if (virDomainParseScaledValue("./@size", "./@unit", ctxt, &size, 1024, @@ -19262,7 +18778,6 @@ virDomainCachetuneDefParseCache(xmlXPathContextPtr = ctxt, ret =3D 0; cleanup: ctxt->node =3D oldnode; - VIR_FREE(tmp); return ret; } =20 @@ -19335,14 +18850,14 @@ virDomainResctrlMonDefParse(virDomainDefPtr def, { virDomainResctrlMonDefPtr domresmon =3D NULL; xmlNodePtr oldnode =3D ctxt->node; - xmlNodePtr *nodes =3D NULL; unsigned int level =3D 0; - char *tmp =3D NULL; - char *id =3D NULL; size_t i =3D 0; int n =3D 0; int rv =3D -1; int ret =3D -1; + VIR_AUTOFREE(xmlNodePtr *) nodes =3D NULL; + VIR_AUTOFREE(char *) tmp =3D NULL; + VIR_AUTOFREE(char *) id =3D NULL; =20 ctxt->node =3D node; =20 @@ -19430,9 +18945,6 @@ virDomainResctrlMonDefParse(virDomainDefPtr def, ret =3D 0; cleanup: ctxt->node =3D oldnode; - VIR_FREE(id); - VIR_FREE(tmp); - VIR_FREE(nodes); virDomainResctrlMonDefFree(domresmon); return ret; } @@ -19444,10 +18956,10 @@ virDomainResctrlNew(xmlNodePtr node, virBitmapPtr vcpus, unsigned int flags) { - char *vcpus_str =3D NULL; - char *alloc_id =3D NULL; virDomainResctrlDefPtr resctrl =3D NULL; virDomainResctrlDefPtr ret =3D NULL; + VIR_AUTOFREE(char *) vcpus_str =3D NULL; + VIR_AUTOFREE(char *) alloc_id =3D NULL; =20 /* We need to format it back because we need to be consistent in the n= aming * even when users specify some "sub-optimal" string there. */ @@ -19485,8 +18997,6 @@ virDomainResctrlNew(xmlNodePtr node, VIR_STEAL_PTR(ret, resctrl); cleanup: virDomainResctrlDefFree(resctrl); - VIR_FREE(alloc_id); - VIR_FREE(vcpus_str); return ret; } =20 @@ -19498,13 +19008,13 @@ virDomainCachetuneDefParse(virDomainDefPtr def, unsigned int flags) { xmlNodePtr oldnode =3D ctxt->node; - xmlNodePtr *nodes =3D NULL; virResctrlAllocPtr alloc =3D NULL; virDomainResctrlDefPtr resctrl =3D NULL; ssize_t i =3D 0; int n; int ret =3D -1; VIR_AUTOPTR(virBitmap) vcpus =3D NULL; + VIR_AUTOFREE(xmlNodePtr *) nodes =3D NULL; =20 ctxt->node =3D node; =20 @@ -19564,7 +19074,6 @@ virDomainCachetuneDefParse(virDomainDefPtr def, ctxt->node =3D oldnode; virDomainResctrlDefFree(resctrl); virObjectUnref(alloc); - VIR_FREE(nodes); return ret; } =20 @@ -19575,11 +19084,10 @@ virDomainDefParseCaps(virDomainDefPtr def, virCapsPtr caps, unsigned int flags) { - int ret =3D -1; - char *virttype =3D NULL; - char *arch =3D NULL; - char *ostype =3D NULL; - virCapsDomainDataPtr capsdata =3D NULL; + VIR_AUTOFREE(char *) virttype =3D NULL; + VIR_AUTOFREE(char *) arch =3D NULL; + VIR_AUTOFREE(char *) ostype =3D NULL; + VIR_AUTOFREE(virCapsDomainDataPtr) capsdata =3D NULL; =20 virttype =3D virXPathString("string(./@type)", ctxt); ostype =3D virXPathString("string(./os/type[1])", ctxt); @@ -19593,12 +19101,12 @@ virDomainDefParseCaps(virDomainDefPtr def, if (!virttype) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing domain type attribute")); - goto cleanup; + return -1; } if ((def->virtType =3D virDomainVirtTypeFromString(virttype)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("invalid domain type %s"), virttype); - goto cleanup; + return -1; } =20 if (!ostype) { @@ -19607,13 +19115,13 @@ virDomainDefParseCaps(virDomainDefPtr def, } else { virReportError(VIR_ERR_XML_ERROR, "%s", _("an os must be specified")); - goto cleanup; + return -1; } } else { if ((def->os.type =3D virDomainOSTypeFromString(ostype)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown OS type '%s'"), ostype); - goto cleanup; + return -1; } } =20 @@ -19630,7 +19138,7 @@ virDomainDefParseCaps(virDomainDefPtr def, if (arch && !(def->os.arch =3D virArchFromString(arch))) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unknown architecture %s"), arch); - goto cleanup; + return -1; } =20 if (!(capsdata =3D virCapabilitiesDomainDataLookup(caps, def->os.type, @@ -19638,23 +19146,17 @@ virDomainDefParseCaps(virDomainDefPtr def, def->virtType, NULL, NULL))) { if (!(flags & VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE)) - goto cleanup; + return -1; virResetLastError(); } else { if (!def->os.arch) def->os.arch =3D capsdata->arch; if ((!def->os.machine && VIR_STRDUP(def->os.machine, capsdata->machinetype) < 0)) - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(virttype); - VIR_FREE(ostype); - VIR_FREE(arch); - VIR_FREE(capsdata); - return ret; + return 0; } =20 =20 @@ -19666,8 +19168,8 @@ virDomainMemorytuneDefParseMemory(xmlXPathContextPt= r ctxt, xmlNodePtr oldnode =3D ctxt->node; unsigned int id; unsigned int bandwidth; - char *tmp =3D NULL; int ret =3D -1; + VIR_AUTOFREE(char *) tmp =3D NULL; =20 ctxt->node =3D node; =20 @@ -19697,14 +19199,12 @@ virDomainMemorytuneDefParseMemory(xmlXPathContext= Ptr ctxt, tmp); goto cleanup; } - VIR_FREE(tmp); if (virResctrlAllocSetMemoryBandwidth(alloc, id, bandwidth) < 0) goto cleanup; =20 ret =3D 0; cleanup: ctxt->node =3D oldnode; - VIR_FREE(tmp); return ret; } =20 @@ -19716,10 +19216,10 @@ virDomainMemorytuneDefParse(virDomainDefPtr def, unsigned int flags) { xmlNodePtr oldnode =3D ctxt->node; - xmlNodePtr *nodes =3D NULL; virResctrlAllocPtr alloc =3D NULL; virDomainResctrlDefPtr resctrl =3D NULL; VIR_AUTOPTR(virBitmap) vcpus =3D NULL; + VIR_AUTOFREE(xmlNodePtr *) nodes =3D NULL; =20 ssize_t i =3D 0; int n; @@ -19778,7 +19278,6 @@ virDomainMemorytuneDefParse(virDomainDefPtr def, ctxt->node =3D oldnode; virDomainResctrlDefFree(resctrl); virObjectUnref(alloc); - VIR_FREE(nodes); return ret; } =20 @@ -19791,8 +19290,7 @@ virDomainDefParseXML(xmlDocPtr xml, virDomainXMLOptionPtr xmlopt, unsigned int flags) { - xmlNodePtr *nodes =3D NULL, node =3D NULL; - char *tmp =3D NULL; + xmlNodePtr node =3D NULL; size_t i, j; int n, gic_version; long id =3D -1; @@ -19802,18 +19300,19 @@ virDomainDefParseXML(xmlDocPtr xml, bool usb_other =3D false; bool usb_master =3D false; char *netprefix =3D NULL; + VIR_AUTOFREE(xmlNodePtr *) nodes =3D NULL; + VIR_AUTOFREE(char *) tmp =3D NULL; =20 if (flags & VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA) { - char *schema =3D virFileFindResource("domain.rng", - abs_topsrcdir "/docs/schemas", - PKGDATADIR "/schemas"); + VIR_AUTOFREE(char *) schema =3D NULL; + + schema =3D virFileFindResource("domain.rng", + abs_topsrcdir "/docs/schemas", + PKGDATADIR "/schemas"); if (!schema) return NULL; - if (virXMLValidateAgainstSchema(schema, xml) < 0) { - VIR_FREE(schema); + if (virXMLValidateAgainstSchema(schema, xml) < 0) return NULL; - } - VIR_FREE(schema); } =20 if (!(def =3D virDomainDefNew())) @@ -21439,7 +20938,6 @@ virDomainDefParseXML(xmlDocPtr xml, =20 def->idmap.ngidmap =3D n; } - VIR_FREE(nodes); =20 if ((def->idmap.uidmap && !def->idmap.gidmap) || (!def->idmap.uidmap && def->idmap.gidmap)) { @@ -21468,7 +20966,6 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } def->os.smbios_mode =3D mode; - VIR_FREE(tmp); } =20 if (virDomainKeyWrapDefParseXML(def, ctxt) < 0) @@ -21490,8 +20987,6 @@ virDomainDefParseXML(xmlDocPtr xml, return def; =20 error: - VIR_FREE(tmp); - VIR_FREE(nodes); virDomainDefFree(def); return NULL; } @@ -21504,17 +20999,17 @@ virDomainObjParseXML(xmlDocPtr xml, virDomainXMLOptionPtr xmlopt, unsigned int flags) { - char *tmp =3D NULL; long val; xmlNodePtr config; xmlNodePtr oldnode; virDomainObjPtr obj; - xmlNodePtr *nodes =3D NULL; size_t i; int n; int state; int reason =3D 0; void *parseOpaque =3D NULL; + VIR_AUTOFREE(char *) tmp =3D NULL; + VIR_AUTOFREE(xmlNodePtr *) nodes =3D NULL; =20 if (!(obj =3D virDomainObjNew(xmlopt))) return NULL; @@ -21540,7 +21035,6 @@ virDomainObjParseXML(xmlDocPtr xml, if ((state =3D virDomainStateTypeFromString(tmp)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("invalid domain state '%s'"), tmp); - VIR_FREE(tmp); goto error; } VIR_FREE(tmp); @@ -21549,10 +21043,8 @@ virDomainObjParseXML(xmlDocPtr xml, if ((reason =3D virDomainStateReasonFromString(state, tmp)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("invalid domain state reason '%s'"), tmp); - VIR_FREE(tmp); goto error; } - VIR_FREE(tmp); } =20 virDomainObjSetState(obj, state, reason); @@ -21580,7 +21072,6 @@ virDomainObjParseXML(xmlDocPtr xml, virDomainObjTaint(obj, flag); } } - VIR_FREE(nodes); =20 if (xmlopt->privateData.parse && xmlopt->privateData.parse(ctxt, obj, &xmlopt->config) < 0) @@ -21601,7 +21092,6 @@ virDomainObjParseXML(xmlDocPtr xml, =20 error: virObjectUnref(obj); - VIR_FREE(nodes); return NULL; } =20 @@ -23135,8 +22625,8 @@ virDomainDefCheckABIStabilityFlags(virDomainDefPtr = src, { size_t i; virErrorPtr err; - char *strSrc; - char *strDst; + VIR_AUTOFREE(char *) strSrc =3D NULL; + VIR_AUTOFREE(char *) strDst =3D NULL; =20 if (src->virtType !=3D dst->virtType) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -23605,8 +23095,6 @@ virDomainDefCheckABIStabilityFlags(virDomainDefPtr = src, strDst =3D virDomainDefFormat(dst, NULL, 0); VIR_DEBUG("XMLs that failed stability check were: src=3D\"%s\", dst=3D= \"%s\"", NULLSTR(strSrc), NULLSTR(strDst)); - VIR_FREE(strSrc); - VIR_FREE(strDst); =20 if (err) { virSetError(err); @@ -24066,7 +23554,7 @@ virDomainDiskSourceFormatNetwork(virBufferPtr attrB= uf, unsigned int flags) { size_t n; - char *path =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; =20 virBufferAsprintf(attrBuf, " protocol=3D'%s'", virStorageNetProtocolTypeToString(src->protocol)); @@ -24078,8 +23566,6 @@ virDomainDiskSourceFormatNetwork(virBufferPtr attrB= uf, =20 virBufferEscapeString(attrBuf, " name=3D'%s'", path ? path : src->path= ); =20 - VIR_FREE(path); - if (src->haveTLS !=3D VIR_TRISTATE_BOOL_ABSENT && !(flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE && src->tlsFromConfig)) @@ -26514,8 +26000,7 @@ static int virDomainMemorySourceDefFormat(virBufferPtr buf, virDomainMemoryDefPtr def) { - char *bitmap =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) bitmap =3D NULL; =20 if (!def->pagesize && !def->sourceNodes && !def->nvdimmPath) return 0; @@ -26527,7 +26012,7 @@ virDomainMemorySourceDefFormat(virBufferPtr buf, case VIR_DOMAIN_MEMORY_MODEL_DIMM: if (def->sourceNodes) { if (!(bitmap =3D virBitmapFormat(def->sourceNodes))) - goto cleanup; + return -1; =20 virBufferAsprintf(buf, "%s\n", bitmap); } @@ -26556,11 +26041,7 @@ virDomainMemorySourceDefFormat(virBufferPtr buf, virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "\n"); =20 - ret =3D 0; - - cleanup: - VIR_FREE(bitmap); - return ret; + return 0; } =20 =20 @@ -27710,7 +27191,7 @@ virDomainResctrlMonDefFormatHelper(virDomainResctrl= MonDefPtr domresmon, virResctrlMonitorType tag, virBufferPtr buf) { - char *vcpus =3D NULL; + VIR_AUTOFREE(char *) vcpus =3D NULL; =20 if (domresmon->tag !=3D tag) return 0; @@ -27728,7 +27209,6 @@ virDomainResctrlMonDefFormatHelper(virDomainResctrl= MonDefPtr domresmon, =20 virBufferAsprintf(buf, "vcpus=3D'%s'/>\n", vcpus); =20 - VIR_FREE(vcpus); return 0; } =20 @@ -27739,9 +27219,9 @@ virDomainCachetuneDefFormat(virBufferPtr buf, unsigned int flags) { virBuffer childrenBuf =3D VIR_BUFFER_INITIALIZER; - char *vcpus =3D NULL; size_t i =3D 0; int ret =3D -1; + VIR_AUTOFREE(char *) vcpus =3D NULL; =20 virBufferSetChildIndent(&childrenBuf, buf); if (virResctrlAllocForeachCache(resctrl->alloc, @@ -27785,7 +27265,6 @@ virDomainCachetuneDefFormat(virBufferPtr buf, ret =3D 0; cleanup: virBufferFreeAndReset(&childrenBuf); - VIR_FREE(vcpus); return ret; } =20 @@ -27810,8 +27289,8 @@ virDomainMemorytuneDefFormat(virBufferPtr buf, unsigned int flags) { virBuffer childrenBuf =3D VIR_BUFFER_INITIALIZER; - char *vcpus =3D NULL; int ret =3D -1; + VIR_AUTOFREE(char *) vcpus =3D NULL; =20 virBufferSetChildIndent(&childrenBuf, buf); if (virResctrlAllocForeachMemory(resctrl->alloc, @@ -27848,7 +27327,6 @@ virDomainMemorytuneDefFormat(virBufferPtr buf, ret =3D 0; cleanup: virBufferFreeAndReset(&childrenBuf); - VIR_FREE(vcpus); return ret; } =20 @@ -27983,8 +27461,7 @@ virDomainCpuDefFormat(virBufferPtr buf, { virDomainVcpuDefPtr vcpu; size_t i; - char *cpumask =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) cpumask =3D NULL; =20 virBufferAddLit(buf, "cpumask && !virBitmapIsAllSet(def->cpumask)) { if ((cpumask =3D virBitmapFormat(def->cpumask)) =3D=3D NULL) - goto cleanup; + return -1; virBufferAsprintf(buf, " cpuset=3D'%s'", cpumask); } if (virDomainDefHasVcpusOffline(def)) @@ -28020,12 +27497,7 @@ virDomainCpuDefFormat(virBufferPtr buf, virBufferAddLit(buf, "\n"); } =20 - ret =3D 0; - - cleanup: - VIR_FREE(cpumask); - - return ret; + return 0; } =20 =20 @@ -29221,30 +28693,25 @@ virDomainSaveXML(const char *configDir, const char *xml) { char uuidstr[VIR_UUID_STRING_BUFLEN]; - char *configFile =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) configFile =3D NULL; =20 if (!configDir) return 0; =20 if ((configFile =3D virDomainConfigFile(configDir, def->name)) =3D=3D = NULL) - goto cleanup; + return -1; =20 if (virFileMakePath(configDir) < 0) { virReportSystemError(errno, _("cannot create config directory '%s'"), configDir); - goto cleanup; + return -1; } =20 virUUIDFormat(def->uuid, uuidstr); - ret =3D virXMLSaveFile(configFile, - virXMLPickShellSafeComment(def->name, uuidstr), "= edit", - xml); - - cleanup: - VIR_FREE(configFile); - return ret; + return virXMLSaveFile(configFile, + virXMLPickShellSafeComment(def->name, uuidstr),= "edit", + xml); } =20 int @@ -29252,19 +28719,12 @@ virDomainSaveConfig(const char *configDir, virCapsPtr caps, virDomainDefPtr def) { - int ret =3D -1; - char *xml; + VIR_AUTOFREE(char *) xml =3D NULL; =20 if (!(xml =3D virDomainDefFormat(def, caps, VIR_DOMAIN_DEF_FORMAT_SECU= RE))) - goto cleanup; - - if (virDomainSaveXML(configDir, def, xml)) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - VIR_FREE(xml); - return ret; + return virDomainSaveXML(configDir, def, xml); } =20 int @@ -29279,19 +28739,12 @@ virDomainSaveStatus(virDomainXMLOptionPtr xmlopt, VIR_DOMAIN_DEF_FORMAT_PCI_ORIG_STATES | VIR_DOMAIN_DEF_FORMAT_CLOCK_ADJUST); =20 - int ret =3D -1; - char *xml; + VIR_AUTOFREE(char *) xml =3D NULL; =20 if (!(xml =3D virDomainObjFormat(xmlopt, obj, caps, flags))) - goto cleanup; - - if (virDomainSaveXML(statusDir, obj->def, xml)) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - VIR_FREE(xml); - return ret; + return virDomainSaveXML(statusDir, obj->def, xml); } =20 =20 @@ -29300,14 +28753,14 @@ virDomainDeleteConfig(const char *configDir, const char *autostartDir, virDomainObjPtr dom) { - char *configFile =3D NULL, *autostartLink =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) configFile =3D NULL; + VIR_AUTOFREE(char *) autostartLink =3D NULL; =20 if ((configFile =3D virDomainConfigFile(configDir, dom->def->name)) = =3D=3D NULL) - goto cleanup; + return -1; if ((autostartLink =3D virDomainConfigFile(autostartDir, dom->def->name)) =3D=3D NULL) - goto cleanup; + return -1; =20 /* Not fatal if this doesn't work */ unlink(autostartLink); @@ -29318,15 +28771,10 @@ virDomainDeleteConfig(const char *configDir, virReportSystemError(errno, _("cannot remove config %s"), configFile); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(configFile); - VIR_FREE(autostartLink); - return ret; + return 0; } =20 char @@ -29588,20 +29036,19 @@ virDomainDiskDefForeachPath(virDomainDiskDefPtr d= isk, virDomainDiskDefPathIterator iter, void *opaque) { - int ret =3D -1; size_t depth =3D 0; virStorageSourcePtr tmp; - char *brokenRaw =3D NULL; + VIR_AUTOFREE(char *) brokenRaw =3D NULL; =20 if (!ignoreOpenFailure) { if (virStorageFileChainGetBroken(disk->src, &brokenRaw) < 0) - goto cleanup; + return -1; =20 if (brokenRaw) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unable to visit backing chain file %s"), brokenRaw); - goto cleanup; + return -1; } } =20 @@ -29610,17 +29057,13 @@ virDomainDiskDefForeachPath(virDomainDiskDefPtr d= isk, if (virStorageSourceIsLocalStorage(tmp) && tmp->path) { if (iter(disk, tmp->path, depth, opaque) < 0) - goto cleanup; + return -1; } =20 depth++; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(brokenRaw); - return ret; + return 0; } =20 =20 @@ -29635,11 +29078,10 @@ virDomainDefCopy(virDomainDefPtr src, void *parseOpaque, bool migratable) { - char *xml; - virDomainDefPtr ret; unsigned int format_flags =3D VIR_DOMAIN_DEF_FORMAT_SECURE; unsigned int parse_flags =3D VIR_DOMAIN_DEF_PARSE_INACTIVE | VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE; + VIR_AUTOFREE(char *) xml =3D NULL; =20 if (migratable) format_flags |=3D VIR_DOMAIN_DEF_FORMAT_INACTIVE | VIR_DOMAIN_DEF_= FORMAT_MIGRATABLE; @@ -29648,10 +29090,7 @@ virDomainDefCopy(virDomainDefPtr src, if (!(xml =3D virDomainDefFormat(src, caps, format_flags))) return NULL; =20 - ret =3D virDomainDefParseString(xml, caps, xmlopt, parseOpaque, parse_= flags); - - VIR_FREE(xml); - return ret; + return virDomainDefParseString(xml, caps, xmlopt, parseOpaque, parse_f= lags); } =20 virDomainDefPtr @@ -30075,12 +29514,11 @@ virDomainDeviceDefCopy(virDomainDeviceDefPtr src, virCapsPtr caps, virDomainXMLOptionPtr xmlopt) { - virDomainDeviceDefPtr ret =3D NULL; virBuffer buf =3D VIR_BUFFER_INITIALIZER; int flags =3D VIR_DOMAIN_DEF_FORMAT_INACTIVE | VIR_DOMAIN_DEF_FORMAT_S= ECURE; - char *xmlStr =3D NULL; int rc =3D -1; char *netprefix; + VIR_AUTOFREE(char *) xmlStr =3D NULL; =20 switch ((virDomainDeviceType) src->type) { case VIR_DOMAIN_DEVICE_DISK: @@ -30155,20 +29593,16 @@ virDomainDeviceDefCopy(virDomainDeviceDefPtr src, _("Copying definition of '%d' type " "is not implemented yet."), src->type); - goto cleanup; + return NULL; } =20 if (rc < 0) - goto cleanup; + return NULL; =20 xmlStr =3D virBufferContentAndReset(&buf); - ret =3D virDomainDeviceDefParse(xmlStr, def, caps, xmlopt, - VIR_DOMAIN_DEF_PARSE_INACTIVE | - VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE); - - cleanup: - VIR_FREE(xmlStr); - return ret; + return virDomainDeviceDefParse(xmlStr, def, caps, xmlopt, + VIR_DOMAIN_DEF_PARSE_INACTIVE | + VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE); } =20 =20 @@ -30498,8 +29932,8 @@ virDomainDefGetShortName(const virDomainDef *def) { wchar_t wshortname[VIR_DOMAIN_SHORT_NAME_MAX + 1] =3D {0}; size_t len =3D 0; - char *shortname =3D NULL; char *ret =3D NULL; + VIR_AUTOFREE(char *) shortname =3D NULL; =20 /* No need to do the whole conversion thing when there are no multibyte * characters. The same applies for illegal sequences as they can occ= ur @@ -30541,12 +29975,10 @@ virDomainDefGetShortName(const virDomainDef *def) virReportSystemError(errno, "%s", _("Cannot convert wide character string " "back to multi-byte domain name")); - goto cleanup; + return NULL; } =20 ignore_value(virAsprintf(&ret, "%d-%s", def->id, shortname)); - cleanup: - VIR_FREE(shortname); return ret; } =20 @@ -30825,9 +30257,9 @@ virDomainNetResolveActualType(virDomainNetDefPtr if= ace) { virConnectPtr conn =3D NULL; virNetworkPtr net =3D NULL; - char *xml =3D NULL; virNetworkDefPtr def =3D NULL; int ret =3D -1; + VIR_AUTOFREE(char *) xml =3D NULL; =20 if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) return iface->type; @@ -30894,7 +30326,6 @@ virDomainNetResolveActualType(virDomainNetDefPtr if= ace) =20 cleanup: virNetworkDefFree(def); - VIR_FREE(xml); virObjectUnref(conn); virObjectUnref(net); return ret; @@ -31023,10 +30454,10 @@ virDomainDiskTranslateSourcePool(virDomainDiskDef= Ptr def) virConnectPtr conn =3D NULL; virStoragePoolPtr pool =3D NULL; virStorageVolPtr vol =3D NULL; - char *poolxml =3D NULL; virStorageVolInfo info; int ret =3D -1; VIR_AUTOPTR(virStoragePoolDef) pooldef =3D NULL; + VIR_AUTOFREE(char *) poolxml =3D NULL; =20 if (def->src->type !=3D VIR_STORAGE_TYPE_VOLUME) return 0; @@ -31184,7 +30615,6 @@ virDomainDiskTranslateSourcePool(virDomainDiskDefPt= r def) virObjectUnref(conn); virObjectUnref(pool); virObjectUnref(vol); - VIR_FREE(poolxml); return ret; } =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list