]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
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>
Mon, 14 Feb 2022 19:10:43 +0000 (20:10 +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.

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

index de41fa1fe905aee63127a5cf046b9b1af42c05c8..9b808420513588bb9eb011b4b5486516a6c215ee 100644 (file)
@@ -289,6 +289,7 @@ static inline void *pool_get_from_cache(struct pool_head *pool, const void *call
        /* allocate hottest objects first */
        item = LIST_NEXT(&ph->list, typeof(item), by_pool);
 #endif
+       BUG_ON(&item->by_pool == &ph->list);
        LIST_DELETE(&item->by_pool);
        LIST_DELETE(&item->by_lru);
 
index 0bb79d0253ba7e47bce8a37cb032b047daa8a1b0..554d1cbb8a2fd46fd3ac47087eb8a26723dbf912 100644 (file)
@@ -329,6 +329,7 @@ static void pool_evict_last_items(struct pool_head *pool, struct pool_cache_head
 
        while (released < count && !LIST_ISEMPTY(&ph->list)) {
                item = LIST_PREV(&ph->list, typeof(item), by_pool);
+               BUG_ON(&item->by_pool == &ph->list);
                pool_check_pattern(ph, item, pool->size);
                LIST_DELETE(&item->by_pool);
                LIST_DELETE(&item->by_lru);
@@ -389,6 +390,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.
                 */