[PATCH 1/3] bhyve: fix memory leak in bhyveBuildVirtioSerialControllerArgStr()

Roman Bogorodskiy posted 3 patches 1 month, 2 weeks ago
[PATCH 1/3] bhyve: fix memory leak in bhyveBuildVirtioSerialControllerArgStr()
Posted by Roman Bogorodskiy 1 month, 2 weeks ago
We cannot use virBufferContentAndReset() right in
virCommandAddArgFormat() as we need to free the result.

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
---
 src/bhyve/bhyve_command.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c
index 941b48eb66..a4f9c8823b 100644
--- a/src/bhyve/bhyve_command.c
+++ b/src/bhyve/bhyve_command.c
@@ -518,10 +518,12 @@ bhyveBuildVirtioSerialControllerArgStr(const virDomainDef *def,
     }
 
     if (virBufferUse(&opt) > 0) {
+        g_autofree char *console_opt = virBufferContentAndReset(&opt);
+
         virCommandAddArg(cmd, "-s");
         virCommandAddArgFormat(cmd, "%d:0,virtio-console%s",
                                controller->info.addr.pci.slot,
-                               virBufferContentAndReset(&opt));
+                               console_opt);
     }
 
     return 0;
-- 
2.52.0