aboutsummaryrefslogtreecommitdiff
path: root/malloc/malloc.c
diff options
context:
space:
mode:
authorDJ Delorie <dj@delorie.com>2016-07-13 11:02:39 -0400
committerDJ Delorie <dj@delorie.com>2016-07-13 11:02:39 -0400
commit6ce11061fb60bb64742b19f626f2471f88554039 (patch)
treefeba2d56509c16d8f2b7afacf9fdcdd718a15172 /malloc/malloc.c
parentb856f645a2f58a3e224976167b4b1fb030d7967b (diff)
downloadglibc-6ce11061fb60bb64742b19f626f2471f88554039.tar.xz
glibc-6ce11061fb60bb64742b19f626f2471f88554039.zip
Fix double-padding bug
The tcache was calling request2size which resulted in double padding. Store tcache's copy in a separate variable to avoid this.
Diffstat (limited to 'malloc/malloc.c')
-rw-r--r--malloc/malloc.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/malloc/malloc.c b/malloc/malloc.c
index a0bf866772..70e7dc8bba 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -3294,8 +3294,9 @@ __libc_malloc (size_t bytes)
void *victim;
#if USE_TCACHE
- bytes = request2size(bytes);
- int tc_idx = size2tidx (bytes);
+ /* int_free also calls request2size, be careful to not pad twice. */
+ size_t tbytes = request2size(bytes);
+ int tc_idx = size2tidx (tbytes);
if (tcache.initted == 0)
{
@@ -3312,7 +3313,7 @@ __libc_malloc (size_t bytes)
__MTB_TRACE_ENTRY (MALLOC,bytes,NULL);
#if USE_TCACHE
- if (bytes < MAX_TCACHE_SIZE
+ if (tbytes < MAX_TCACHE_SIZE
&& tcache.entries[tc_idx] != NULL
&& tcache.initted == 1)
{
@@ -3337,7 +3338,7 @@ __libc_malloc (size_t bytes)
/* This is fast but causes internal fragmentation, as it always
pulls large chunks but puts small chunks, leading to a large
backlog of small chunks. */
- if (bytes < MAX_TCACHE_SIZE
+ if (tbytes < MAX_TCACHE_SIZE
&& tcache.initted == 1)
{
void *ent;
@@ -3346,7 +3347,7 @@ __libc_malloc (size_t bytes)
size_t total_bytes;
int i;
- assert (tc_bytes >= bytes);
+ assert (tc_bytes >= tbytes);
if (tc_bytes < 2 * SIZE_SZ)
tc_bytes = 2 * SIZE_SZ;