Skip to content
Permalink
Browse files

improve ASAN instrumentation: MEM_ROOT

more complete TRASH-ing of memroots
  • Loading branch information...
vuvova committed Jan 21, 2018
1 parent a966d42 commit dc28b6d180a00658debf65b1258bd5fdf0d0c26e
Showing with 6 additions and 3 deletions.
  1. +6 −3 mysys/my_alloc.c
@@ -22,6 +22,8 @@
#undef EXTRA_DEBUG
#define EXTRA_DEBUG

#define TRASH_MEM(X) TRASH_FREE(((char*)(X) + ((X)->size-(X)->left)), (X)->left)

/*
Initialize memory root
@@ -60,12 +62,13 @@ void init_alloc_root(MEM_ROOT *mem_root, size_t block_size,
if (pre_alloc_size)
{
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))))
{
mem_root->free->size= pre_alloc_size+ALIGN_SIZE(sizeof(USED_MEM));
mem_root->free->left= pre_alloc_size;
mem_root->free->next= 0;
TRASH_MEM(mem_root->free);
}
}
#endif
@@ -132,6 +135,7 @@ void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size,
mem->left= pre_alloc_size;
mem->next= *prev;
*prev= mem_root->pre_alloc= mem;
TRASH_MEM(mem);
}
else
{
@@ -225,6 +229,7 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length)
next->size= get_size;
next->left= get_size-ALIGN_SIZE(sizeof(USED_MEM));
*prev=next;
TRASH_MEM(next);
}

point= (uchar*) ((char*) next+ (next->size-next->left));
@@ -293,8 +298,6 @@ void *multi_alloc_root(MEM_ROOT *root, ...)
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 */

static inline void mark_blocks_free(MEM_ROOT* root)

0 comments on commit dc28b6d

Please sign in to comment.
You can’t perform that action at this time.