提交 5498aa29 编写于 作者: J Jiri Denemark

qemu: Free persistent def inside qemuMigrationCookieFree

Creating a copy of the definition we want to add in a migration cookie
makes the code cleaner and less prone to memory leaks or double free
errors.
Signed-off-by: NJiri Denemark <jdenemar@redhat.com>
上级 6052f75d
......@@ -3617,11 +3617,13 @@ qemuMigrationRun(virQEMUDriverPtr driver,
if (persist_xml) {
persistDef = qemuMigrationPrepareDef(driver, persist_xml,
NULL, NULL);
if (!persistDef)
goto cleanup;
} else {
persistDef = vm->newDef;
persistDef = qemuDomainDefCopy(driver, vm->newDef,
VIR_DOMAIN_XML_SECURE |
VIR_DOMAIN_XML_MIGRATABLE);
}
if (!persistDef)
goto cleanup;
}
mig = qemuMigrationEatCookie(driver, vm, cookiein, cookieinlen,
......@@ -3868,13 +3870,12 @@ qemuMigrationRun(virQEMUDriverPtr driver,
QEMU_MIGRATION_COOKIE_STATS;
if (ret == 0 &&
(qemuMigrationCookieAddPersistent(mig, persistDef) < 0 ||
(qemuMigrationCookieAddPersistent(mig, &persistDef) < 0 ||
qemuMigrationBakeCookie(mig, driver, vm, cookieout,
cookieoutlen, cookieFlags) < 0)) {
VIR_WARN("Unable to encode migration cookie");
}
if (persistDef != vm->newDef)
virDomainDefFree(persistDef);
qemuMigrationCookieFree(mig);
......@@ -5365,10 +5366,7 @@ qemuMigrationFinish(virQEMUDriverPtr driver,
qemuMonitorSetDomainLog(priv->mon, NULL, NULL, NULL);
VIR_FREE(priv->origname);
virDomainObjEndAPI(&vm);
if (mig) {
virDomainDefFree(qemuMigrationCookieGetPersistent(mig));
qemuMigrationCookieFree(mig);
}
if (orig_err) {
virSetError(orig_err);
virFreeError(orig_err);
......
......@@ -99,6 +99,7 @@ qemuMigrationCookieFree(qemuMigrationCookiePtr mig)
return;
qemuMigrationCookieGraphicsFree(mig->graphics);
virDomainDefFree(mig->persistent);
qemuMigrationCookieNetworkFree(mig->network);
qemuMigrationCookieNBDFree(mig->nbd);
......@@ -385,7 +386,7 @@ qemuMigrationCookieAddLockstate(qemuMigrationCookiePtr mig,
int
qemuMigrationCookieAddPersistent(qemuMigrationCookiePtr mig,
virDomainDefPtr def)
virDomainDefPtr *def)
{
if (mig->flags & QEMU_MIGRATION_COOKIE_PERSISTENT) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
......@@ -393,10 +394,11 @@ qemuMigrationCookieAddPersistent(qemuMigrationCookiePtr mig,
return -1;
}
if (!def)
if (!def || !*def)
return 0;
mig->persistent = def;
mig->persistent = *def;
*def = NULL;
mig->flags |= QEMU_MIGRATION_COOKIE_PERSISTENT;
mig->flagsMandatory |= QEMU_MIGRATION_COOKIE_PERSISTENT;
return 0;
......
......@@ -145,7 +145,7 @@ qemuMigrationCookieFree(qemuMigrationCookiePtr mig);
int
qemuMigrationCookieAddPersistent(qemuMigrationCookiePtr mig,
virDomainDefPtr def);
virDomainDefPtr *def);
virDomainDefPtr
qemuMigrationCookieGetPersistent(qemuMigrationCookiePtr mig);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册