]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
DEBUG: add p_malloc() to return a poisonned memory area
authorWilly Tarreau <w@1wt.eu>
Fri, 25 Sep 2015 23:27:43 +0000 (01:27 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 25 Sep 2015 23:28:43 +0000 (01:28 +0200)
This one is useful to detect improperly initialized memory areas
when some suspicious malloc() are involved in random behaviours.

include/common/debug.h

index baabf4a1d639b3fd6d38d2b26731cbebeac502e1..ac7288a3562a6d624a46da23d1e1741f58fc5f06 100644 (file)
@@ -23,6 +23,7 @@
 #define _COMMON_DEBUG_H
 
 #include <common/config.h>
+#include <common/memory.h>
 
 #ifdef DEBUG_FULL
 #define DPRINTF(x...) fprintf(x)
                ##args);                                           \
         } while (0)
 
+/* This one is useful to automatically apply poisonning on an area returned
+ * by malloc(). Only "p_" is required to make it work, and to define a poison
+ * byte using -dM.
+ */
+static inline void *p_malloc(size_t size)
+{
+       void *ret = malloc(size);
+       if (mem_poison_byte && ret)
+               memset(ret, mem_poison_byte, size);
+       return ret;
+}
 
 #endif /* _COMMON_DEBUG_H */