From: Willy Tarreau Date: Wed, 9 Feb 2022 15:23:55 +0000 (+0100) Subject: DEBUG: pools: add extra sanity checks when picking objects from a local cache X-Git-Tag: v2.5.2~21 X-Git-Url: http://git.haproxy.org/?a=commitdiff_plain;h=ebeb66645ec529285d63c64773d2bc74ca7f4a58;p=haproxy-2.5.git DEBUG: pools: add extra sanity checks when picking objects from a local cache These few checks are added to make sure we never try to pick an object from an empty list, which would have a devastating effect. (cherry picked from commit e2830addda9baf42c682d7c1856a53e2875deea4) [wt: adjusted context] Signed-off-by: Willy Tarreau --- diff --git a/include/haproxy/pool.h b/include/haproxy/pool.h index f329ef1..683502f 100644 --- a/include/haproxy/pool.h +++ b/include/haproxy/pool.h @@ -260,6 +260,7 @@ static inline void *pool_get_from_cache(struct pool_head *pool) /* allocate hottest objects first */ item = LIST_NEXT(&ph->list, typeof(item), by_pool); #endif + BUG_ON(&item->by_pool == &ph->list); ph->count--; pool_cache_bytes -= pool->size; pool_cache_count--; diff --git a/src/pool.c b/src/pool.c index 37c6ed0..605508d 100644 --- a/src/pool.c +++ b/src/pool.c @@ -284,6 +284,7 @@ void pool_evict_from_local_cache(struct pool_head *pool, int full) (ph->count >= 16 + pool_cache_count / 8 && pool_cache_bytes > CONFIG_HAP_POOL_CACHE_SIZE * 3 / 4)) { item = LIST_NEXT(&ph->list, typeof(item), by_pool); + BUG_ON(&item->by_pool == &ph->list); ph->count--; pool_cache_bytes -= pool->size; pool_cache_count--; @@ -305,6 +306,7 @@ void pool_evict_from_local_caches() do { item = LIST_PREV(&th_ctx->pool_lru_head, struct pool_cache_item *, by_lru); + BUG_ON(&item->by_lru == &th_ctx->pool_lru_head); /* note: by definition we remove oldest objects so they also are the * oldest in their own pools, thus their next is the pool's head. */