[libvirt] [PATCH] Fix memory leak issues in virshAllocpagesPagesizeCompleter.

Roland Schulz schullzroll at gmail.com
Wed May 23 12:40:41 UTC 2018


Signed-off-by: Roland Schulz <schullzroll at gmail.com>
---
 tools/virsh-completer.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c
index 1435d1d4c..c72f3bcad 100644
--- a/tools/virsh-completer.c
+++ b/tools/virsh-completer.c
@@ -576,6 +576,7 @@ virshAllocpagesPagesizeCompleter(vshControl *ctl,
     virshControlPtr priv = ctl->privData;
     unsigned int npages = 0;
     xmlNodePtr *pages = NULL;
+    xmlDocPtr doc = NULL;
     double size = 0;
     size_t i = 0;
     const char *suffix = NULL;
@@ -595,7 +596,7 @@ virshAllocpagesPagesizeCompleter(vshControl *ctl,
     if (!(cap_xml = virConnectGetCapabilities(priv->conn)))
         goto error;
 
-    if (!(virXMLParseStringCtxt(cap_xml, _("capabilities"), &ctxt)))
+    if ((doc = virXMLParseStringCtxt(cap_xml, _("capabilities"), &ctxt)) == NULL)
         goto error;
 
     if (cellno && vshCommandOptStringQuiet(ctl, cmd, "cellno", &cellnum) > 0) {
@@ -631,12 +632,11 @@ virshAllocpagesPagesizeCompleter(vshControl *ctl,
 
  cleanup:
     xmlXPathFreeContext(ctxt);
-    for (i = 0; i < npages; i++)
-        VIR_FREE(pages[i]);
     VIR_FREE(pages);
-    VIR_FREE(cap_xml);
+    xmlFreeDoc(doc);
     VIR_FREE(path);
     VIR_FREE(pagesize);
+    VIR_FREE(cap_xml);
     VIR_FREE(unit);
 
     return ret;
-- 
2.17.0




More information about the libvir-list mailing list