[libvirt] [PATCH 0/3] Couple of mem leak fixes

*** BLURB HERE *** Michal Privoznik (3): xenParseXLVnuma: Don't leak @tmp and @token xenMakeIPList: Don't leak @address_array fillQemuCaps: Don't leak machine string src/xenconfig/xen_common.c | 1 + src/xenconfig/xen_xl.c | 2 ++ tests/domaincapstest.c | 10 ++++++---- 3 files changed, 9 insertions(+), 4 deletions(-) -- 2.13.6

==30399== 180 (144 direct, 36 indirect) bytes in 3 blocks are definitely lost in loss record 91 of 111 ==30399== at 0x4C2E0FF: realloc (vg_replace_malloc.c:785) ==30399== by 0x5574572: virReallocN (viralloc.c:245) ==30399== by 0x5574668: virExpandN (viralloc.c:294) ==30399== by 0x55747AB: virResizeN (viralloc.c:352) ==30399== by 0x560074D: virStringSplitCount (virstring.c:115) ==30399== by 0x137A59: xenParseXLVnuma (xen_xl.c:442) ==30399== by 0x13952B: xenParseXL (xen_xl.c:1064) ==30399== by 0x11884D: testCompareFormatXML (xlconfigtest.c:152) ==30399== by 0x118A87: testCompareHelper (xlconfigtest.c:207) ==30399== by 0x119E36: virTestRun (testutils.c:180) ==30399== by 0x119186: mymain (xlconfigtest.c:274) ==30399== by 0x11BEE3: virTestMain (testutils.c:1119) Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/xenconfig/xen_xl.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/xenconfig/xen_xl.c b/src/xenconfig/xen_xl.c index 532d6677b..2ef80eb83 100644 --- a/src/xenconfig/xen_xl.c +++ b/src/xenconfig/xen_xl.c @@ -436,9 +436,11 @@ xenParseXLVnuma(virConfPtr conf, goto cleanup; } + VIR_FREE(tmp); if (VIR_STRDUP(tmp, vtoken) < 0) goto cleanup; + virStringListFree(token); if (!(token = virStringSplitCount(tmp, ",", 0, &ndistances))) goto cleanup; -- 2.13.6

On 12/12/2017 09:10 AM, Michal Privoznik wrote:
==30399== 180 (144 direct, 36 indirect) bytes in 3 blocks are definitely lost in loss record 91 of 111 ==30399== at 0x4C2E0FF: realloc (vg_replace_malloc.c:785) ==30399== by 0x5574572: virReallocN (viralloc.c:245) ==30399== by 0x5574668: virExpandN (viralloc.c:294) ==30399== by 0x55747AB: virResizeN (viralloc.c:352) ==30399== by 0x560074D: virStringSplitCount (virstring.c:115) ==30399== by 0x137A59: xenParseXLVnuma (xen_xl.c:442) ==30399== by 0x13952B: xenParseXL (xen_xl.c:1064) ==30399== by 0x11884D: testCompareFormatXML (xlconfigtest.c:152) ==30399== by 0x118A87: testCompareHelper (xlconfigtest.c:207) ==30399== by 0x119E36: virTestRun (testutils.c:180) ==30399== by 0x119186: mymain (xlconfigtest.c:274) ==30399== by 0x11BEE3: virTestMain (testutils.c:1119)
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/xenconfig/xen_xl.c | 2 ++ 1 file changed, 2 insertions(+)
Reviewed-by: John Ferlan <jferlan@redhat.com> John

==32171== 32 bytes in 1 blocks are definitely lost in loss record 44 of 107 ==32171== at 0x4C2DEF6: calloc (vg_replace_malloc.c:711) ==32171== by 0x55744A9: virAllocN (viralloc.c:191) ==32171== by 0x12CED2: xenMakeIPList (xen_common.c:1186) ==32171== by 0x12D0BE: xenFormatNet (xen_common.c:1221) ==32171== by 0x12F0D2: xenFormatVif (xen_common.c:1889) ==32171== by 0x12F2B4: xenFormatConfigCommon (xen_common.c:1944) ==32171== by 0x13BA32: xenFormatXL (xen_xl.c:1971) ==32171== by 0x1186CA: testCompareParseXML (xlconfigtest.c:105) ==32171== by 0x118A64: testCompareHelper (xlconfigtest.c:205) ==32171== by 0x119E36: virTestRun (testutils.c:180) ==32171== by 0x11970E: mymain (xlconfigtest.c:301) ==32171== by 0x11BEE3: virTestMain (testutils.c:1119) Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/xenconfig/xen_common.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index 40b148321..a815b3e0a 100644 --- a/src/xenconfig/xen_common.c +++ b/src/xenconfig/xen_common.c @@ -1198,6 +1198,7 @@ xenMakeIPList(virNetDevIPInfoPtr guestIP) cleanup: while (i > 0) VIR_FREE(address_array[--i]); + VIR_FREE(address_array); return ret; } -- 2.13.6

On 12/12/2017 09:10 AM, Michal Privoznik wrote:
==32171== 32 bytes in 1 blocks are definitely lost in loss record 44 of 107 ==32171== at 0x4C2DEF6: calloc (vg_replace_malloc.c:711) ==32171== by 0x55744A9: virAllocN (viralloc.c:191) ==32171== by 0x12CED2: xenMakeIPList (xen_common.c:1186) ==32171== by 0x12D0BE: xenFormatNet (xen_common.c:1221) ==32171== by 0x12F0D2: xenFormatVif (xen_common.c:1889) ==32171== by 0x12F2B4: xenFormatConfigCommon (xen_common.c:1944) ==32171== by 0x13BA32: xenFormatXL (xen_xl.c:1971) ==32171== by 0x1186CA: testCompareParseXML (xlconfigtest.c:105) ==32171== by 0x118A64: testCompareHelper (xlconfigtest.c:205) ==32171== by 0x119E36: virTestRun (testutils.c:180) ==32171== by 0x11970E: mymain (xlconfigtest.c:301) ==32171== by 0x11BEE3: virTestMain (testutils.c:1119)
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/xenconfig/xen_common.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index 40b148321..a815b3e0a 100644 --- a/src/xenconfig/xen_common.c +++ b/src/xenconfig/xen_common.c @@ -1198,6 +1198,7 @@ xenMakeIPList(virNetDevIPInfoPtr guestIP) cleanup: while (i > 0) VIR_FREE(address_array[--i]); + VIR_FREE(address_array);
How about virStringListFree instead, see: https://www.redhat.com/archives/libvir-list/2017-December/msg00349.html Reviewed-by: John Ferlan <jferlan@redhat.com> John
return ret; }

On 12/12/2017 03:31 PM, John Ferlan wrote:
On 12/12/2017 09:10 AM, Michal Privoznik wrote:
==32171== 32 bytes in 1 blocks are definitely lost in loss record 44 of 107 ==32171== at 0x4C2DEF6: calloc (vg_replace_malloc.c:711) ==32171== by 0x55744A9: virAllocN (viralloc.c:191) ==32171== by 0x12CED2: xenMakeIPList (xen_common.c:1186) ==32171== by 0x12D0BE: xenFormatNet (xen_common.c:1221) ==32171== by 0x12F0D2: xenFormatVif (xen_common.c:1889) ==32171== by 0x12F2B4: xenFormatConfigCommon (xen_common.c:1944) ==32171== by 0x13BA32: xenFormatXL (xen_xl.c:1971) ==32171== by 0x1186CA: testCompareParseXML (xlconfigtest.c:105) ==32171== by 0x118A64: testCompareHelper (xlconfigtest.c:205) ==32171== by 0x119E36: virTestRun (testutils.c:180) ==32171== by 0x11970E: mymain (xlconfigtest.c:301) ==32171== by 0x11BEE3: virTestMain (testutils.c:1119)
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/xenconfig/xen_common.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c index 40b148321..a815b3e0a 100644 --- a/src/xenconfig/xen_common.c +++ b/src/xenconfig/xen_common.c @@ -1198,6 +1198,7 @@ xenMakeIPList(virNetDevIPInfoPtr guestIP) cleanup: while (i > 0) VIR_FREE(address_array[--i]); + VIR_FREE(address_array);
How about virStringListFree instead, see:
Ah, good point. Fixed and pushed. Thanks. Michal

==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

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
participants (2)
-
John Ferlan
-
Michal Privoznik