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: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
Jiri Denemark 2017-03-21 11:04:16 +01:00
parent 6052f75de5
commit 5498aa29a7
3 changed files with 14 additions and 14 deletions

View File

@ -3617,11 +3617,13 @@ qemuMigrationRun(virQEMUDriverPtr driver,
if (persist_xml) { if (persist_xml) {
persistDef = qemuMigrationPrepareDef(driver, persist_xml, persistDef = qemuMigrationPrepareDef(driver, persist_xml,
NULL, NULL); NULL, NULL);
} else {
persistDef = qemuDomainDefCopy(driver, vm->newDef,
VIR_DOMAIN_XML_SECURE |
VIR_DOMAIN_XML_MIGRATABLE);
}
if (!persistDef) if (!persistDef)
goto cleanup; goto cleanup;
} else {
persistDef = vm->newDef;
}
} }
mig = qemuMigrationEatCookie(driver, vm, cookiein, cookieinlen, mig = qemuMigrationEatCookie(driver, vm, cookiein, cookieinlen,
@ -3868,13 +3870,12 @@ qemuMigrationRun(virQEMUDriverPtr driver,
QEMU_MIGRATION_COOKIE_STATS; QEMU_MIGRATION_COOKIE_STATS;
if (ret == 0 && if (ret == 0 &&
(qemuMigrationCookieAddPersistent(mig, persistDef) < 0 || (qemuMigrationCookieAddPersistent(mig, &persistDef) < 0 ||
qemuMigrationBakeCookie(mig, driver, vm, cookieout, qemuMigrationBakeCookie(mig, driver, vm, cookieout,
cookieoutlen, cookieFlags) < 0)) { cookieoutlen, cookieFlags) < 0)) {
VIR_WARN("Unable to encode migration cookie"); VIR_WARN("Unable to encode migration cookie");
} }
if (persistDef != vm->newDef)
virDomainDefFree(persistDef); virDomainDefFree(persistDef);
qemuMigrationCookieFree(mig); qemuMigrationCookieFree(mig);
@ -5365,10 +5366,7 @@ qemuMigrationFinish(virQEMUDriverPtr driver,
qemuMonitorSetDomainLog(priv->mon, NULL, NULL, NULL); qemuMonitorSetDomainLog(priv->mon, NULL, NULL, NULL);
VIR_FREE(priv->origname); VIR_FREE(priv->origname);
virDomainObjEndAPI(&vm); virDomainObjEndAPI(&vm);
if (mig) {
virDomainDefFree(qemuMigrationCookieGetPersistent(mig));
qemuMigrationCookieFree(mig); qemuMigrationCookieFree(mig);
}
if (orig_err) { if (orig_err) {
virSetError(orig_err); virSetError(orig_err);
virFreeError(orig_err); virFreeError(orig_err);

View File

@ -99,6 +99,7 @@ qemuMigrationCookieFree(qemuMigrationCookiePtr mig)
return; return;
qemuMigrationCookieGraphicsFree(mig->graphics); qemuMigrationCookieGraphicsFree(mig->graphics);
virDomainDefFree(mig->persistent);
qemuMigrationCookieNetworkFree(mig->network); qemuMigrationCookieNetworkFree(mig->network);
qemuMigrationCookieNBDFree(mig->nbd); qemuMigrationCookieNBDFree(mig->nbd);
@ -385,7 +386,7 @@ qemuMigrationCookieAddLockstate(qemuMigrationCookiePtr mig,
int int
qemuMigrationCookieAddPersistent(qemuMigrationCookiePtr mig, qemuMigrationCookieAddPersistent(qemuMigrationCookiePtr mig,
virDomainDefPtr def) virDomainDefPtr *def)
{ {
if (mig->flags & QEMU_MIGRATION_COOKIE_PERSISTENT) { if (mig->flags & QEMU_MIGRATION_COOKIE_PERSISTENT) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@ -393,10 +394,11 @@ qemuMigrationCookieAddPersistent(qemuMigrationCookiePtr mig,
return -1; return -1;
} }
if (!def) if (!def || !*def)
return 0; return 0;
mig->persistent = def; mig->persistent = *def;
*def = NULL;
mig->flags |= QEMU_MIGRATION_COOKIE_PERSISTENT; mig->flags |= QEMU_MIGRATION_COOKIE_PERSISTENT;
mig->flagsMandatory |= QEMU_MIGRATION_COOKIE_PERSISTENT; mig->flagsMandatory |= QEMU_MIGRATION_COOKIE_PERSISTENT;
return 0; return 0;

View File

@ -145,7 +145,7 @@ qemuMigrationCookieFree(qemuMigrationCookiePtr mig);
int int
qemuMigrationCookieAddPersistent(qemuMigrationCookiePtr mig, qemuMigrationCookieAddPersistent(qemuMigrationCookiePtr mig,
virDomainDefPtr def); virDomainDefPtr *def);
virDomainDefPtr virDomainDefPtr
qemuMigrationCookieGetPersistent(qemuMigrationCookiePtr mig); qemuMigrationCookieGetPersistent(qemuMigrationCookiePtr mig);