From 7d02f8dbf441a9bd65cc9d52a4d1aa3a80b6d6da Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Wed, 11 Mar 2015 11:27:38 +0100 Subject: [PATCH] mem-pool: Remove entries without online or offline leases This avoids filling up the hash table with unused/old identities. References #841. --- src/libcharon/attributes/mem_pool.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/libcharon/attributes/mem_pool.c b/src/libcharon/attributes/mem_pool.c index 759d941261..2796682495 100644 --- a/src/libcharon/attributes/mem_pool.c +++ b/src/libcharon/attributes/mem_pool.c @@ -109,6 +109,17 @@ static entry_t* entry_create(identification_t *id) return entry; } +/** + * 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 */ @@ -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);