diff --git a/config-linuxmodule.h.in b/config-linuxmodule.h.in index cd88e4f89baaed792b5aff2d581d7ec31ad5d2b8..e9d1e5300840cfbfbc8ab82e8e3230e2dbe64034 100644 --- a/config-linuxmodule.h.in +++ b/config-linuxmodule.h.in @@ -178,6 +178,9 @@ /* Define to 1 if Linux defines the type 'uintptr_t'. */ #undef HAVE_UINTPTR_T_LINUXMODULE +/* Define to 1 to enable poisoning of freed HashAllocator blocks. */ +#undef HAVE_HASH_ALLOCATOR_POISONING + /* The size of a `click_jiffies_t', as computed by sizeof. */ #define SIZEOF_CLICK_JIFFIES_T SIZEOF_LONG diff --git a/config-userlevel.h.in b/config-userlevel.h.in index 7bf180e7e2cb4cfcddc31b98c342143f365d4b2e..68be606eb5db8c0fb28915a4ef646606be7df966 100644 --- a/config-userlevel.h.in +++ b/config-userlevel.h.in @@ -316,6 +316,9 @@ /* Define if you have the <valgrind/memcheck.h> header file. */ #undef HAVE_VALGRIND_MEMCHECK_H +/* Define to 1 to enable poisoning of freed HashAllocator blocks. */ +#undef HAVE_HASH_ALLOCATOR_POISONING + /* Define if you have the vsnprintf function. */ #undef HAVE_VSNPRINTF diff --git a/configure.in b/configure.in index 57f3995be47d5a58a88b25dd880f701758c036f3..f9391acb0121b27be7d11acf74006914e468e1a8 100644 --- a/configure.in +++ b/configure.in @@ -1482,6 +1482,11 @@ if test "$value" != 0; then AC_DEFINE_UNQUOTED([CLICK_DEBUG_SCHEDULING], [$value], [Define to enable debugging support for Click scheduling.]) fi +AC_ARG_ENABLE(hash-allocator-poisoning, [ --enable-hash-allocator-poisoning enable HashAllocator block poisoning], :, enable_hash_allocator_poisoning=no) +if test $enable_hash_allocator_poisoning = yes; then + AC_DEFINE(HAVE_HASH_ALLOCATOR_POISONING) +fi + dnl Compile for the native architecture AC_ARG_ENABLE(portable-binary, [AS_HELP_STRING([--enable-portable-binary], [disable compiler optimizations that would produce unportable binaries])], diff --git a/include/click/hashallocator.hh b/include/click/hashallocator.hh index 38d55cef040d7782ed6747dc8657f12a09964319..8d8d88c6301ec9468744bd75b5029d99c33803e8 100644 --- a/include/click/hashallocator.hh +++ b/include/click/hashallocator.hh @@ -23,6 +23,11 @@ class HashAllocator { public: private: +#if HAVE_HASH_ALLOCATOR_POISONING + // Freed blocks are poisoned with this byte value. + static const uint8_t poison_byte = 0x0d; +#endif + struct link { link *next; }; @@ -91,6 +96,9 @@ inline void *HashAllocator::allocate() inline void HashAllocator::deallocate(void *p) { if (p) { +#if HAVE_HASH_ALLOCATOR_POISONING + memset(p, poison_byte, _size); +#endif reinterpret_cast<link *>(p)->next = _free; _free = reinterpret_cast<link *>(p); #ifdef VALGRIND_MEMPOOL_FREE