From nobody Sun Feb 8 15:46:02 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1628757606; cv=none; d=zohomail.com; s=zohoarc; b=Q0tc77WnnsLgEbvyV4Yh/Mvur064iCdzZfpPZFmGH/b9x4w0eWpPjI3qXlGSTx7QPjm1XbzhdZ8YDhSvFLu5NIWZxnaS1CpK29dlJ+cxDnfnbyOnD2HLSI6a8yyEn3LxI2q7AD10vDvoT1N6nNW8MRkLRahT5s43issPCQp8LqQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1628757606; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EEmhm6Ymt+Maqj/q7tIcTisjuCWVzGVsANO8YvW9mIs=; b=mvqnsIMyCKQs9hcUQG+Fisy8UIoaVrAVnb0gypSm9O4jD13BaTktot/X0TQy2+PQsRpVYH9QW1aAV5hCHFNsNMukzV4VF8K48nAwCCg0mCEVpmtuAFR1/Bn28kLMyd9e8Bi7imn816+geiTt0RpDKqjig9T6B3zefIOf5jwRhmI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1628757606723626.8804717720236; Thu, 12 Aug 2021 01:40:06 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-228-H7sVJVRcN-mwHOdJ30pyUg-1; Thu, 12 Aug 2021 04:39:39 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 675BB760C5; Thu, 12 Aug 2021 08:39:34 +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 4CF8D69CBB; Thu, 12 Aug 2021 08:39:34 +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 1DF9F4A7CD; Thu, 12 Aug 2021 08:39:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17C8XAeG003671 for ; Thu, 12 Aug 2021 04:33:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 266B310372CC; Thu, 12 Aug 2021 08:33:10 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id A35E510013C1 for ; Thu, 12 Aug 2021 08:33:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1628757605; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=EEmhm6Ymt+Maqj/q7tIcTisjuCWVzGVsANO8YvW9mIs=; b=YDM6vucLP+oY91MblVyrSlgc109Xeep5DEysxdUFlmGS2mwjSMHUm0/JD9n/gOPnWZ/H/M qkD5fOSay6sW0fYMIeWS6VcZvRfUZhSALknka9yafjJEqtKRI9tHVfXDD+pXRiTnCG6mms wtcTtn8w8ch0nSjfoMV6VVYoa36l3ic= X-MC-Unique: H7sVJVRcN-mwHOdJ30pyUg-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 07/12] tools: virsh: use automatic cleanup for xmlDoc Date: Thu, 12 Aug 2021 10:32:45 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1628757607908100002 Signed-off-by: J=C3=A1n Tomko --- tools/virsh-completer-domain.c | 6 ++---- tools/virsh-domain-monitor.c | 12 ++++-------- tools/virsh-domain.c | 27 +++++++++------------------ tools/virsh-host.c | 15 +++++---------- tools/virsh-interface.c | 6 ++---- tools/virsh-volume.c | 3 +-- 6 files changed, 23 insertions(+), 46 deletions(-) diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c index 4cdc533a07..471f9974a1 100644 --- a/tools/virsh-completer-domain.c +++ b/tools/virsh-completer-domain.c @@ -478,7 +478,7 @@ virshDomainVcpuCompleter(vshControl *ctl, unsigned int flags) { g_autoptr(virshDomain) dom =3D NULL; - xmlDocPtr xml =3D NULL; + g_autoptr(xmlDoc) xml =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; int nvcpus =3D 0; unsigned int id; @@ -506,7 +506,6 @@ virshDomainVcpuCompleter(vshControl *ctl, ret =3D g_steal_pointer(&tmp); =20 cleanup: - xmlFreeDoc(xml); return ret; } =20 @@ -517,7 +516,7 @@ virshDomainVcpulistCompleter(vshControl *ctl, unsigned int flags) { g_autoptr(virshDomain) dom =3D NULL; - xmlDocPtr xml =3D NULL; + g_autoptr(xmlDoc) xml =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; int nvcpus =3D 0; unsigned int id; @@ -549,7 +548,6 @@ virshDomainVcpulistCompleter(vshControl *ctl, ret =3D virshCommaStringListComplete(vcpuid, (const char **)vcpulist); =20 cleanup: - xmlFreeDoc(xml); return ret; } =20 diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index cabf968393..fb52915cab 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -55,7 +55,7 @@ virshGetDomainDescription(vshControl *ctl, virDomainPtr d= om, bool title, unsigned int flags) { char *desc =3D NULL; - xmlDocPtr doc =3D NULL; + g_autoptr(xmlDoc) doc =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; int type; =20 @@ -92,7 +92,6 @@ virshGetDomainDescription(vshControl *ctl, virDomainPtr d= om, bool title, desc =3D g_strdup(""); =20 cleanup: - xmlFreeDoc(doc); =20 return desc; } @@ -593,7 +592,7 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) { bool ret =3D false; unsigned int flags =3D 0; - xmlDocPtr xmldoc =3D NULL; + g_autoptr(xmlDoc) xmldoc =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; int ndisks; xmlNodePtr *disks =3D NULL; @@ -693,7 +692,6 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) VIR_FREE(device); VIR_FREE(type); VIR_FREE(disks); - xmlFreeDoc(xmldoc); return ret; } =20 @@ -720,7 +718,7 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd) { bool ret =3D false; unsigned int flags =3D 0; - xmlDocPtr xmldoc =3D NULL; + g_autoptr(xmlDoc) xmldoc =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; int ninterfaces; xmlNodePtr *interfaces =3D NULL; @@ -779,7 +777,6 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd) cleanup: vshTableFree(table); VIR_FREE(interfaces); - xmlFreeDoc(xmldoc); return ret; } =20 @@ -820,7 +817,7 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd) char *xpath =3D NULL; virMacAddr macaddr; char macstr[VIR_MAC_STRING_BUFLEN] =3D ""; - xmlDocPtr xml =3D NULL; + g_autoptr(xmlDoc) xml =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; xmlNodePtr *interfaces =3D NULL; int ninterfaces; @@ -874,7 +871,6 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd) VIR_FREE(state); VIR_FREE(interfaces); VIR_FREE(xpath); - xmlFreeDoc(xml); =20 return ret; } diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 0c60a4de99..fe2bfdaed0 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -3064,7 +3064,7 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd) unsigned int flags =3D 0; unsigned int xmlflags =3D 0; size_t i; - xmlDocPtr xml =3D NULL; + g_autoptr(xmlDoc) xml =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; g_autoptr(xmlXPathObject) obj =3D NULL; xmlNodePtr cur =3D NULL; @@ -3178,7 +3178,6 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd) } =20 cleanup: - xmlFreeDoc(xml); VIR_FREE(xml_buf); =20 return ret; @@ -3636,7 +3635,7 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) int nvol_list =3D 0; virshUndefineVolume *vols =3D NULL; /* info about the volumes to delet= e */ size_t nvols =3D 0; - xmlDocPtr doc =3D NULL; + g_autoptr(xmlDoc) doc =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; xmlNodePtr *vol_nodes =3D NULL; /* XML nodes of volumes of the guest= */ int nvol_nodes; @@ -3953,7 +3952,6 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) VIR_FREE(vol_list); =20 VIR_FREE(vol_nodes); - xmlFreeDoc(doc); return ret; =20 error: @@ -6551,7 +6549,7 @@ virshCPUCountCollect(vshControl *ctl, int ret =3D -2; virDomainInfo info; int count; - xmlDocPtr xml =3D NULL; + g_autoptr(xmlDoc) xml =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; =20 if (checkState && @@ -6611,7 +6609,6 @@ virshCPUCountCollect(vshControl *ctl, =20 ret =3D count; cleanup: - xmlFreeDoc(xml); =20 return ret; } @@ -6754,7 +6751,7 @@ virshDomainGetVcpuBitmap(vshControl *ctl, { unsigned int flags =3D 0; virBitmap *ret =3D NULL; - xmlDocPtr xml =3D NULL; + g_autoptr(xmlDoc) xml =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; xmlNodePtr *nodes =3D NULL; int nnodes; @@ -6812,7 +6809,6 @@ virshDomainGetVcpuBitmap(vshControl *ctl, cleanup: VIR_FREE(online); VIR_FREE(nodes); - xmlFreeDoc(xml); return ret; } =20 @@ -11383,7 +11379,7 @@ static const vshCmdOptDef opts_domdisplay[] =3D { static bool cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) { - xmlDocPtr xml =3D NULL; + g_autoptr(xmlDoc) xml =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; g_autoptr(virshDomain) dom =3D NULL; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; @@ -11613,7 +11609,6 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) VIR_FREE(passwd); VIR_FREE(listen_addr); VIR_FREE(output); - xmlFreeDoc(xml); return ret; } =20 @@ -11638,7 +11633,7 @@ static const vshCmdOptDef opts_vncdisplay[] =3D { static bool cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd) { - xmlDocPtr xml =3D NULL; + g_autoptr(xmlDoc) xml =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; g_autoptr(virshDomain) dom =3D NULL; bool ret =3D false; @@ -11687,7 +11682,6 @@ cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd) =20 cleanup: VIR_FREE(listen_addr); - xmlFreeDoc(xml); return ret; } =20 @@ -11712,7 +11706,7 @@ static const vshCmdOptDef opts_ttyconsole[] =3D { static bool cmdTTYConsole(vshControl *ctl, const vshCmd *cmd) { - xmlDocPtr xml =3D NULL; + g_autoptr(xmlDoc) xml =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; bool ret =3D false; char *tty =3D NULL; @@ -11727,7 +11721,6 @@ cmdTTYConsole(vshControl *ctl, const vshCmd *cmd) ret =3D true; =20 cleanup: - xmlFreeDoc(xml); VIR_FREE(tty); return ret; } @@ -12068,7 +12061,7 @@ virshDomainDetachInterface(char *doc, const char *type, const char *mac) { - xmlDocPtr xml =3D NULL; + g_autoptr(xmlDoc) xml =3D NULL; g_autoptr(xmlXPathObject) obj =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; xmlNodePtr cur =3D NULL, matchNode =3D NULL; @@ -12143,7 +12136,6 @@ virshDomainDetachInterface(char *doc, =20 cleanup: VIR_FREE(detach_xml); - xmlFreeDoc(xml); return ret =3D=3D 0; } =20 @@ -12247,7 +12239,7 @@ virshFindDisk(const char *doc, const char *path, int type) { - xmlDocPtr xml =3D NULL; + g_autoptr(xmlDoc) xml =3D NULL; g_autoptr(xmlXPathObject) obj =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; xmlNodePtr cur =3D NULL; @@ -12323,7 +12315,6 @@ virshFindDisk(const char *doc, vshError(NULL, _("No disk found whose source path or target is %s"), p= ath); =20 cleanup: - xmlFreeDoc(xml); return ret; } =20 diff --git a/tools/virsh-host.c b/tools/virsh-host.c index b2d3a9c85f..a07f5adbfa 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -167,7 +167,7 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd) bool cellno =3D vshCommandOptBool(cmd, "cellno"); size_t i; char *cap_xml =3D NULL; - xmlDocPtr xml =3D NULL; + g_autoptr(xmlDoc) xml =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; virshControl *priv =3D ctl->privData; =20 @@ -243,7 +243,6 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd) ret =3D true; =20 cleanup: - xmlFreeDoc(xml); VIR_FREE(nodes); VIR_FREE(nodes_free); VIR_FREE(nodes_id); @@ -306,7 +305,7 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd) xmlNodePtr *nodes =3D NULL; int nodes_cnt; char *cap_xml =3D NULL; - xmlDocPtr doc =3D NULL; + g_autoptr(xmlDoc) doc =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; bool all =3D vshCommandOptBool(cmd, "all"); bool cellno =3D vshCommandOptBool(cmd, "cellno"); @@ -442,7 +441,6 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd) =20 ret =3D true; cleanup: - xmlFreeDoc(doc); VIR_FREE(cap_xml); VIR_FREE(nodes); VIR_FREE(counts); @@ -504,7 +502,7 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd) unsigned long long pageCounts[1], tmp; unsigned int flags =3D 0; char *cap_xml =3D NULL; - xmlDocPtr xml =3D NULL; + g_autoptr(xmlDoc) xml =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; xmlNodePtr *nodes =3D NULL; virshControl *priv =3D ctl->privData; @@ -569,7 +567,6 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd) =20 ret =3D true; cleanup: - xmlFreeDoc(xml); VIR_FREE(nodes); VIR_FREE(cap_xml); return ret; @@ -603,7 +600,7 @@ cmdMaxvcpus(vshControl *ctl, const vshCmd *cmd) const char *type =3D NULL; int vcpus =3D -1; char *caps =3D NULL; - xmlDocPtr xml =3D NULL; + g_autoptr(xmlDoc) xml =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; virshControl *priv =3D ctl->privData; bool ret =3D false; @@ -628,7 +625,6 @@ cmdMaxvcpus(vshControl *ctl, const vshCmd *cmd) ret =3D true; =20 cleanup: - xmlFreeDoc(xml); VIR_FREE(caps); return ret; } @@ -1120,7 +1116,7 @@ vshExtractCPUDefXMLs(vshControl *ctl, char **cpus =3D NULL; char *buffer =3D NULL; char *xmlStr =3D NULL; - xmlDocPtr xml =3D NULL; + g_autoptr(xmlDoc) xml =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; xmlNodePtr *nodes =3D NULL; char *doc; @@ -1183,7 +1179,6 @@ vshExtractCPUDefXMLs(vshControl *ctl, cleanup: VIR_FREE(buffer); VIR_FREE(xmlStr); - xmlFreeDoc(xml); VIR_FREE(nodes); return cpus; =20 diff --git a/tools/virsh-interface.c b/tools/virsh-interface.c index 1a94eba1c3..71cc265efc 100644 --- a/tools/virsh-interface.c +++ b/tools/virsh-interface.c @@ -821,7 +821,7 @@ cmdInterfaceBridge(vshControl *ctl, const vshCmd *cmd) char *if_xml =3D NULL; xmlChar *br_xml =3D NULL; int br_xml_size; - xmlDocPtr xml_doc =3D NULL; + g_autoptr(xmlDoc) xml_doc =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; xmlNodePtr top_node, br_node, if_node, cur; virshControl *priv =3D ctl->privData; @@ -1001,7 +1001,6 @@ cmdInterfaceBridge(vshControl *ctl, const vshCmd *cmd) VIR_FREE(if_type); VIR_FREE(if2_name); VIR_FREE(delay_str); - xmlFreeDoc(xml_doc); return ret; } =20 @@ -1042,7 +1041,7 @@ cmdInterfaceUnbridge(vshControl *ctl, const vshCmd *c= md) char *br_xml =3D NULL; xmlChar *if_xml =3D NULL; int if_xml_size; - xmlDocPtr xml_doc =3D NULL; + g_autoptr(xmlDoc) xml_doc =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; xmlNodePtr top_node, if_node, cur; virshControl *priv =3D ctl->privData; @@ -1200,7 +1199,6 @@ cmdInterfaceUnbridge(vshControl *ctl, const vshCmd *c= md) VIR_FREE(br_xml); VIR_FREE(if_type); VIR_FREE(if_name); - xmlFreeDoc(xml_doc); return ret; } =20 diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index 4b179d7d87..6a1fe6785b 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -525,7 +525,7 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd) static xmlChar * virshMakeCloneXML(const char *origxml, const char *newname) { - xmlDocPtr doc =3D NULL; + g_autoptr(xmlDoc) doc =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; g_autoptr(xmlXPathObject) obj =3D NULL; xmlChar *newxml =3D NULL; @@ -544,7 +544,6 @@ virshMakeCloneXML(const char *origxml, const char *newn= ame) xmlDocDumpMemory(doc, &newxml, &size); =20 cleanup: - xmlFreeDoc(doc); return newxml; } =20 --=20 2.31.1