[libvirt] [PATCH 2/2] conf: Fix leaks in virNetworkObjUpdateParseFile

Ján Tomko jtomko at redhat.com
Fri Jan 25 15:36:36 UTC 2013


Free the bitmap before calling virBitmapParse, which will overwrite it.

Also free xml.
---
 src/conf/network_conf.c |   19 +++++++++++--------
 1 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index c93916d..013333c 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -1855,14 +1855,16 @@ virNetworkObjUpdateParseFile(const char *filename,
 
         ctxt->node = node;
         class_id = virXPathString("string(./class_id[1]/@bitmap)", ctxt);
-        if (class_id &&
-            virBitmapParse(class_id, 0,
-                           &net->class_id, CLASS_ID_BITMAP_SIZE) < 0) {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("Malformed 'class_id' attribute: %s"),
-                           class_id);
-            VIR_FREE(class_id);
-            goto cleanup;
+        if (class_id) {
+            virBitmapFree(net->class_id);
+            if (virBitmapParse(class_id, 0,
+                               &net->class_id, CLASS_ID_BITMAP_SIZE) < 0) {
+                virReportError(VIR_ERR_INTERNAL_ERROR,
+                               _("Malformed 'class_id' attribute: %s"),
+                               class_id);
+                VIR_FREE(class_id);
+                goto cleanup;
+            }
         }
         VIR_FREE(class_id);
 
@@ -1896,6 +1898,7 @@ virNetworkObjUpdateParseFile(const char *filename,
 
 cleanup:
     xmlXPathFreeContext(ctxt);
+    xmlFreeDoc(xml);
     return ret;
 }
 
-- 
1.7.8.6




More information about the libvir-list mailing list