From 0bfd36e7b80afd9b2e815d83b853312c8fe64ad6 Mon Sep 17 00:00:00 2001 From: William Lallemand Date: Fri, 15 Nov 2024 17:15:06 +0100 Subject: [PATCH] MINOR: chunk: add a BUG_ON upon the next init_trash_buffer() 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 | 1 + 1 file changed, 1 insertion(+) diff --git a/src/chunk.c b/src/chunk.c index c5b74fc5e7..ab60cd1281 100644 --- a/src/chunk.c +++ b/src/chunk.c @@ -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,