From ef301b75566cc4a45e39e27380811b780050f378 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 23 Feb 2022 14:15:18 +0100 Subject: [PATCH] MINOR: pools: add a debugging flag for memory poisonning option Now -dM will set POOL_DBG_POISON for consistency with the rest of the pool debugging options. As such now we only check for the new flag, which allows the default value to be preset. --- include/haproxy/pool-t.h | 1 + src/haproxy.c | 7 ++++++- src/pool.c | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/include/haproxy/pool-t.h b/include/haproxy/pool-t.h index 6f77bd985..47fa34a5d 100644 --- a/include/haproxy/pool-t.h +++ b/include/haproxy/pool-t.h @@ -49,6 +49,7 @@ #define POOL_DBG_NO_CACHE 0x00000020 // disable thread-local pool caches #define POOL_DBG_CALLER 0x00000040 // trace last caller's location #define POOL_DBG_TAG 0x00000080 // place a tag at the end of the area +#define POOL_DBG_POISON 0x00000100 // poison memory area on pool_alloc() /* This is the head of a thread-local cache */ diff --git a/src/haproxy.c b/src/haproxy.c index 6350a6aa7..f2e417b26 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -1629,8 +1629,13 @@ static void init(int argc, char **argv) arg_mode |= MODE_DIAG; else if (*flag == 'd' && flag[1] == 'W') arg_mode |= MODE_ZERO_WARNING; - else if (*flag == 'd' && flag[1] == 'M') + else if (*flag == 'd' && flag[1] == 'M') { mem_poison_byte = flag[2] ? strtol(flag + 2, NULL, 0) : 'P'; + if (mem_poison_byte >= 0) + pool_debugging |= POOL_DBG_POISON; + else + pool_debugging &= ~POOL_DBG_POISON; + } else if (*flag == 'd' && flag[1] == 'r') global.tune.options |= GTUNE_RESOLVE_DONTFAIL; #if defined(HA_HAVE_DUMP_LIBS) diff --git a/src/pool.c b/src/pool.c index b85a797a0..2cb37f345 100644 --- a/src/pool.c +++ b/src/pool.c @@ -34,7 +34,7 @@ THREAD_LOCAL size_t pool_cache_bytes = 0; /* total cache size */ THREAD_LOCAL size_t pool_cache_count = 0; /* #cache objects */ static struct list pools __read_mostly = LIST_HEAD_INIT(pools); -int mem_poison_byte __read_mostly = -1; +int mem_poison_byte __read_mostly = 'P'; uint pool_debugging __read_mostly = /* set of POOL_DBG_* flags */ #ifdef DEBUG_FAIL_ALLOC POOL_DBG_FAIL_ALLOC | @@ -700,7 +700,7 @@ void *__pool_alloc(struct pool_head *pool, unsigned int flags) if (likely(p)) { if (unlikely(flags & POOL_F_MUST_ZERO)) memset(p, 0, pool->size); - else if (unlikely(!(flags & POOL_F_NO_POISON) && mem_poison_byte >= 0)) + else if (unlikely(!(flags & POOL_F_NO_POISON) && (pool_debugging & POOL_DBG_POISON))) memset(p, mem_poison_byte, pool->size); } return p;