[libvirt] [PATCH 3/3] fillQemuCaps: Don't leak machine string

Michal Privoznik posted 3 patches 8 years, 1 month ago
[libvirt] [PATCH 3/3] fillQemuCaps: Don't leak machine string
Posted by Michal Privoznik 8 years, 1 month ago
==25251== 5 bytes in 1 blocks are definitely lost in loss record 7 of 81
==25251==    at 0x4C2BEDF: malloc (vg_replace_malloc.c:299)
==25251==    by 0x967E379: strdup (in /lib64/libc-2.25.so)
==25251==    by 0x5366F9F: virStrdup (virstring.c:941)
==25251==    by 0x538BF1D: virDomainCapsNew (domain_capabilities.c:121)
==25251==    by 0x10EACE: test_virDomainCapsFormat (domaincapstest.c:295)
==25251==    by 0x10FBD2: virTestRun (testutils.c:180)
==25251==    by 0x10F192: mymain (domaincapstest.c:457)
==25251==    by 0x111C7F: virTestMain (testutils.c:1119)
==25251==    by 0x10FA3C: main (domaincapstest.c:528)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 tests/domaincapstest.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/tests/domaincapstest.c b/tests/domaincapstest.c
index 76494a01c..533a4b379 100644
--- a/tests/domaincapstest.c
+++ b/tests/domaincapstest.c
@@ -159,10 +159,12 @@ fillQemuCaps(virDomainCapsPtr domCaps,
         !(qemuCaps = qemuTestParseCapabilities(caps, path)))
         goto cleanup;
 
-    if (machine &&
-        VIR_STRDUP(domCaps->machine,
-                   virQEMUCapsGetCanonicalMachine(qemuCaps, machine)) < 0)
-        goto cleanup;
+    if (machine) {
+        VIR_FREE(domCaps->machine);
+        if (VIR_STRDUP(domCaps->machine,
+                       virQEMUCapsGetCanonicalMachine(qemuCaps, machine)) < 0)
+            goto cleanup;
+    }
 
     if (!domCaps->machine &&
         VIR_STRDUP(domCaps->machine,
-- 
2.13.6

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 3/3] fillQemuCaps: Don't leak machine string
Posted by John Ferlan 8 years, 1 month ago

On 12/12/2017 09:10 AM, Michal Privoznik wrote:
> ==25251== 5 bytes in 1 blocks are definitely lost in loss record 7 of 81
> ==25251==    at 0x4C2BEDF: malloc (vg_replace_malloc.c:299)
> ==25251==    by 0x967E379: strdup (in /lib64/libc-2.25.so)
> ==25251==    by 0x5366F9F: virStrdup (virstring.c:941)
> ==25251==    by 0x538BF1D: virDomainCapsNew (domain_capabilities.c:121)
> ==25251==    by 0x10EACE: test_virDomainCapsFormat (domaincapstest.c:295)
> ==25251==    by 0x10FBD2: virTestRun (testutils.c:180)
> ==25251==    by 0x10F192: mymain (domaincapstest.c:457)
> ==25251==    by 0x111C7F: virTestMain (testutils.c:1119)
> ==25251==    by 0x10FA3C: main (domaincapstest.c:528)
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  tests/domaincapstest.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 

Reviewed-by: John Ferlan <jferlan@redhat.com>

John

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