From ea964658af7a54216e3c7c3ee2e0d2ea719ba018 Mon Sep 17 00:00:00 2001 From: Alex Jia Date: Tue, 20 Dec 2011 18:33:52 +0800 Subject: [PATCH] virsh: plug mem leaks in domxml-*-native Detected by valgrind. Leaks introduced in commit 4d5383f. * tools/virsh.c: fix memory leaks on cmdDomXMLFromNative and cmdDomXMLToNative. * how to reproduce? % virsh dumpxml ${guest} > foo.xml % valgrind -v --leak-check=full virsh domxml-from-native qemu-argv foo.xml % valgrind -v --leak-check=full virsh domxml-to-native qemu-argv foo.xml * actual valgrind results: ==9724== 8,193 bytes in 1 blocks are definitely lost in loss record 31 of 33 ==9724== at 0x4A05FDE: malloc (vg_replace_malloc.c:236) ==9724== by 0x4A06167: realloc (vg_replace_malloc.c:525) ==9724== by 0x4C7510B: virReallocN (memory.c:161) ==9724== by 0x4C84679: virFileReadLimFD (util.c:394) ==9724== by 0x4C84815: virFileReadAll (util.c:455) ==9724== by 0x41A89F: cmdDomXMLFromNative (virsh.c:5532) ==9724== by 0x414872: vshCommandRun (virsh.c:16464) ==9724== by 0x425623: main (virsh.c:17971) ==9724== ==9724== LEAK SUMMARY: ==9724== definitely lost: 8,193 bytes in 1 blocks ==9724== indirectly lost: 0 bytes in 0 blocks ==9724== possibly lost: 0 bytes in 0 blocks ==9724== still reachable: 127,128 bytes in 1,347 blocks ==7409== 8,193 bytes in 1 blocks are definitely lost in loss record 31 of 33 ==7409== at 0x4A05FDE: malloc (vg_replace_malloc.c:236) ==7409== by 0x4A06167: realloc (vg_replace_malloc.c:525) ==7409== by 0x4C7510B: virReallocN (memory.c:161) ==7409== by 0x4C84679: virFileReadLimFD (util.c:394) ==7409== by 0x4C84815: virFileReadAll (util.c:455) ==7409== by 0x41A7AF: cmdDomXMLToNative (virsh.c:5578) ==7409== by 0x414892: vshCommandRun (virsh.c:16463) ==7409== by 0x425633: main (virsh.c:17970) ==7409== ==7409== LEAK SUMMARY: ==7409== definitely lost: 8,193 bytes in 1 blocks ==7409== indirectly lost: 0 bytes in 0 blocks ==7409== possibly lost: 0 bytes in 0 blocks ==7409== still reachable: 127,128 bytes in 1,347 blocks Signed-off-by: Alex Jia --- tools/virsh.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/virsh.c b/tools/virsh.c index 0cf51e42b8..ed9e1b75c9 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -5699,6 +5699,7 @@ cmdDomXMLFromNative(vshControl *ctl, const vshCmd *cmd) ret = false; } + VIR_FREE(configData); return ret; } @@ -5745,6 +5746,7 @@ cmdDomXMLToNative(vshControl *ctl, const vshCmd *cmd) ret = false; } + VIR_FREE(xmlData); return ret; }