From: Jim Fehlig Date: Fri, 14 Oct 2016 17:55:52 +0000 (-0600) Subject: libxl: fix leaking of allocated migration ports X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=f830674bf320522f50a09759fbc568c9f2f436f1;p=libvirt.git libxl: fix leaking of allocated migration ports Although the migration port is immediately released in the finish phase of migration, it was never set in the domain private object when allocated in the prepare phase. So libxlDomainMigrationFinish() always released a 0-initialized migrationPort, leaking any allocated port. After enough migrations to exhaust the migration port pool, migration would fail with error: internal error: Unable to find an unused port in range 'migration' (49152-49216) Fix it by setting libxlDomainObjPrivate->migrationPort to the port allocated in the prepare phase. While at it, also fix leaking an allocated port if the prepare phase fails. --- diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c index 534abb8704..a471d2aa11 100644 --- a/src/libxl/libxl_migration.c +++ b/src/libxl/libxl_migration.c @@ -594,6 +594,7 @@ libxlDomainMigrationPrepare(virConnectPtr dconn, if (virPortAllocatorAcquire(driver->migrationPorts, &port) < 0) goto error; + priv->migrationPort = port; if (virAsprintf(uri_out, "tcp://%s:%d", hostname, port) < 0) goto error; } else { @@ -628,6 +629,7 @@ libxlDomainMigrationPrepare(virConnectPtr dconn, if (virPortAllocatorAcquire(driver->migrationPorts, &port) < 0) goto error; + priv->migrationPort = port; } else { port = uri->port; } @@ -690,6 +692,8 @@ libxlDomainMigrationPrepare(virConnectPtr dconn, } VIR_FREE(socks); virObjectUnref(args); + virPortAllocatorRelease(driver->migrationPorts, priv->migrationPort); + priv->migrationPort = 0; /* Remove virDomainObj from domain list */ if (vm) {