1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-23 21:34:54 +03:00

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 <mprivozn@redhat.com>
This commit is contained in:
Hongbin Lu 2014-09-15 22:22:48 -04:00 committed by Michal Privoznik
parent 735a15a6b5
commit e3c626a61d

View File

@ -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);