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.
This commit is contained in:
William Lallemand 2024-11-15 17:15:06 +01:00
parent 5f37af7a8e
commit 0bfd36e7b8

View 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,