Commit dc28b6d1 authored by Sergei Golubchik's avatar Sergei Golubchik

improve ASAN instrumentation: MEM_ROOT

more complete TRASH-ing of memroots
parent a966d422
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
#undef EXTRA_DEBUG #undef EXTRA_DEBUG
#define EXTRA_DEBUG #define EXTRA_DEBUG
#define TRASH_MEM(X) TRASH_FREE(((char*)(X) + ((X)->size-(X)->left)), (X)->left)
/* /*
Initialize memory root Initialize memory root
...@@ -60,12 +62,13 @@ void init_alloc_root(MEM_ROOT *mem_root, size_t block_size, ...@@ -60,12 +62,13 @@ void init_alloc_root(MEM_ROOT *mem_root, size_t block_size,
if (pre_alloc_size) if (pre_alloc_size)
{ {
if ((mem_root->free= mem_root->pre_alloc= if ((mem_root->free= mem_root->pre_alloc=
(USED_MEM*) my_malloc(pre_alloc_size+ ALIGN_SIZE(sizeof(USED_MEM)), (USED_MEM*) my_malloc(pre_alloc_size + ALIGN_SIZE(sizeof(USED_MEM)),
MYF(0)))) MYF(0))))
{ {
mem_root->free->size= pre_alloc_size+ALIGN_SIZE(sizeof(USED_MEM)); mem_root->free->size= pre_alloc_size+ALIGN_SIZE(sizeof(USED_MEM));
mem_root->free->left= pre_alloc_size; mem_root->free->left= pre_alloc_size;
mem_root->free->next= 0; mem_root->free->next= 0;
TRASH_MEM(mem_root->free);
} }
} }
#endif #endif
...@@ -132,6 +135,7 @@ void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size, ...@@ -132,6 +135,7 @@ void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size,
mem->left= pre_alloc_size; mem->left= pre_alloc_size;
mem->next= *prev; mem->next= *prev;
*prev= mem_root->pre_alloc= mem; *prev= mem_root->pre_alloc= mem;
TRASH_MEM(mem);
} }
else else
{ {
...@@ -225,6 +229,7 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length) ...@@ -225,6 +229,7 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length)
next->size= get_size; next->size= get_size;
next->left= get_size-ALIGN_SIZE(sizeof(USED_MEM)); next->left= get_size-ALIGN_SIZE(sizeof(USED_MEM));
*prev=next; *prev=next;
TRASH_MEM(next);
} }
point= (uchar*) ((char*) next+ (next->size-next->left)); point= (uchar*) ((char*) next+ (next->size-next->left));
...@@ -293,8 +298,6 @@ void *multi_alloc_root(MEM_ROOT *root, ...) ...@@ -293,8 +298,6 @@ void *multi_alloc_root(MEM_ROOT *root, ...)
DBUG_RETURN((void*) start); DBUG_RETURN((void*) start);
} }
#define TRASH_MEM(X) TRASH_FREE(((char*)(X) + ((X)->size-(X)->left)), (X)->left)
/* Mark all data in blocks free for reusage */ /* Mark all data in blocks free for reusage */
static inline void mark_blocks_free(MEM_ROOT* root) static inline void mark_blocks_free(MEM_ROOT* root)
......
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