From: Hongbin Lu Date: Tue, 16 Sep 2014 02:22:48 +0000 (-0400) Subject: openvz: fixed two memory leaks on migration code X-Git-Tag: CVE-2014-3633~30 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e3c626a61d6c3d808555653684c0fb1e7c4d74ec;p=thirdparty%2Flibvirt.git openvz: fixed two memory leaks on migration code The first one occurs in openvzDomainMigratePrepare3Params() where in case no remote uri is given, the distant hostname is used. The name is obtained via virGetHostname() which require callers to free the returned value. The second leak lies in openvzDomainMigratePerform3Params(). There's a virCommand used later. However, at the beginning of the function virCheckFlags() is called which returns. So the command created was leaked. Signed-off-by: Michal Privoznik --- diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 57b3c22156..6c73eaf264 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -2286,7 +2286,8 @@ openvzDomainMigratePrepare3Params(virConnectPtr dconn, const char *uri_in = NULL; virDomainDefPtr def = NULL; virDomainObjPtr vm = NULL; - char *hostname = NULL; + char *my_hostname = NULL; + const char *hostname = NULL; virURIPtr uri = NULL; int ret = -1; @@ -2321,10 +2322,10 @@ openvzDomainMigratePrepare3Params(virConnectPtr dconn, def = NULL; if (!uri_in) { - if ((hostname = virGetHostname()) == NULL) + if ((my_hostname = virGetHostname()) == NULL) goto error; - if (STRPREFIX(hostname, "localhost")) { + if (STRPREFIX(my_hostname, "localhost")) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("hostname on destination resolved to localhost," " but migration requires an FQDN")); @@ -2364,6 +2365,7 @@ openvzDomainMigratePrepare3Params(virConnectPtr dconn, } done: + VIR_FREE(my_hostname); virURIFree(uri); if (vm) virObjectUnlock(vm); @@ -2385,7 +2387,7 @@ openvzDomainMigratePerform3Params(virDomainPtr domain, virDomainObjPtr vm = NULL; const char *uri_str = NULL; virURIPtr uri = NULL; - virCommandPtr cmd = virCommandNew(VZMIGRATE); + virCommandPtr cmd = NULL; int ret = -1; virCheckFlags(OPENVZ_MIGRATION_FLAGS, -1); @@ -2412,6 +2414,7 @@ openvzDomainMigratePerform3Params(virDomainPtr domain, if (uri == NULL || uri->server == NULL) goto cleanup; + cmd = virCommandNew(VZMIGRATE); if (flags & VIR_MIGRATE_LIVE) virCommandAddArg(cmd, "--live"); virCommandAddArg(cmd, uri->server);