[PATCH] Fix memory leak on virDomainParseXMLDiskDesc()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi

I found some memory leaks in xml.c 
 --> Missing release of drvType and drvName in virDomainParseXMLDiskDesc().
This patch fixes it.

Signed-off-by: Masayuki Sunou <fj1826dm@xxxxxxxxxxxxxxxxx>

Thanks,
Masayuki Sunou.
--------------------------------------------------------------------------------
Index: src/xml.c
===================================================================
RCS file: /data/cvs/libvirt/src/xml.c,v
retrieving revision 1.80
diff -u -p -r1.80 xml.c
--- src/xml.c	4 Jul 2007 09:16:23 -0000	1.80
+++ src/xml.c	11 Jul 2007 07:51:17 -0000
@@ -719,6 +719,7 @@ virDomainParseXMLDiskDesc(virConnectPtr 
     int typ = 0;
     int cdrom = 0;
     int isNoSrcCdrom = 0;
+    int ret = 0;
 
     type = xmlGetProp(node, BAD_CAST "type");
     if (type != NULL) {
@@ -768,21 +769,14 @@ virDomainParseXMLDiskDesc(virConnectPtr 
         }
         if (!isNoSrcCdrom) {
             virXMLError(conn, VIR_ERR_NO_SOURCE, (const char *) target, 0);
-
-            if (target != NULL)
-                xmlFree(target);
-            if (device != NULL)
-                xmlFree(device);
-            return (-1);
+            ret = -1;
+            goto cleanup;
         }
     }
     if (target == NULL) {
         virXMLError(conn, VIR_ERR_NO_TARGET, (const char *) source, 0);
-        if (source != NULL)
-            xmlFree(source);
-        if (device != NULL)
-            xmlFree(device);
-        return (-1);
+        ret = -1;
+        goto cleanup;
     }
 
     /* Xend (all versions) put the floppy device config
@@ -861,12 +855,17 @@ virDomainParseXMLDiskDesc(virConnectPtr 
     virBufferAdd(buf, ")", 1);
 
  cleanup:
-    xmlFree(drvType);
-    xmlFree(drvName);
-    xmlFree(device);
-    xmlFree(target);
-    xmlFree(source);
-    return (0);
+    if(drvType)
+        xmlFree(drvType);
+    if(drvName)
+        xmlFree(drvName);
+    if(device)
+        xmlFree(device);
+    if(target)
+        xmlFree(target);
+    if(source)
+        xmlFree(source);
+    return (ret);
 }
 
 /**

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]