malloc: perturb mchunk returned from tcache like fast, small, large bin
Commit Message
From: Wang Xu <wangxu72@huawei.com>
mchunk returned from tcache donot have the chance to be perturbed
like what from fastbin, smallbin and largebin.
This patch perturbs the mchunk returned from tcache.
Thanks Carlos O'Donell for comment.
---
malloc/malloc.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
@@ -3108,7 +3108,9 @@ __libc_malloc (size_t bytes)
&& tcache
&& tcache->counts[tc_idx] > 0)
{
- return tcache_get (tc_idx);
+ void *p = tcache_get (tc_idx);
+ alloc_perturb (p, bytes);
+ return p;
}
DIAG_POP_NEEDS_COMMENT;
#endif
@@ -3963,7 +3965,9 @@ _int_malloc (mstate av, size_t bytes)
&& mp_.tcache_unsorted_limit > 0
&& tcache_unsorted_count > mp_.tcache_unsorted_limit)
{
- return tcache_get (tc_idx);
+ void *p = tcache_get (tc_idx);
+ alloc_perturb (p, bytes);
+ return p;
}
#endif
@@ -3976,7 +3980,9 @@ _int_malloc (mstate av, size_t bytes)
/* If all the small chunks we found ended up cached, return one now. */
if (return_cached)
{
- return tcache_get (tc_idx);
+ void *p = tcache_get (tc_idx);
+ alloc_perturb (p, bytes);
+ return p;
}
#endif