Avoid leaking virDomainDef if Prepare phase fails before it gets to qemuMigrationPrepareAny. --- src/qemu/qemu_driver.c | 12 ++++-------- src/qemu/qemu_migration.c | 29 ++++++++++++++--------------- src/qemu/qemu_migration.h | 4 ++-- 3 files changed, 20 insertions(+), 25 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 3bad629..621e184 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -9552,8 +9552,7 @@ qemuDomainMigratePrepareTunnel(virConnectPtr dconn, ret = qemuMigrationPrepareTunnel(driver, dconn, NULL, 0, NULL, NULL, /* No cookies in v2 */ - st, def, flags); - def = NULL; + st, &def, flags); cleanup: virDomainDefFree(def); @@ -9628,8 +9627,7 @@ qemuDomainMigratePrepare2(virConnectPtr dconn, ret = qemuMigrationPrepareDirect(driver, dconn, NULL, 0, NULL, NULL, /* No cookies */ uri_in, uri_out, - def, flags); - def = NULL; + &def, flags); cleanup: virDomainDefFree(def); @@ -9864,8 +9862,7 @@ qemuDomainMigratePrepare3(virConnectPtr dconn, cookiein, cookieinlen, cookieout, cookieoutlen, uri_in, uri_out, - def, flags); - def = NULL; + &def, flags); cleanup: virDomainDefFree(def); @@ -9926,8 +9923,7 @@ qemuDomainMigratePrepareTunnel3(virConnectPtr dconn, ret = qemuMigrationPrepareTunnel(driver, dconn, cookiein, cookieinlen, cookieout, cookieoutlen, - st, def, flags); - def = NULL; + st, &def, flags); cleanup: virDomainDefFree(def); diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index dec04a5..0a54a30 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -2016,7 +2016,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver, int cookieinlen, char **cookieout, int *cookieoutlen, - virDomainDefPtr def, + virDomainDefPtr *def, virStreamPtr st, unsigned int port, unsigned long flags) @@ -2064,7 +2064,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver, if (!(caps = virQEMUDriverGetCapabilities(driver, false))) goto cleanup; - if (!qemuMigrationIsAllowed(driver, NULL, def, true)) + if (!qemuMigrationIsAllowed(driver, NULL, *def, true)) goto cleanup; /* Let migration hook filter domain XML */ @@ -2072,12 +2072,12 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver, char *xml; int hookret; - if (!(xml = qemuDomainDefFormatXML(driver, def, + if (!(xml = qemuDomainDefFormatXML(driver, *def, VIR_DOMAIN_XML_SECURE | VIR_DOMAIN_XML_MIGRATABLE))) goto cleanup; - hookret = virHookCall(VIR_HOOK_DRIVER_QEMU, def->name, + hookret = virHookCall(VIR_HOOK_DRIVER_QEMU, (*def)->name, VIR_HOOK_QEMU_OP_MIGRATE, VIR_HOOK_SUBOP_BEGIN, NULL, xml, &xmlout); VIR_FREE(xml); @@ -2098,13 +2098,13 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver, if (!newdef) goto cleanup; - if (!virDomainDefCheckABIStability(def, newdef)) { + if (!virDomainDefCheckABIStability(*def, newdef)) { virDomainDefFree(newdef); goto cleanup; } - virDomainDefFree(def); - def = newdef; + virDomainDefFree(*def); + *def = newdef; } } } @@ -2122,7 +2122,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver, .ai_socktype = SOCK_STREAM }; if (!(qemuCaps = virQEMUCapsCacheLookupCopy(driver->qemuCapsCache, - def->emulator))) + (*def)->emulator))) goto cleanup; /* Listen on :: instead of 0.0.0.0 if QEMU understands it @@ -2146,14 +2146,14 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver, } } - if (!(vm = virDomainObjListAdd(driver->domains, def, + if (!(vm = virDomainObjListAdd(driver->domains, *def, driver->xmlopt, VIR_DOMAIN_OBJ_LIST_ADD_LIVE | VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, NULL))) goto cleanup; - def = NULL; + *def = NULL; priv = vm->privateData; priv->origname = origname; origname = NULL; @@ -2272,7 +2272,6 @@ cleanup: VIR_FREE(migrateFrom); VIR_FREE(origname); VIR_FREE(xmlout); - virDomainDefFree(def); VIR_FORCE_CLOSE(dataFD[0]); VIR_FORCE_CLOSE(dataFD[1]); if (vm) { @@ -2315,7 +2314,7 @@ qemuMigrationPrepareTunnel(virQEMUDriverPtr driver, char **cookieout, int *cookieoutlen, virStreamPtr st, - virDomainDefPtr def, + virDomainDefPtr *def, unsigned long flags) { int ret; @@ -2324,7 +2323,7 @@ qemuMigrationPrepareTunnel(virQEMUDriverPtr driver, "cookieout=%p, cookieoutlen=%p, st=%p, def=%p, " "flags=%lx", driver, dconn, NULLSTR(cookiein), cookieinlen, - cookieout, cookieoutlen, st, def, flags); + cookieout, cookieoutlen, st, *def, flags); ret = qemuMigrationPrepareAny(driver, dconn, cookiein, cookieinlen, cookieout, cookieoutlen, def, @@ -2342,7 +2341,7 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver, int *cookieoutlen, const char *uri_in, char **uri_out, - virDomainDefPtr def, + virDomainDefPtr *def, unsigned long flags) { static int port = 0; @@ -2358,7 +2357,7 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver, "def=%p, flags=%lx", driver, dconn, NULLSTR(cookiein), cookieinlen, cookieout, cookieoutlen, NULLSTR(uri_in), uri_out, - def, flags); + *def, flags); /* The URI passed in may be NULL or a string "tcp://somehostname:port". * diff --git a/src/qemu/qemu_migration.h b/src/qemu/qemu_migration.h index b42fe4e..22b04b4 100644 --- a/src/qemu/qemu_migration.h +++ b/src/qemu/qemu_migration.h @@ -98,7 +98,7 @@ int qemuMigrationPrepareTunnel(virQEMUDriverPtr driver, char **cookieout, int *cookieoutlen, virStreamPtr st, - virDomainDefPtr def, + virDomainDefPtr *def, unsigned long flags); int qemuMigrationPrepareDirect(virQEMUDriverPtr driver, @@ -109,7 +109,7 @@ int qemuMigrationPrepareDirect(virQEMUDriverPtr driver, int *cookieoutlen, const char *uri_in, char **uri_out, - virDomainDefPtr def, + virDomainDefPtr *def, unsigned long flags); int qemuMigrationPerform(virQEMUDriverPtr driver, -- 1.8.2.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list