From 145de7b8f3069152f7228462612c4964515db7b9 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Tue, 24 Sep 2013 16:38:26 +0100 Subject: [PATCH] Fix leak of command line args in qemuParseCommandLine 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 --- 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 1f9a999760..ba102f4174 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -11963,13 +11963,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 1f57f7280d..1a41caf93f 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 206f2c6140..da29a2aa2a 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 f2cca70e32..968e323210 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 -- GitLab