DEBUG: pools: add extra sanity checks when picking objects from a local cache
authorWilly Tarreau <w@1wt.eu>
Wed, 9 Feb 2022 15:23:55 +0000 (16:23 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 15 Feb 2022 06:42:00 +0000 (07:42 +0100)
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 <w@1wt.eu>

include/haproxy/pool.h
src/pool.c

index f329ef1..683502f 100644 (file)
@@ -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--;
index 37c6ed0..605508d 100644 (file)
@@ -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.
                 */