From: "Daniel P. Berrange" <berrange(a)redhat.com>
If qemuParseCommandLine finds an arg it does not understand
it adds it to the QEMU passthrough custom arg list. If the
qemuParseCommandLine method hits an error for any reason
though, it just does 'VIR_FREE(cmd)' on the custom arg list.
This means all actual args / env vars are leaked. Introduce
a qemuDomainCmdlineDefFree method to be used for cleanup.
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
src/qemu/qemu_command.c | 4 ++--
src/qemu/qemu_conf.c | 18 ++++++++++++++++++
src/qemu/qemu_conf.h | 2 ++
src/qemu/qemu_domain.c | 15 +--------------
4 files changed, 23 insertions(+), 16 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index a8b9a74..724e1d4 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -11868,13 +11868,13 @@ qemuParseCommandLine(virCapsPtr qemuCaps,
def->namespaceData = cmd;
}
else
- VIR_FREE(cmd);
+ qemuDomainCmdlineDefFree(cmd);
return def;
error:
virDomainDiskDefFree(disk);
- VIR_FREE(cmd);
+ qemuDomainCmdlineDefFree(cmd);
virDomainDefFree(def);
VIR_FREE(nics);
if (monConfig) {
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 1f57f72..1a41caf 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -87,6 +87,24 @@ qemuDriverUnlock(virQEMUDriverPtr driver)
virMutexUnlock(&driver->lock);
}
+void qemuDomainCmdlineDefFree(qemuDomainCmdlineDefPtr def)
+{
+ size_t i;
+
+ if (!def)
+ return;
+
+ for (i = 0; i < def->num_args; i++)
+ VIR_FREE(def->args[i]);
+ for (i = 0; i < def->num_env; i++) {
+ VIR_FREE(def->env_name[i]);
+ VIR_FREE(def->env_value[i]);
+ }
+ VIR_FREE(def->args);
+ VIR_FREE(def->env_name);
+ VIR_FREE(def->env_value);
+ VIR_FREE(def);
+}
virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged)
{
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index 206f2c6..da29a2a 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -247,6 +247,8 @@ struct _qemuDomainCmdlineDef {
# define QEMUD_MIGRATION_NUM_PORTS 64
+void qemuDomainCmdlineDefFree(qemuDomainCmdlineDefPtr def);
+
virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged);
int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index f2cca70..968e323 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -535,21 +535,8 @@ static void
qemuDomainDefNamespaceFree(void *nsdata)
{
qemuDomainCmdlineDefPtr cmd = nsdata;
- size_t i;
-
- if (!cmd)
- return;
- for (i = 0; i < cmd->num_args; i++)
- VIR_FREE(cmd->args[i]);
- for (i = 0; i < cmd->num_env; i++) {
- VIR_FREE(cmd->env_name[i]);
- VIR_FREE(cmd->env_value[i]);
- }
- VIR_FREE(cmd->args);
- VIR_FREE(cmd->env_name);
- VIR_FREE(cmd->env_value);
- VIR_FREE(cmd);
+ qemuDomainCmdlineDefFree(cmd);
}
static int
--
1.8.3.1