--- orig5037/mysys/my_alloc.c 2007-03-05 11:21:13.000000000 -0800 +++ new5037/mysys/my_alloc.c 2009-04-30 11:05:24.000000000 -0700 @@ -21,6 +21,41 @@ #undef EXTRA_DEBUG #define EXTRA_DEBUG +#if defined(USE_VALGRIND) +/* Please use Valgrind version 3.2 or later */ +#include + +/* some macros definitions, pretty much same as in innobase/include/univ.i */ +#define VG_MEM_ALLOC(addr, size) VALGRIND_MAKE_MEM_UNDEFINED(addr, size) + +/* Mark the free'd memory unusable */ +#define VG_TRASH_MEM(X) \ + VALGRIND_MAKE_MEM_NOACCESS(((char*)(X) + ((X)->size-(X)->left)), (X)->left) + +#else + +#define VG_MEM_ALLOC(addr, size) +#define VG_TRASH_MEM(X) + +#endif /* USE_VALGRIND */ + +/* Clobber the free'd memory */ +#ifndef DBUG_OFF +#define SCRUB_MEM(X) \ +do { \ + VG_MEM_ALLOC(((char*)(X) + ((X)->size-(X)->left)), (X)->left); \ + bfill(((char*)(X) + ((X)->size-(X)->left)), (X)->left, 0x8f); \ +} while(0) +#else +#define SCRUB_MEM(X) +#endif /* DBUG_OFF */ + +/* Clobber the free'd memory and mark it unusable */ +#define TRASH_MEM(X) \ +do { \ + SCRUB_MEM(X); \ + VG_TRASH_MEM(X); \ +} while (0) /* Initialize memory root @@ -145,6 +180,7 @@ { #if defined(HAVE_purify) && defined(EXTRA_DEBUG) reg1 USED_MEM *next; + gptr ret; DBUG_ENTER("alloc_root"); DBUG_PRINT("enter",("root: 0x%lx", (long) mem_root)); @@ -157,12 +193,14 @@ (*mem_root->error_handler)(); DBUG_RETURN((gptr) 0); /* purecov: inspected */ } + next->next= mem_root->used; next->size= Size; + next->left= Size-ALIGN_SIZE(sizeof(USED_MEM)); mem_root->used= next; - DBUG_PRINT("exit",("ptr: 0x%lx", (long) (((char*) next)+ - ALIGN_SIZE(sizeof(USED_MEM))))); - DBUG_RETURN((gptr) (((char*) next)+ALIGN_SIZE(sizeof(USED_MEM)))); + ret= (gptr) (((char*) next)+ALIGN_SIZE(sizeof(USED_MEM))); + DBUG_PRINT("exit",("ptr: 0x%lx", (long) ret)); + DBUG_RETURN(ret); #else uint get_size, block_size; gptr point; @@ -217,6 +255,7 @@ mem_root->first_block_usage= 0; } DBUG_PRINT("exit",("ptr: 0x%lx", (ulong) point)); + VG_MEM_ALLOC(point, Size); DBUG_RETURN(point); #endif } @@ -272,8 +311,6 @@ DBUG_RETURN((gptr) start); } -#define TRASH_MEM(X) TRASH(((char*)(X) + ((X)->size-(X)->left)), (X)->left) - /* Mark all data in blocks free for reusage */ static inline void mark_blocks_free(MEM_ROOT* root) @@ -344,13 +381,19 @@ { old=next; next= next->next ; if (old != root->pre_alloc) + { + SCRUB_MEM(old); my_free((gptr) old,MYF(0)); + } } for (next=root->free ; next ;) { old=next; next= next->next; if (old != root->pre_alloc) + { + SCRUB_MEM(old); my_free((gptr) old,MYF(0)); + } } root->used=root->free=0; if (root->pre_alloc)