From dae4aa8c4a9c57fe8566fb897677cbf997fec2a6 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sat, 16 Jun 2007 23:19:53 +0200 Subject: [PATCH] [BUG] fix segfault at exit when using captures since pools v2, the way pools were destroyed at exit is incorrect because it ought to account for users of those pools before freeing them. This test also ensures there is no double free. --- src/memory.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/memory.c b/src/memory.c index 800922714..b157cf0a0 100644 --- a/src/memory.c +++ b/src/memory.c @@ -142,15 +142,23 @@ void pool_gc2() } /* - * This function destroys a pull by freeing it completely. - * This should be called only under extreme circumstances. - * It always returns NULL, easing the clearing of the old pointer. + * This function destroys a pool by freeing it completely, unless it's still + * in use. This should be called only under extreme circumstances. It always + * returns NULL if the resulting pool is empty, easing the clearing of the old + * pointer, otherwise it returns the pool. + * . */ void *pool_destroy2(struct pool_head *pool) { if (pool) { pool_flush2(pool); - FREE(pool); + if (pool->used) + return pool; + pool->users--; + if (!pool->users) { + LIST_DEL(&pool->list); + FREE(pool); + } } return NULL; }