]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tools: virsh: use automatic cleanup for xmlXPathContext
authorJán Tomko <jtomko@redhat.com>
Wed, 11 Aug 2021 11:21:18 +0000 (13:21 +0200)
committerJán Tomko <jtomko@redhat.com>
Mon, 16 Aug 2021 11:10:33 +0000 (13:10 +0200)
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
tools/virsh-completer-domain.c
tools/virsh-domain-monitor.c
tools/virsh-domain.c
tools/virsh-host.c
tools/virsh-interface.c
tools/virsh-volume.c

index d1430c951abc6411edfde8aa2e4344c359cdd221..4cdc533a07ecab05d5443e7f8feb0d8dd4179699 100644 (file)
@@ -479,7 +479,7 @@ virshDomainVcpuCompleter(vshControl *ctl,
 {
     g_autoptr(virshDomain) dom = NULL;
     xmlDocPtr xml = NULL;
-    xmlXPathContextPtr ctxt = NULL;
+    g_autoptr(xmlXPathContext) ctxt = NULL;
     int nvcpus = 0;
     unsigned int id;
     char **ret = NULL;
@@ -506,7 +506,6 @@ virshDomainVcpuCompleter(vshControl *ctl,
     ret = g_steal_pointer(&tmp);
 
  cleanup:
-    xmlXPathFreeContext(ctxt);
     xmlFreeDoc(xml);
     return ret;
 }
@@ -519,7 +518,7 @@ virshDomainVcpulistCompleter(vshControl *ctl,
 {
     g_autoptr(virshDomain) dom = NULL;
     xmlDocPtr xml = NULL;
-    xmlXPathContextPtr ctxt = NULL;
+    g_autoptr(xmlXPathContext) ctxt = NULL;
     int nvcpus = 0;
     unsigned int id;
     g_auto(GStrv) vcpulist = NULL;
@@ -550,7 +549,6 @@ virshDomainVcpulistCompleter(vshControl *ctl,
     ret = virshCommaStringListComplete(vcpuid, (const char **)vcpulist);
 
  cleanup:
-    xmlXPathFreeContext(ctxt);
     xmlFreeDoc(xml);
     return ret;
 }
index d0c87255974f4b456dca3139e3aa84c1b52919c1..7190ec563acd4d2c4205a07777e91055c887c939 100644 (file)
@@ -56,7 +56,7 @@ virshGetDomainDescription(vshControl *ctl, virDomainPtr dom, bool title,
 {
     char *desc = NULL;
     xmlDocPtr doc = NULL;
-    xmlXPathContextPtr ctxt = NULL;
+    g_autoptr(xmlXPathContext) ctxt = NULL;
     int type;
 
     if (title)
@@ -92,7 +92,6 @@ virshGetDomainDescription(vshControl *ctl, virDomainPtr dom, bool title,
         desc = g_strdup("");
 
  cleanup:
-    xmlXPathFreeContext(ctxt);
     xmlFreeDoc(doc);
 
     return desc;
@@ -583,7 +582,7 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd)
     bool ret = false;
     unsigned int flags = 0;
     xmlDocPtr xmldoc = NULL;
-    xmlXPathContextPtr ctxt = NULL;
+    g_autoptr(xmlXPathContext) ctxt = NULL;
     int ndisks;
     xmlNodePtr *disks = NULL;
     size_t i;
@@ -682,7 +681,6 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd)
     VIR_FREE(device);
     VIR_FREE(type);
     VIR_FREE(disks);
-    xmlXPathFreeContext(ctxt);
     xmlFreeDoc(xmldoc);
     return ret;
 }
@@ -711,7 +709,7 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd)
     bool ret = false;
     unsigned int flags = 0;
     xmlDocPtr xmldoc = NULL;
-    xmlXPathContextPtr ctxt = NULL;
+    g_autoptr(xmlXPathContext) ctxt = NULL;
     int ninterfaces;
     xmlNodePtr *interfaces = NULL;
     size_t i;
@@ -770,7 +768,6 @@ cmdDomiflist(vshControl *ctl, const vshCmd *cmd)
     vshTableFree(table);
     VIR_FREE(interfaces);
     xmlFreeDoc(xmldoc);
-    xmlXPathFreeContext(ctxt);
     return ret;
 }
 
@@ -812,7 +809,7 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd)
     virMacAddr macaddr;
     char macstr[VIR_MAC_STRING_BUFLEN] = "";
     xmlDocPtr xml = NULL;
-    xmlXPathContextPtr ctxt = NULL;
+    g_autoptr(xmlXPathContext) ctxt = NULL;
     xmlNodePtr *interfaces = NULL;
     int ninterfaces;
     unsigned int flags = 0;
@@ -865,7 +862,6 @@ cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd)
     VIR_FREE(state);
     VIR_FREE(interfaces);
     VIR_FREE(xpath);
-    xmlXPathFreeContext(ctxt);
     xmlFreeDoc(xml);
 
     return ret;
index b671ae398f133149fe03bc5b1017c7cb18a58602..398190bb5b7cb5036b049bfc6b9467bcd58293c2 100644 (file)
@@ -3065,7 +3065,7 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd)
     unsigned int xmlflags = 0;
     size_t i;
     xmlDocPtr xml = NULL;
-    xmlXPathContextPtr ctxt = NULL;
+    g_autoptr(xmlXPathContext) ctxt = NULL;
     xmlXPathObjectPtr obj = NULL;
     xmlNodePtr cur = NULL;
     char *xml_buf = NULL;
@@ -3179,7 +3179,6 @@ cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd)
 
  cleanup:
     xmlXPathFreeObject(obj);
-    xmlXPathFreeContext(ctxt);
     xmlFreeDoc(xml);
     VIR_FREE(xml_buf);
 
@@ -3639,7 +3638,7 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd)
     virshUndefineVolume *vols = NULL; /* info about the volumes to delete */
     size_t nvols = 0;
     xmlDocPtr doc = NULL;
-    xmlXPathContextPtr ctxt = NULL;
+    g_autoptr(xmlXPathContext) ctxt = NULL;
     xmlNodePtr *vol_nodes = NULL;   /* XML nodes of volumes of the guest */
     int nvol_nodes;
     char *source = NULL;
@@ -3956,7 +3955,6 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd)
 
     VIR_FREE(vol_nodes);
     xmlFreeDoc(doc);
-    xmlXPathFreeContext(ctxt);
     return ret;
 
  error:
@@ -6555,7 +6553,7 @@ virshCPUCountCollect(vshControl *ctl,
     virDomainInfo info;
     int count;
     xmlDocPtr xml = NULL;
-    xmlXPathContextPtr ctxt = NULL;
+    g_autoptr(xmlXPathContext) ctxt = NULL;
 
     if (checkState &&
         ((flags & VIR_DOMAIN_AFFECT_LIVE && virDomainIsActive(dom) < 1) ||
@@ -6614,7 +6612,6 @@ virshCPUCountCollect(vshControl *ctl,
 
     ret = count;
  cleanup:
-    xmlXPathFreeContext(ctxt);
     xmlFreeDoc(xml);
 
     return ret;
@@ -6759,7 +6756,7 @@ virshDomainGetVcpuBitmap(vshControl *ctl,
     unsigned int flags = 0;
     virBitmap *ret = NULL;
     xmlDocPtr xml = NULL;
-    xmlXPathContextPtr ctxt = NULL;
+    g_autoptr(xmlXPathContext) ctxt = NULL;
     xmlNodePtr *nodes = NULL;
     int nnodes;
     size_t i;
@@ -6816,7 +6813,6 @@ virshDomainGetVcpuBitmap(vshControl *ctl,
  cleanup:
     VIR_FREE(online);
     VIR_FREE(nodes);
-    xmlXPathFreeContext(ctxt);
     xmlFreeDoc(xml);
     return ret;
 }
@@ -11389,7 +11385,7 @@ static bool
 cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
 {
     xmlDocPtr xml = NULL;
-    xmlXPathContextPtr ctxt = NULL;
+    g_autoptr(xmlXPathContext) ctxt = NULL;
     g_autoptr(virshDomain) dom = NULL;
     g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
     bool ret = false;
@@ -11618,7 +11614,6 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
     VIR_FREE(passwd);
     VIR_FREE(listen_addr);
     VIR_FREE(output);
-    xmlXPathFreeContext(ctxt);
     xmlFreeDoc(xml);
     return ret;
 }
@@ -11645,7 +11640,7 @@ static bool
 cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd)
 {
     xmlDocPtr xml = NULL;
-    xmlXPathContextPtr ctxt = NULL;
+    g_autoptr(xmlXPathContext) ctxt = NULL;
     g_autoptr(virshDomain) dom = NULL;
     bool ret = false;
     int port = 0;
@@ -11693,7 +11688,6 @@ cmdVNCDisplay(vshControl *ctl, const vshCmd *cmd)
 
  cleanup:
     VIR_FREE(listen_addr);
-    xmlXPathFreeContext(ctxt);
     xmlFreeDoc(xml);
     return ret;
 }
@@ -11720,7 +11714,7 @@ static bool
 cmdTTYConsole(vshControl *ctl, const vshCmd *cmd)
 {
     xmlDocPtr xml = NULL;
-    xmlXPathContextPtr ctxt = NULL;
+    g_autoptr(xmlXPathContext) ctxt = NULL;
     bool ret = false;
     char *tty = NULL;
 
@@ -11734,7 +11728,6 @@ cmdTTYConsole(vshControl *ctl, const vshCmd *cmd)
     ret = true;
 
  cleanup:
-    xmlXPathFreeContext(ctxt);
     xmlFreeDoc(xml);
     VIR_FREE(tty);
     return ret;
@@ -12078,7 +12071,7 @@ virshDomainDetachInterface(char *doc,
 {
     xmlDocPtr xml = NULL;
     xmlXPathObjectPtr obj = NULL;
-    xmlXPathContextPtr ctxt = NULL;
+    g_autoptr(xmlXPathContext) ctxt = NULL;
     xmlNodePtr cur = NULL, matchNode = NULL;
     char *detach_xml = NULL;
     char buf[64];
@@ -12153,7 +12146,6 @@ virshDomainDetachInterface(char *doc,
     VIR_FREE(detach_xml);
     xmlFreeDoc(xml);
     xmlXPathFreeObject(obj);
-    xmlXPathFreeContext(ctxt);
     return ret == 0;
 }
 
@@ -12259,7 +12251,7 @@ virshFindDisk(const char *doc,
 {
     xmlDocPtr xml = NULL;
     xmlXPathObjectPtr obj = NULL;
-    xmlXPathContextPtr ctxt = NULL;
+    g_autoptr(xmlXPathContext) ctxt = NULL;
     xmlNodePtr cur = NULL;
     xmlNodePtr ret = NULL;
     size_t i;
@@ -12334,7 +12326,6 @@ virshFindDisk(const char *doc,
 
  cleanup:
     xmlXPathFreeObject(obj);
-    xmlXPathFreeContext(ctxt);
     xmlFreeDoc(xml);
     return ret;
 }
index 7b47b7583d68fb914eadea2d1cf53fe2a375f9db..b2d3a9c85f5ce82a34993a102455230b5783d832 100644 (file)
@@ -168,7 +168,7 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
     size_t i;
     char *cap_xml = NULL;
     xmlDocPtr xml = NULL;
-    xmlXPathContextPtr ctxt = NULL;
+    g_autoptr(xmlXPathContext) ctxt = NULL;
     virshControl *priv = ctl->privData;
 
     VSH_EXCLUSIVE_OPTIONS_VAR(all, cellno);
@@ -243,7 +243,6 @@ cmdFreecell(vshControl *ctl, const vshCmd *cmd)
     ret = true;
 
  cleanup:
-    xmlXPathFreeContext(ctxt);
     xmlFreeDoc(xml);
     VIR_FREE(nodes);
     VIR_FREE(nodes_free);
@@ -308,7 +307,7 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd)
     int nodes_cnt;
     char *cap_xml = NULL;
     xmlDocPtr doc = NULL;
-    xmlXPathContextPtr ctxt = NULL;
+    g_autoptr(xmlXPathContext) ctxt = NULL;
     bool all = vshCommandOptBool(cmd, "all");
     bool cellno = vshCommandOptBool(cmd, "cellno");
     bool pagesz = vshCommandOptBool(cmd, "pagesize");
@@ -443,7 +442,6 @@ cmdFreepages(vshControl *ctl, const vshCmd *cmd)
 
     ret = true;
  cleanup:
-    xmlXPathFreeContext(ctxt);
     xmlFreeDoc(doc);
     VIR_FREE(cap_xml);
     VIR_FREE(nodes);
@@ -507,7 +505,7 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd)
     unsigned int flags = 0;
     char *cap_xml = NULL;
     xmlDocPtr xml = NULL;
-    xmlXPathContextPtr ctxt = NULL;
+    g_autoptr(xmlXPathContext) ctxt = NULL;
     xmlNodePtr *nodes = NULL;
     virshControl *priv = ctl->privData;
 
@@ -571,7 +569,6 @@ cmdAllocpages(vshControl *ctl, const vshCmd *cmd)
 
     ret = true;
  cleanup:
-    xmlXPathFreeContext(ctxt);
     xmlFreeDoc(xml);
     VIR_FREE(nodes);
     VIR_FREE(cap_xml);
@@ -607,7 +604,7 @@ cmdMaxvcpus(vshControl *ctl, const vshCmd *cmd)
     int vcpus = -1;
     char *caps = NULL;
     xmlDocPtr xml = NULL;
-    xmlXPathContextPtr ctxt = NULL;
+    g_autoptr(xmlXPathContext) ctxt = NULL;
     virshControl *priv = ctl->privData;
     bool ret = false;
 
@@ -631,7 +628,6 @@ cmdMaxvcpus(vshControl *ctl, const vshCmd *cmd)
     ret = true;
 
  cleanup:
-    xmlXPathFreeContext(ctxt);
     xmlFreeDoc(xml);
     VIR_FREE(caps);
     return ret;
@@ -1125,7 +1121,7 @@ vshExtractCPUDefXMLs(vshControl *ctl,
     char *buffer = NULL;
     char *xmlStr = NULL;
     xmlDocPtr xml = NULL;
-    xmlXPathContextPtr ctxt = NULL;
+    g_autoptr(xmlXPathContext) ctxt = NULL;
     xmlNodePtr *nodes = NULL;
     char *doc;
     size_t i;
@@ -1188,7 +1184,6 @@ vshExtractCPUDefXMLs(vshControl *ctl,
     VIR_FREE(buffer);
     VIR_FREE(xmlStr);
     xmlFreeDoc(xml);
-    xmlXPathFreeContext(ctxt);
     VIR_FREE(nodes);
     return cpus;
 
index 41acae5dcbb16baec273115c18d326525008e90e..1a94eba1c3cbe1bd2c25eb3b67005dd486b879f3 100644 (file)
@@ -822,7 +822,7 @@ cmdInterfaceBridge(vshControl *ctl, const vshCmd *cmd)
     xmlChar *br_xml = NULL;
     int br_xml_size;
     xmlDocPtr xml_doc = NULL;
-    xmlXPathContextPtr ctxt = NULL;
+    g_autoptr(xmlXPathContext) ctxt = NULL;
     xmlNodePtr top_node, br_node, if_node, cur;
     virshControl *priv = ctl->privData;
 
@@ -1001,7 +1001,6 @@ cmdInterfaceBridge(vshControl *ctl, const vshCmd *cmd)
     VIR_FREE(if_type);
     VIR_FREE(if2_name);
     VIR_FREE(delay_str);
-    xmlXPathFreeContext(ctxt);
     xmlFreeDoc(xml_doc);
     return ret;
 }
@@ -1044,7 +1043,7 @@ cmdInterfaceUnbridge(vshControl *ctl, const vshCmd *cmd)
     xmlChar *if_xml = NULL;
     int if_xml_size;
     xmlDocPtr xml_doc = NULL;
-    xmlXPathContextPtr ctxt = NULL;
+    g_autoptr(xmlXPathContext) ctxt = NULL;
     xmlNodePtr top_node, if_node, cur;
     virshControl *priv = ctl->privData;
 
@@ -1201,7 +1200,6 @@ cmdInterfaceUnbridge(vshControl *ctl, const vshCmd *cmd)
     VIR_FREE(br_xml);
     VIR_FREE(if_type);
     VIR_FREE(if_name);
-    xmlXPathFreeContext(ctxt);
     xmlFreeDoc(xml_doc);
     return ret;
 }
index fe632b1b1999dfa11ac7c93743bf49f63311e557..c9c4310cbd06752a9629b1110e48efecff19ec21 100644 (file)
@@ -526,7 +526,7 @@ static xmlChar *
 virshMakeCloneXML(const char *origxml, const char *newname)
 {
     xmlDocPtr doc = NULL;
-    xmlXPathContextPtr ctxt = NULL;
+    g_autoptr(xmlXPathContext) ctxt = NULL;
     xmlXPathObjectPtr obj = NULL;
     xmlChar *newxml = NULL;
     int size;
@@ -545,7 +545,6 @@ virshMakeCloneXML(const char *origxml, const char *newname)
 
  cleanup:
     xmlXPathFreeObject(obj);
-    xmlXPathFreeContext(ctxt);
     xmlFreeDoc(doc);
     return newxml;
 }