]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[BUG] fix segfault at exit when using captures
authorWilly Tarreau <w@1wt.eu>
Sat, 16 Jun 2007 21:19:53 +0000 (23:19 +0200)
committerWilly Tarreau <w@1wt.eu>
Sat, 16 Jun 2007 21:19:53 +0000 (23:19 +0200)
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

index 8009227143e737a8963670afe2a0214870a4a6e8..b157cf0a06b5f732e0465cbb618bca447343267c 100644 (file)
@@ -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;
 }