qemu: Fix memory leak in Prepare phase

Avoid leaking virDomainDef if Prepare phase fails before it gets to
qemuMigrationPrepareAny.
This commit is contained in:
Jiri Denemark 2013-06-07 14:12:28 +02:00
parent 0b466db29b
commit 9313a6a7fc
3 changed files with 20 additions and 25 deletions

View File

@ -9707,8 +9707,7 @@ qemuDomainMigratePrepareTunnel(virConnectPtr dconn,
ret = qemuMigrationPrepareTunnel(driver, dconn, ret = qemuMigrationPrepareTunnel(driver, dconn,
NULL, 0, NULL, NULL, /* No cookies in v2 */ NULL, 0, NULL, NULL, /* No cookies in v2 */
st, def, flags); st, &def, flags);
def = NULL;
cleanup: cleanup:
virDomainDefFree(def); virDomainDefFree(def);
@ -9783,8 +9782,7 @@ qemuDomainMigratePrepare2(virConnectPtr dconn,
ret = qemuMigrationPrepareDirect(driver, dconn, ret = qemuMigrationPrepareDirect(driver, dconn,
NULL, 0, NULL, NULL, /* No cookies */ NULL, 0, NULL, NULL, /* No cookies */
uri_in, uri_out, uri_in, uri_out,
def, flags); &def, flags);
def = NULL;
cleanup: cleanup:
virDomainDefFree(def); virDomainDefFree(def);
@ -10019,8 +10017,7 @@ qemuDomainMigratePrepare3(virConnectPtr dconn,
cookiein, cookieinlen, cookiein, cookieinlen,
cookieout, cookieoutlen, cookieout, cookieoutlen,
uri_in, uri_out, uri_in, uri_out,
def, flags); &def, flags);
def = NULL;
cleanup: cleanup:
virDomainDefFree(def); virDomainDefFree(def);
@ -10081,8 +10078,7 @@ qemuDomainMigratePrepareTunnel3(virConnectPtr dconn,
ret = qemuMigrationPrepareTunnel(driver, dconn, ret = qemuMigrationPrepareTunnel(driver, dconn,
cookiein, cookieinlen, cookiein, cookieinlen,
cookieout, cookieoutlen, cookieout, cookieoutlen,
st, def, flags); st, &def, flags);
def = NULL;
cleanup: cleanup:
virDomainDefFree(def); virDomainDefFree(def);

View File

@ -2002,7 +2002,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
int cookieinlen, int cookieinlen,
char **cookieout, char **cookieout,
int *cookieoutlen, int *cookieoutlen,
virDomainDefPtr def, virDomainDefPtr *def,
virStreamPtr st, virStreamPtr st,
unsigned int port, unsigned int port,
unsigned long flags) unsigned long flags)
@ -2050,7 +2050,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
if (!(caps = virQEMUDriverGetCapabilities(driver, false))) if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
goto cleanup; goto cleanup;
if (!qemuMigrationIsAllowed(driver, NULL, def, true)) if (!qemuMigrationIsAllowed(driver, NULL, *def, true))
goto cleanup; goto cleanup;
/* Let migration hook filter domain XML */ /* Let migration hook filter domain XML */
@ -2058,12 +2058,12 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
char *xml; char *xml;
int hookret; int hookret;
if (!(xml = qemuDomainDefFormatXML(driver, def, if (!(xml = qemuDomainDefFormatXML(driver, *def,
VIR_DOMAIN_XML_SECURE | VIR_DOMAIN_XML_SECURE |
VIR_DOMAIN_XML_MIGRATABLE))) VIR_DOMAIN_XML_MIGRATABLE)))
goto cleanup; 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, VIR_HOOK_QEMU_OP_MIGRATE, VIR_HOOK_SUBOP_BEGIN,
NULL, xml, &xmlout); NULL, xml, &xmlout);
VIR_FREE(xml); VIR_FREE(xml);
@ -2084,13 +2084,13 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
if (!newdef) if (!newdef)
goto cleanup; goto cleanup;
if (!virDomainDefCheckABIStability(def, newdef)) { if (!virDomainDefCheckABIStability(*def, newdef)) {
virDomainDefFree(newdef); virDomainDefFree(newdef);
goto cleanup; goto cleanup;
} }
virDomainDefFree(def); virDomainDefFree(*def);
def = newdef; *def = newdef;
} }
} }
} }
@ -2108,7 +2108,7 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
.ai_socktype = SOCK_STREAM }; .ai_socktype = SOCK_STREAM };
if (!(qemuCaps = virQEMUCapsCacheLookupCopy(driver->qemuCapsCache, if (!(qemuCaps = virQEMUCapsCacheLookupCopy(driver->qemuCapsCache,
def->emulator))) (*def)->emulator)))
goto cleanup; goto cleanup;
/* Listen on :: instead of 0.0.0.0 if QEMU understands it /* Listen on :: instead of 0.0.0.0 if QEMU understands it
@ -2132,14 +2132,14 @@ qemuMigrationPrepareAny(virQEMUDriverPtr driver,
} }
} }
if (!(vm = virDomainObjListAdd(driver->domains, def, if (!(vm = virDomainObjListAdd(driver->domains, *def,
driver->xmlopt, driver->xmlopt,
VIR_DOMAIN_OBJ_LIST_ADD_LIVE | VIR_DOMAIN_OBJ_LIST_ADD_LIVE |
VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE, VIR_DOMAIN_OBJ_LIST_ADD_CHECK_LIVE,
NULL))) NULL)))
goto cleanup; goto cleanup;
def = NULL; *def = NULL;
priv = vm->privateData; priv = vm->privateData;
priv->origname = origname; priv->origname = origname;
origname = NULL; origname = NULL;
@ -2258,7 +2258,6 @@ cleanup:
VIR_FREE(migrateFrom); VIR_FREE(migrateFrom);
VIR_FREE(origname); VIR_FREE(origname);
VIR_FREE(xmlout); VIR_FREE(xmlout);
virDomainDefFree(def);
VIR_FORCE_CLOSE(dataFD[0]); VIR_FORCE_CLOSE(dataFD[0]);
VIR_FORCE_CLOSE(dataFD[1]); VIR_FORCE_CLOSE(dataFD[1]);
if (vm) { if (vm) {
@ -2301,7 +2300,7 @@ qemuMigrationPrepareTunnel(virQEMUDriverPtr driver,
char **cookieout, char **cookieout,
int *cookieoutlen, int *cookieoutlen,
virStreamPtr st, virStreamPtr st,
virDomainDefPtr def, virDomainDefPtr *def,
unsigned long flags) unsigned long flags)
{ {
int ret; int ret;
@ -2310,7 +2309,7 @@ qemuMigrationPrepareTunnel(virQEMUDriverPtr driver,
"cookieout=%p, cookieoutlen=%p, st=%p, def=%p, " "cookieout=%p, cookieoutlen=%p, st=%p, def=%p, "
"flags=%lx", "flags=%lx",
driver, dconn, NULLSTR(cookiein), cookieinlen, driver, dconn, NULLSTR(cookiein), cookieinlen,
cookieout, cookieoutlen, st, def, flags); cookieout, cookieoutlen, st, *def, flags);
ret = qemuMigrationPrepareAny(driver, dconn, cookiein, cookieinlen, ret = qemuMigrationPrepareAny(driver, dconn, cookiein, cookieinlen,
cookieout, cookieoutlen, def, cookieout, cookieoutlen, def,
@ -2328,7 +2327,7 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
int *cookieoutlen, int *cookieoutlen,
const char *uri_in, const char *uri_in,
char **uri_out, char **uri_out,
virDomainDefPtr def, virDomainDefPtr *def,
unsigned long flags) unsigned long flags)
{ {
static int port = 0; static int port = 0;
@ -2344,7 +2343,7 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
"def=%p, flags=%lx", "def=%p, flags=%lx",
driver, dconn, NULLSTR(cookiein), cookieinlen, driver, dconn, NULLSTR(cookiein), cookieinlen,
cookieout, cookieoutlen, NULLSTR(uri_in), uri_out, cookieout, cookieoutlen, NULLSTR(uri_in), uri_out,
def, flags); *def, flags);
/* The URI passed in may be NULL or a string "tcp://somehostname:port". /* The URI passed in may be NULL or a string "tcp://somehostname:port".
* *

View File

@ -98,7 +98,7 @@ int qemuMigrationPrepareTunnel(virQEMUDriverPtr driver,
char **cookieout, char **cookieout,
int *cookieoutlen, int *cookieoutlen,
virStreamPtr st, virStreamPtr st,
virDomainDefPtr def, virDomainDefPtr *def,
unsigned long flags); unsigned long flags);
int qemuMigrationPrepareDirect(virQEMUDriverPtr driver, int qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
@ -109,7 +109,7 @@ int qemuMigrationPrepareDirect(virQEMUDriverPtr driver,
int *cookieoutlen, int *cookieoutlen,
const char *uri_in, const char *uri_in,
char **uri_out, char **uri_out,
virDomainDefPtr def, virDomainDefPtr *def,
unsigned long flags); unsigned long flags);
int qemuMigrationPerform(virQEMUDriverPtr driver, int qemuMigrationPerform(virQEMUDriverPtr driver,