Commit ffcedfab authored by Monty's avatar Monty

Added TRASH_FREED_MEMORY compilation option

One can use -DTRASH_FREED_MEMORY to enable TRASH
macros. Useful to do when one suspects that there
is accesses to freed memory.

Extended my_free() to TRASH freed memory
parent 84514ec6
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
# define MEM_CHECK_DEFINED(a,len) ((void) 0) # define MEM_CHECK_DEFINED(a,len) ((void) 0)
#endif /* HAVE_VALGRIND_MEMCHECK_H */ #endif /* HAVE_VALGRIND_MEMCHECK_H */
#ifndef DBUG_OFF #if !defined(DBUG_OFF) || defined(TRASH_FREED_MEMORY)
#define TRASH_FILL(A,B,C) do { const size_t trash_tmp= (B); memset(A, C, trash_tmp); MEM_UNDEFINED(A, trash_tmp); } while (0) #define TRASH_FILL(A,B,C) do { const size_t trash_tmp= (B); memset(A, C, trash_tmp); MEM_UNDEFINED(A, trash_tmp); } while (0)
#else #else
#define TRASH_FILL(A,B,C) do{ const size_t trash_tmp __attribute__((unused)) = (B) ; MEM_CHECK_ADDRESSABLE(A,trash_tmp);MEM_UNDEFINED(A,trash_tmp);} while (0) #define TRASH_FILL(A,B,C) do{ const size_t trash_tmp __attribute__((unused)) = (B) ; MEM_CHECK_ADDRESSABLE(A,trash_tmp);MEM_UNDEFINED(A,trash_tmp);} while (0)
......
...@@ -214,6 +214,13 @@ void my_free(void *ptr) ...@@ -214,6 +214,13 @@ void my_free(void *ptr)
my_bool old_flags; my_bool old_flags;
old_size= MALLOC_SIZE_AND_FLAG(ptr, &old_flags); old_size= MALLOC_SIZE_AND_FLAG(ptr, &old_flags);
update_malloc_size(- (longlong) old_size - MALLOC_PREFIX_SIZE, old_flags); update_malloc_size(- (longlong) old_size - MALLOC_PREFIX_SIZE, old_flags);
#ifndef SAFEMALLOC
/*
Trash memory if not safemalloc. We don't have to do this if safemalloc
is used as safemalloc will also do trashing
*/
TRASH_FREE(ptr, old_size);
#endif
sf_free(MALLOC_FIX_POINTER_FOR_FREE(ptr)); sf_free(MALLOC_FIX_POINTER_FOR_FREE(ptr));
} }
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment