From: William Lallemand Date: Fri, 15 Nov 2024 16:15:06 +0000 (+0100) Subject: MINOR: chunk: add a BUG_ON upon the next init_trash_buffer() X-Git-Tag: v3.1-dev13~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0bfd36e7b8;p=thirdparty%2Fhaproxy.git 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. --- 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,