From 9707c2a8bc5ea8a2a80628e92dbdc6a85ea3e22e Mon Sep 17 00:00:00 2001 From: Alex Jia Date: Thu, 8 Dec 2011 17:11:26 +0800 Subject: [PATCH] virsh: plug memory leak on cmdDomblklist Detected by valgrind. Leak introduced in commit 88a993b: * tools/virsh.c: fix memory leak on cmdDomblklist. * how to reproduce? % valgrind -v --leak-check=full virsh domblklist * actual valgrind result: ==6573== 1,836 bytes in 1 blocks are definitely lost in loss record 110 of 124 ==6573== at 0x4A05FDE: malloc (vg_replace_malloc.c:236) ==6573== by 0x330D71497D: xdr_string (in /lib64/libc-2.12.so) ==6573== by 0x4D26CED: xdr_remote_nonnull_string (remote_protocol.c:30) ==6573== by 0x4D28138: xdr_remote_domain_get_xml_desc_ret (remote_protocol.c:1418) ==6573== by 0x4D3C0C2: virNetMessageDecodePayload (virnetmessage.c:382) ==6573== by 0x4D3279F: virNetClientProgramCall (virnetclientprogram.c:382) ==6573== by 0x4D0D50B: callWithFD (remote_driver.c:4339) ==6573== by 0x4D0D5AB: call (remote_driver.c:4360) ==6573== by 0x4D16EAF: remoteDomainGetXMLDesc (remote_client_bodies.h:861) ==6573== by 0x4CF9F4F: virDomainGetXMLDesc (libvirt.c:4098) ==6573== by 0x4154D9: cmdDomblklist (virsh.c:1722) ==6573== by 0x4149E2: vshCommandRun (virsh.c:16365) ==6573== ==6573== 46,009 (352 direct, 45,657 indirect) bytes in 1 blocks are definitely lost in loss record 123 of 124 ==6573== at 0x4A05FDE: malloc (vg_replace_malloc.c:236) ==6573== by 0x3318286DC6: xmlXPathNewContext (in /usr/lib64/libxml2.so.2.7.6) ==6573== by 0x4C79AE2: virXMLParseHelper (xml.c:779) ==6573== by 0x415512: cmdDomblklist (virsh.c:1726) ==6573== by 0x4149E2: vshCommandRun (virsh.c:16365) ==6573== by 0x427743: main (virsh.c:17867) ==6573== ==6573== LEAK SUMMARY: ==6573== definitely lost: 2,188 bytes in 2 blocks ==6573== indirectly lost: 45,657 bytes in 332 blocks ==6573== possibly lost: 0 bytes in 0 blocks ==6573== still reachable: 128,034 bytes in 1,364 blocks ==6573== suppressed: 0 bytes in 0 blocks Signed-off-by: Alex Jia --- tools/virsh.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/virsh.c b/tools/virsh.c index 90ff5874f1..d859b3adf5 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -1759,6 +1759,9 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd) cleanup: VIR_FREE(disks); virDomainFree(dom); + VIR_FREE(xml); + xmlFreeDoc(xmldoc); + xmlXPathFreeContext(ctxt); return ret; } -- GitLab