From: Michal Privoznik <[email protected]> When building OS loader part of bhyve command line, there's @buf declared and it is even correctly annotated with g_auto() to be freed automatically. But then, the buffer contents is appended onto the command line using virBufferContentAndReset() which leads to a memleak because the buffer is reset. It's virBufferCurrentContent() that should have been used instead.
128 bytes in 1 blocks are definitely lost in loss record 476 of 536 at 0x48882B1: realloc (vg_replace_malloc.c:1810) by 0x4EE6622: g_realloc (in /usr/local/lib/libglib-2.0.so.0.8400.4) by 0x4F048BC: g_string_new (in /usr/local/lib/libglib-2.0.so.0.8400.4) by 0x4A59E1E: virBufferInitialize (virbuffer.c:121) by 0x4A5A63C: virBufferVasprintf (virbuffer.c:321) by 0x4A5A5DE: virBufferAsprintf (virbuffer.c:303) by 0x401B22F: virBhyveProcessBuildBhyveCmd (bhyve_command.c:1021) by 0x4015F05: testCompareXMLToArgvFiles (bhyvexml2argvtest.c:72) by 0x4015BA9: testCompareXMLToArgvHelper (bhyvexml2argvtest.c:144) by 0x4016588: virTestRun (testutils.c:143) by 0x4015919: mymain (bhyvexml2argvtest.c:341) by 0x4018882: virTestMain (testutils.c:913) Signed-off-by: Michal Privoznik <[email protected]> --- src/bhyve/bhyve_command.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c index a45a5d1c33..c9bfe22c8c 100644 --- a/src/bhyve/bhyve_command.c +++ b/src/bhyve/bhyve_command.c @@ -1003,7 +1003,7 @@ virBhyveProcessBuildBhyveCmd(struct _bhyveConn *driver, virDomainDef *def, if (def->os.bootloader == NULL && def->os.loader) { virArch arch = def->os.arch; - g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; if (ARCH_IS_X86(arch)) { if ((bhyveDriverGetBhyveCaps(driver) & BHYVE_CAP_LPC_BOOTROM)) { @@ -1011,7 +1011,7 @@ virBhyveProcessBuildBhyveCmd(struct _bhyveConn *driver, virDomainDef *def, if (def->os.loader->nvram && def->os.loader->nvram->path) virBufferAsprintf(&buf, ",%s", def->os.loader->nvram->path); - virCommandAddArgList(cmd, "-l", virBufferContentAndReset(&buf), NULL); + virCommandAddArgList(cmd, "-l", virBufferCurrentContent(&buf), NULL); } else { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Installed bhyve binary does not support UEFI loader")); @@ -1019,7 +1019,7 @@ virBhyveProcessBuildBhyveCmd(struct _bhyveConn *driver, virDomainDef *def, } } else if (ARCH_IS_ARM(arch)) { virBufferAsprintf(&buf, "bootrom=%s", def->os.loader->path); - virCommandAddArgList(cmd, "-o", virBufferContentAndReset(&buf), NULL); + virCommandAddArgList(cmd, "-o", virBufferCurrentContent(&buf), NULL); } } -- 2.52.0
