From: Willy Tarreau Date: Fri, 25 Sep 2015 23:27:43 +0000 (+0200) Subject: DEBUG: add p_malloc() to return a poisonned memory area X-Git-Tag: v1.6-dev6~56 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1895428ef43929e8a4505b8bf0e4749b59268427;p=thirdparty%2Fhaproxy.git DEBUG: add p_malloc() to return a poisonned memory area This one is useful to detect improperly initialized memory areas when some suspicious malloc() are involved in random behaviours. --- diff --git a/include/common/debug.h b/include/common/debug.h index baabf4a1d6..ac7288a356 100644 --- a/include/common/debug.h +++ b/include/common/debug.h @@ -23,6 +23,7 @@ #define _COMMON_DEBUG_H #include +#include #ifdef DEBUG_FULL #define DPRINTF(x...) fprintf(x) @@ -54,5 +55,16 @@ ##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 */