diff options
author | Tobias Brunner <tobias@strongswan.org> | 2015-03-11 11:27:38 +0100 |
---|---|---|
committer | Tobias Brunner <tobias@strongswan.org> | 2015-03-19 09:55:56 +0100 |
commit | 7d02f8dbf441a9bd65cc9d52a4d1aa3a80b6d6da (patch) | |
tree | 6113ea5884e6be9c94c9e062240d0cf50a20f106 | |
parent | f30be6a92fb2b48f6021b5f7480e026f5a37f67e (diff) | |
download | strongswan-7d02f8dbf441a9bd65cc9d52a4d1aa3a80b6d6da.tar.bz2 strongswan-7d02f8dbf441a9bd65cc9d52a4d1aa3a80b6d6da.tar.xz |
mem-pool: Remove entries without online or offline leases
This avoids filling up the hash table with unused/old identities.
References #841.
-rw-r--r-- | src/libcharon/attributes/mem_pool.c | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/src/libcharon/attributes/mem_pool.c b/src/libcharon/attributes/mem_pool.c index 759d94126..279668249 100644 --- a/src/libcharon/attributes/mem_pool.c +++ b/src/libcharon/attributes/mem_pool.c @@ -110,6 +110,17 @@ static entry_t* entry_create(identification_t *id) } /** + * Destroy an entry + */ +static void entry_destroy(entry_t *this) +{ + this->id->destroy(this->id); + array_destroy(this->online); + array_destroy(this->offline); + free(this); +} + +/** * hashtable hash function for identities */ static u_int id_hash(identification_t *id) @@ -356,8 +367,16 @@ static int get_reassigned(private_mem_pool_t *this, identification_t *id, if (array_remove(entry->offline, ARRAY_HEAD, ¤t)) { lease.offset = current; - DBG1(DBG_CFG, "reassigning existing offline lease by '%Y'" - " to '%Y'", entry->id, id); + DBG1(DBG_CFG, "reassigning existing offline lease by '%Y' " + "to '%Y'", entry->id, id); + } + if (!array_count(entry->online) && !array_count(entry->offline)) + { + this->leases->remove_at(this->leases, enumerator); + entry_destroy(entry); + } + if (lease.offset) + { break; } } @@ -570,10 +589,7 @@ METHOD(mem_pool_t, destroy, void, enumerator = this->leases->create_enumerator(this->leases); while (enumerator->enumerate(enumerator, NULL, &entry)) { - entry->id->destroy(entry->id); - array_destroy(entry->online); - array_destroy(entry->offline); - free(entry); + entry_destroy(entry); } enumerator->destroy(enumerator); |