提交 145de7b8 编写于 作者: D Daniel P. Berrange

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: NDaniel P. Berrange <berrange@redhat.com>
上级 94e6b94a
......@@ -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) {
......
......@@ -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)
{
......
......@@ -247,6 +247,8 @@ struct _qemuDomainCmdlineDef {
# define QEMUD_MIGRATION_NUM_PORTS 64
void qemuDomainCmdlineDefFree(qemuDomainCmdlineDefPtr def);
virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged);
int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册