[libvirt] [PATCH] qemu_command: Fix memleak in qemuBuildFloppyCommandLineControllerOptions

Michal Privoznik posted 1 patch 5 years, 8 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/7e6903171033293d4188f871a3935600bfc9e845.1534414944.git.mprivozn@redhat.com
Test syntax-check passed
src/qemu/qemu_command.c | 1 +
1 file changed, 1 insertion(+)
[libvirt] [PATCH] qemu_command: Fix memleak in qemuBuildFloppyCommandLineControllerOptions
Posted by Michal Privoznik 5 years, 8 months ago
Even though the buffer is passed to virCommand we still need to
free it.

==191201== 1,010 bytes in 1 blocks are definitely lost in loss record 826 of 836
==191201==    at 0x4C2CE3F: malloc (vg_replace_malloc.c:298)
==191201==    by 0x4C2F1BF: realloc (vg_replace_malloc.c:785)
==191201==    by 0x5D39E82: virReallocN (viralloc.c:245)
==191201==    by 0x5D3E8F2: virBufferGrow (virbuffer.c:150)
==191201==    by 0x5D3E9C8: virBufferAdd (virbuffer.c:185)
==191201==    by 0x56EAC98: qemuBuildFloppyCommandLineControllerOptions (qemu_command.c:2162)
==191201==    by 0x56EB3E1: qemuBuildDisksCommandLine (qemu_command.c:2370)
==191201==    by 0x570055E: qemuBuildCommandLine (qemu_command.c:10315)
==191201==    by 0x575EA7F: qemuProcessCreatePretendCmd (qemu_process.c:6777)
==191201==    by 0x113DAB: testCompareXMLToArgv (qemuxml2argvtest.c:598)
==191201==    by 0x13A75B: virTestRun (testutils.c:180)
==191201==    by 0x138BE8: mymain (qemuxml2argvtest.c:2975)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_command.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index ddb90895e0..96fc360f4a 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2225,6 +2225,7 @@ qemuBuildFloppyCommandLineControllerOptions(virCommandPtr cmd,
     VIR_FREE(backendAlias);
     VIR_FREE(backendStr);
     VIR_FREE(bootindexStr);
+    virBufferFreeAndReset(&fdc_opts);
     return ret;
 }
 
-- 
2.16.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemu_command: Fix memleak in qemuBuildFloppyCommandLineControllerOptions
Posted by Peter Krempa 5 years, 8 months ago
On Thu, Aug 16, 2018 at 12:22:24 +0200, Michal Privoznik wrote:
> Even though the buffer is passed to virCommand we still need to
> free it.

This is misleading. In fact we are NOT passing it to virCommandAddArgBuffer
in some cases as it would be properly freed in that case.

> ==191201== 1,010 bytes in 1 blocks are definitely lost in loss record 826 of 836
> ==191201==    at 0x4C2CE3F: malloc (vg_replace_malloc.c:298)
> ==191201==    by 0x4C2F1BF: realloc (vg_replace_malloc.c:785)
> ==191201==    by 0x5D39E82: virReallocN (viralloc.c:245)
> ==191201==    by 0x5D3E8F2: virBufferGrow (virbuffer.c:150)
> ==191201==    by 0x5D3E9C8: virBufferAdd (virbuffer.c:185)
> ==191201==    by 0x56EAC98: qemuBuildFloppyCommandLineControllerOptions (qemu_command.c:2162)
> ==191201==    by 0x56EB3E1: qemuBuildDisksCommandLine (qemu_command.c:2370)
> ==191201==    by 0x570055E: qemuBuildCommandLine (qemu_command.c:10315)
> ==191201==    by 0x575EA7F: qemuProcessCreatePretendCmd (qemu_process.c:6777)
> ==191201==    by 0x113DAB: testCompareXMLToArgv (qemuxml2argvtest.c:598)
> ==191201==    by 0x13A75B: virTestRun (testutils.c:180)
> ==191201==    by 0x138BE8: mymain (qemuxml2argvtest.c:2975)
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  src/qemu/qemu_command.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
> index ddb90895e0..96fc360f4a 100644
> --- a/src/qemu/qemu_command.c
> +++ b/src/qemu/qemu_command.c
> @@ -2225,6 +2225,7 @@ qemuBuildFloppyCommandLineControllerOptions(virCommandPtr cmd,
>      VIR_FREE(backendAlias);
>      VIR_FREE(backendStr);
>      VIR_FREE(bootindexStr);
> +    virBufferFreeAndReset(&fdc_opts);
>      return ret;

ACK if you fix the commit message
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemu_command: Fix memleak in qemuBuildFloppyCommandLineControllerOptions
Posted by Erik Skultety 5 years, 8 months ago
On Thu, Aug 16, 2018 at 12:22:24PM +0200, Michal Privoznik wrote:
> Even though the buffer is passed to virCommand we still need to
> free it.
>
> ==191201== 1,010 bytes in 1 blocks are definitely lost in loss record 826 of 836
> ==191201==    at 0x4C2CE3F: malloc (vg_replace_malloc.c:298)
> ==191201==    by 0x4C2F1BF: realloc (vg_replace_malloc.c:785)
> ==191201==    by 0x5D39E82: virReallocN (viralloc.c:245)
> ==191201==    by 0x5D3E8F2: virBufferGrow (virbuffer.c:150)
> ==191201==    by 0x5D3E9C8: virBufferAdd (virbuffer.c:185)
> ==191201==    by 0x56EAC98: qemuBuildFloppyCommandLineControllerOptions (qemu_command.c:2162)
> ==191201==    by 0x56EB3E1: qemuBuildDisksCommandLine (qemu_command.c:2370)
> ==191201==    by 0x570055E: qemuBuildCommandLine (qemu_command.c:10315)
> ==191201==    by 0x575EA7F: qemuProcessCreatePretendCmd (qemu_process.c:6777)
> ==191201==    by 0x113DAB: testCompareXMLToArgv (qemuxml2argvtest.c:598)
> ==191201==    by 0x13A75B: virTestRun (testutils.c:180)
> ==191201==    by 0x138BE8: mymain (qemuxml2argvtest.c:2975)
>
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---

Reviewed-by: Erik Skultety <eskultet@redhat.com>

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