From: Tobias Brunner Date: Tue, 11 Nov 2014 17:50:26 +0000 (+0100) Subject: mem-pool: Fix potential memory leak and lost leases when reassigning leases X-Git-Tag: 5.2.2dr1~36 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8ab1b29da4c51bf92df0030f3a17df0ceee1ea06;p=thirdparty%2Fstrongswan.git mem-pool: Fix potential memory leak and lost leases when reassigning leases If no offline leases are available for the current client and assigning online leases is disabled, and if all IPs of the pool have already been assigned to clients we look for offline leases that previously were assigned to other clients. In case the current client has online leases the previous code would replace the existing mapping entry and besides resulting in a memory leak the online leases would be lost forever (even if the client later releases the addresses). If this happens repeatedly the number of available addresses would decrease even though the total number of online and offline leases seen in `ipsec leases` would indicate that there are free addresses available. Fixes #764. --- diff --git a/src/libhydra/attributes/mem_pool.c b/src/libhydra/attributes/mem_pool.c index 225abe3834..f35ffaa9c2 100644 --- a/src/libhydra/attributes/mem_pool.c +++ b/src/libhydra/attributes/mem_pool.c @@ -342,9 +342,13 @@ static int get_reassigned(private_mem_pool_t *this, identification_t *id) if (offset) { - entry = entry_create(id); + entry = this->leases->get(this->leases, id); + if (!entry) + { + entry = entry_create(id); + this->leases->put(this->leases, entry->id, entry); + } array_insert(entry->online, ARRAY_TAIL, &offset); - this->leases->put(this->leases, entry->id, entry); } return offset; }