]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: debug: enable memory poisonning to use byte 0
authorWilly Tarreau <w@1wt.eu>
Thu, 8 Oct 2015 12:12:13 +0000 (14:12 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 8 Oct 2015 12:12:13 +0000 (14:12 +0200)
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.

include/common/debug.h
include/common/memory.h
src/memory.c

index ac7288a3562a6d624a46da23d1e1741f58fc5f06..1f84c658c9d7d83ce88bfe3217f9c5a211cd27dd 100644 (file)
@@ -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;
 }
index 965dfc4886e16479d52e14818f840ad6ce504e79..c76b4ca3bf49721e9742d8754b143a59c1b88f9e 100644 (file)
@@ -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;
 }
index 61c150bfd996afb509da615b58cd78649b353952..d9cef64b6e6944780d29a802e33c77fa051d8917 100644 (file)
@@ -20,7 +20,7 @@
 #include <proto/log.h>
 
 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