with more than 20 domains, I get this:
$ valgrind --leak-check=full ./virsh --connect test://$PWD/../docs/testnode.xml list
...
error: failed to connect to the hypervisor
...
==13756== 5 bytes in 1 blocks are definitely lost in loss record 1 of 32
==13756== at 0x4A059F6: malloc (vg_replace_malloc.c:149)
==13756== by 0x387BC7CC11: strdup (strdup.c:43)
==13756== by 0x41D9F2: virXPathString (xml.c:486)
==13756== by 0x4174D3: testLoadDomain (test.c:248)
==13756== by 0x417BA4: testLoadDomainFromFile (test.c:401)
==13756== by 0x418E57: testOpenFromFile (test.c:797)
==13756== by 0x4192CE: testOpen (test.c:913)
==13756== by 0x40FA20: do_open (libvirt.c:572)
==13756== by 0x40FDE4: virConnectOpenAuth (libvirt.c:681)
==13756== by 0x40D5B1: vshInit (virsh.c:4464)
==13756== by 0x40E67C: main (virsh.c:4985)
==13756==
==13756==
==13756== 12,996 (352 direct, 12,644 indirect) bytes in 1 blocks are definitely lost in
loss record 31 of 32
==13756== at 0x4A059F6: malloc (vg_replace_malloc.c:149)
==13756== by 0x38864880E6: xmlXPathNewContext (in /usr/lib64/libxml2.so.2.6.31)
==13756== by 0x417494: testLoadDomain (test.c:242)
==13756== by 0x417BA4: testLoadDomainFromFile (test.c:401)
==13756== by 0x418E57: testOpenFromFile (test.c:797)
==13756== by 0x4192CE: testOpen (test.c:913)
==13756== by 0x40FA20: do_open (libvirt.c:572)
==13756== by 0x40FDE4: virConnectOpenAuth (libvirt.c:681)
==13756== by 0x40D5B1: vshInit (virsh.c:4464)
==13756== by 0x40E67C: main (virsh.c:4985)
==13756==
==13756== LEAK SUMMARY:
==13756== definitely lost: 357 bytes in 2 blocks.
==13756== indirectly lost: 12,644 bytes in 32 blocks.
==13756== possibly lost: 0 bytes in 0 blocks.
==13756== still reachable: 20,614 bytes in 362 blocks.
==13756== suppressed: 0 bytes in 0 blocks.
==13756== Reachable blocks (those to which a pointer was found) are not shown.
==13756== To see them, rerun with: --leak-check=full --show-reachable
Here's the fix:
* test.c (testLoadDomain): Avoid leaks upon failure.
---
src/test.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/test.c b/src/test.c
index fe5da41..ab83f65 100644
--- a/src/test.c
+++ b/src/test.c
@@ -327,7 +327,7 @@ static int testLoadDomain(virConnectPtr conn,
}
}
if (handle < 0)
- return (-1);
+ goto error;
privconn->domains[handle].active = 1;
privconn->domains[handle].id = domid;
--
1.5.4.rc5.1.g0fa73