Skip to content

Commit dc28b6d

Browse files
committed
improve ASAN instrumentation: MEM_ROOT
more complete TRASH-ing of memroots
1 parent a966d42 commit dc28b6d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

mysys/my_alloc.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#undef EXTRA_DEBUG
2323
#define EXTRA_DEBUG
2424

25+
#define TRASH_MEM(X) TRASH_FREE(((char*)(X) + ((X)->size-(X)->left)), (X)->left)
26+
2527
/*
2628
Initialize memory root
2729
@@ -60,12 +62,13 @@ void init_alloc_root(MEM_ROOT *mem_root, size_t block_size,
6062
if (pre_alloc_size)
6163
{
6264
if ((mem_root->free= mem_root->pre_alloc=
63-
(USED_MEM*) my_malloc(pre_alloc_size+ ALIGN_SIZE(sizeof(USED_MEM)),
65+
(USED_MEM*) my_malloc(pre_alloc_size + ALIGN_SIZE(sizeof(USED_MEM)),
6466
MYF(0))))
6567
{
6668
mem_root->free->size= pre_alloc_size+ALIGN_SIZE(sizeof(USED_MEM));
6769
mem_root->free->left= pre_alloc_size;
6870
mem_root->free->next= 0;
71+
TRASH_MEM(mem_root->free);
6972
}
7073
}
7174
#endif
@@ -132,6 +135,7 @@ void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size,
132135
mem->left= pre_alloc_size;
133136
mem->next= *prev;
134137
*prev= mem_root->pre_alloc= mem;
138+
TRASH_MEM(mem);
135139
}
136140
else
137141
{
@@ -225,6 +229,7 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length)
225229
next->size= get_size;
226230
next->left= get_size-ALIGN_SIZE(sizeof(USED_MEM));
227231
*prev=next;
232+
TRASH_MEM(next);
228233
}
229234

230235
point= (uchar*) ((char*) next+ (next->size-next->left));
@@ -293,8 +298,6 @@ void *multi_alloc_root(MEM_ROOT *root, ...)
293298
DBUG_RETURN((void*) start);
294299
}
295300

296-
#define TRASH_MEM(X) TRASH_FREE(((char*)(X) + ((X)->size-(X)->left)), (X)->left)
297-
298301
/* Mark all data in blocks free for reusage */
299302

300303
static inline void mark_blocks_free(MEM_ROOT* root)

0 commit comments

Comments
 (0)