mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 19:32:19 +00:00
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:
parent
6052f75de5
commit
5498aa29a7
@ -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,14 +3870,13 @@ 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);
|
||||
virDomainDefFree(persistDef);
|
||||
qemuMigrationCookieFree(mig);
|
||||
|
||||
if (events)
|
||||
@ -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);
|
||||
}
|
||||
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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user