memroot: trash the memory in free_root()

parent 1fbb96ea
...@@ -217,6 +217,12 @@ gptr alloc_root(MEM_ROOT *mem_root,unsigned int Size) ...@@ -217,6 +217,12 @@ gptr alloc_root(MEM_ROOT *mem_root,unsigned int Size)
#endif #endif
} }
#ifdef SAFEMALLOC
#define TRASH(X) bfill(((char*)(X) + ((X)->size-(X)->left)), (X)->left, 0xa5)
#else
#define TRASH /* no-op */
#endif
/* 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)
...@@ -227,14 +233,20 @@ static inline void mark_blocks_free(MEM_ROOT* root) ...@@ -227,14 +233,20 @@ static inline void mark_blocks_free(MEM_ROOT* root)
/* iterate through (partially) free blocks, mark them free */ /* iterate through (partially) free blocks, mark them free */
last= &root->free; last= &root->free;
for (next= root->free; next; next= *(last= &next->next)) for (next= root->free; next; next= *(last= &next->next))
{
next->left= next->size - ALIGN_SIZE(sizeof(USED_MEM)); next->left= next->size - ALIGN_SIZE(sizeof(USED_MEM));
TRASH(next);
}
/* Combine the free and the used list */ /* Combine the free and the used list */
*last= next=root->used; *last= next=root->used;
/* now go through the used blocks and mark them free */ /* now go through the used blocks and mark them free */
for (; next; next= next->next) for (; next; next= next->next)
{
next->left= next->size - ALIGN_SIZE(sizeof(USED_MEM)); next->left= next->size - ALIGN_SIZE(sizeof(USED_MEM));
TRASH(next);
}
/* Now everything is set; Indicate that nothing is used anymore */ /* Now everything is set; Indicate that nothing is used anymore */
root->used= 0; root->used= 0;
...@@ -280,6 +292,7 @@ void free_root(MEM_ROOT *root, myf MyFlags) ...@@ -280,6 +292,7 @@ void free_root(MEM_ROOT *root, myf MyFlags)
{ {
root->free=root->pre_alloc; root->free=root->pre_alloc;
root->free->left=root->pre_alloc->size-ALIGN_SIZE(sizeof(USED_MEM)); root->free->left=root->pre_alloc->size-ALIGN_SIZE(sizeof(USED_MEM));
TRASH(root->pre_alloc);
root->free->next=0; root->free->next=0;
} }
root->block_num= 4; root->block_num= 4;
......
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