diff --git a/include/haproxy/pool-t.h b/include/haproxy/pool-t.h index 073fe3251..bbdc5365a 100644 --- a/include/haproxy/pool-t.h +++ b/include/haproxy/pool-t.h @@ -80,6 +80,7 @@ /* possible flags for __pool_alloc() */ #define POOL_F_NO_POISON 0x00000001 // do not poison the area #define POOL_F_MUST_ZERO 0x00000002 // zero the returned area +#define POOL_F_NO_FAIL 0x00000004 // do not randomly fail struct pool_cache_head { diff --git a/include/haproxy/pool.h b/include/haproxy/pool.h index 6f0197115..0f76b9658 100644 --- a/include/haproxy/pool.h +++ b/include/haproxy/pool.h @@ -275,6 +275,11 @@ static inline void *__pool_alloc(struct pool_head *pool, unsigned int flags) { void *p; +#ifdef DEBUG_FAIL_ALLOC + if (!(flags & POOL_F_NO_FAIL) && mem_should_fail(pool)) + return NULL; +#endif + #ifdef CONFIG_HAP_POOLS if (likely(p = pool_get_from_local_cache(pool))) goto ret; diff --git a/src/pool.c b/src/pool.c index 48cc46788..5939d961d 100644 --- a/src/pool.c +++ b/src/pool.c @@ -158,10 +158,6 @@ void *pool_alloc_nocache(struct pool_head *pool) int limit = pool->limit; void *ptr = NULL; -#ifdef DEBUG_FAIL_ALLOC - if (mem_should_fail(pool)) - return NULL; -#endif if (limit && allocated >= limit) { activity[tid].pool_fail++; return NULL;