]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: chunk: add a BUG_ON upon the next init_trash_buffer()
authorWilliam Lallemand <wlallemand@haproxy.com>
Fri, 15 Nov 2024 16:15:06 +0000 (17:15 +0100)
committerWilliam Lallemand <wlallemand@haproxy.com>
Fri, 15 Nov 2024 16:15:06 +0000 (17:15 +0100)
The trash pool is initialized twice in haproxy, first during STG_POOL,
and 2nd after configuration parsing.

Doing alloc_trash_chunk() between this 2 phases can lead to strange
things if we are using it after, indeed the pool is destroyed and
trying to do a free_trash_chunk() or accessing the pointer will lead to
crashes.

This patch checks that we don't have used buffers from the trash pool
before initializing the pool again.

src/chunk.c

index c5b74fc5e73098ea1b3939cbcc9f8865d047fb0f..ab60cd1281ab31c377d0e8109417ea240d907e2b 100644 (file)
@@ -89,6 +89,7 @@ static void free_trash_buffers_per_thread()
 /* Initialize the trash buffers. It returns 0 if an error occurred. */
 int init_trash_buffers(int first)
 {
+       BUG_ON(!first && pool_used(pool_head_trash) > 0); /* we tried to keep a trash buffer after reinit the pool */
        pool_destroy(pool_head_trash);
        pool_head_trash = create_pool("trash",
                                      sizeof(struct buffer) + global.tune.bufsize,