tools: virsh: use automatic cleanup for xmlXPathContext

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