Mercurial > dovecot > core-2.2
changeset 11636:9086b081c339 HEAD
sql cache: Free all unused connections at deinit.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 25 Jun 2010 17:18:46 +0100 |
parents | 9127a9f4a020 |
children | c8b6dd6d86d1 |
files | src/lib-sql/sql-db-cache.c |
diffstat | 1 files changed, 14 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-sql/sql-db-cache.c Fri Jun 25 17:02:18 2010 +0100 +++ b/src/lib-sql/sql-db-cache.c Fri Jun 25 17:18:46 2010 +0100 @@ -67,19 +67,23 @@ ctx->cache->unused_count--; } -static void sql_db_cache_drop_oldest(struct sql_db_cache *cache) +static void sql_db_cache_free_tail(struct sql_db_cache *cache) { struct sql_db *db; struct sql_db_cache_context *ctx; - while (cache->unused_count >= cache->max_unused_connections) { - db = cache->unused_tail; - ctx = SQL_DB_CACHE_CONTEXT(db); - sql_db_cache_unlink(ctx); + db = cache->unused_tail; + ctx = SQL_DB_CACHE_CONTEXT(db); + sql_db_cache_unlink(ctx); - i_free(ctx->key); - ctx->orig_deinit(db); - } + i_free(ctx->key); + ctx->orig_deinit(db); +} + +static void sql_db_cache_drop_oldest(struct sql_db_cache *cache) +{ + while (cache->unused_count >= cache->max_unused_connections) + sql_db_cache_free_tail(cache); } struct sql_db * @@ -134,6 +138,8 @@ struct sql_db_cache *cache = *_cache; *_cache = NULL; + while (cache->unused_tail != NULL) + sql_db_cache_free_tail(cache); hash_table_destroy(&cache->dbs); i_free(cache); }