From: Willy Tarreau Date: Thu, 8 Oct 2015 12:12:13 +0000 (+0200) Subject: MINOR: debug: enable memory poisonning to use byte 0 X-Git-Tag: v1.6.0~38 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=067ac9f4b6d1f04cba66d2d4324370dc31d5f557;p=thirdparty%2Fhaproxy.git MINOR: debug: enable memory poisonning to use byte 0 When debugging an issue, sometimes it can be useful to be able to use byte 0 to poison memory areas, resulting in the same effect as a calloc(). This patch changes the default mem_poison_byte to -1 to disable it so that all positive values are usable. --- diff --git a/include/common/debug.h b/include/common/debug.h index ac7288a356..1f84c658c9 100644 --- a/include/common/debug.h +++ b/include/common/debug.h @@ -62,7 +62,7 @@ static inline void *p_malloc(size_t size) { void *ret = malloc(size); - if (mem_poison_byte && ret) + if (mem_poison_byte >= 0 && ret) memset(ret, mem_poison_byte, size); return ret; } diff --git a/include/common/memory.h b/include/common/memory.h index 965dfc4886..c76b4ca3bf 100644 --- a/include/common/memory.h +++ b/include/common/memory.h @@ -43,8 +43,8 @@ struct pool_head { char name[12]; /* name of the pool */ }; -/* poison each newly allocated area with this byte if not null */ -extern char mem_poison_byte; +/* poison each newly allocated area with this byte if >= 0 */ +extern int mem_poison_byte; /* * This function destroys a pull by freeing it completely. @@ -141,7 +141,7 @@ static inline void *pool_alloc2(struct pool_head *pool) void *p; p = pool_alloc_dirty(pool); - if (p && mem_poison_byte) + if (p && mem_poison_byte >= 0) memset(p, mem_poison_byte, pool->size); return p; } diff --git a/src/memory.c b/src/memory.c index 61c150bfd9..d9cef64b6e 100644 --- a/src/memory.c +++ b/src/memory.c @@ -20,7 +20,7 @@ #include static struct list pools = LIST_HEAD_INIT(pools); -char mem_poison_byte = 0; +int mem_poison_byte = -1; /* Try to find an existing shared pool with the same characteristics and * returns it, otherwise creates this one. NULL is returned if no memory