[Libvir] [PATCH] Fix memory leak on virDomainParseXMLDiskDesc()

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@aa.jp.fujitsu.com> 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); } /**

On Wed, Jul 11, 2007 at 05:19:27PM +0900, Masayuki Sunou wrote:
Hi
I found some memory leaks in xml.c --> Missing release of drvType and drvName in virDomainParseXMLDiskDesc(). This patch fixes it.
Looks good, and the small refactoring makes the code cleaner :-) Applied and commited to CVS, thanks a lot ! Daniel -- Red Hat Virtualization group http://redhat.com/virtualization/ Daniel Veillard | virtualization library http://libvirt.org/ veillard@redhat.com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/

Masayuki Sunou wrote:
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@aa.jp.fujitsu.com>
+1 Rich. -- Emerging Technologies, Red Hat - http://et.redhat.com/~rjones/ Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SL4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 03798903
participants (3)
-
Daniel Veillard
-
Masayuki Sunou
-
Richard W.M. Jones