This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] malloc: fix perturb_byte handling for tcache
- From: Joern Engel <joern at purestorage dot com>
- To: "GNU C. Library" <libc-alpha at sourceware dot org>
- Cc: Siddhesh Poyarekar <siddhesh dot poyarekar at gmail dot com>, Joern Engel <joern at purestorage dot com>
- Date: Mon, 25 Jan 2016 16:25:28 -0800
- Subject: [PATCH] malloc: fix perturb_byte handling for tcache
- Authentication-results: sourceware.org; auth=none
- References: <1453767942-19369-1-git-send-email-joern at purestorage dot com>
Also removes stale comment for tcache_free.
JIRA: PURE-27597
---
tpc/malloc2.13/malloc.c | 5 +----
tpc/malloc2.13/tcache.h | 9 ++++++---
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/tpc/malloc2.13/malloc.c b/tpc/malloc2.13/malloc.c
index 190c1d24b082..74b35f6aa366 100644
--- a/tpc/malloc2.13/malloc.c
+++ b/tpc/malloc2.13/malloc.c
@@ -3290,7 +3290,7 @@ Void_t *public_mALLOc(size_t bytes)
victim = tcache_malloc(bytes);
if (victim)
- goto out;
+ return victim;
ar_ptr = arena_get(bytes);
if (!ar_ptr)
@@ -3302,9 +3302,6 @@ Void_t *public_mALLOc(size_t bytes)
}
arena_unlock(ar_ptr);
assert(!victim || chunk_is_mmapped(mem2chunk(victim)) || ar_ptr == arena_for_chunk(mem2chunk(victim)));
-out:
- if (perturb_byte)
- alloc_perturb(victim, bytes);
return victim;
}
diff --git a/tpc/malloc2.13/tcache.h b/tpc/malloc2.13/tcache.h
index edfe7acbc75e..00fe24249d49 100644
--- a/tpc/malloc2.13/tcache.h
+++ b/tpc/malloc2.13/tcache.h
@@ -287,6 +287,8 @@ static void *tcache_malloc(size_t size)
void *p = chunk2mem(victim);
cache->tc_size -= chunksize(victim);
cache->tc_count--;
+ if (perturb_byte)
+ alloc_perturb(p, size);
return p;
}
@@ -333,12 +335,11 @@ static void *tcache_malloc(size_t size)
}
arena_unlock(arena);
assert(!victim || arena == arena_for_chunk(mem2chunk(victim)));
+ if (perturb_byte)
+ alloc_perturb(victim, size);
return victim;
}
-/*
- * returns 1 if object was freed
- */
static void tcache_free(mchunkptr p)
{
struct thread_cache *cache;
@@ -367,6 +368,8 @@ static void tcache_free(mchunkptr p)
malloc_printerr(check_action, "invalid tcache entry", chunk2mem(p));
return;
}
+ if (perturb_byte)
+ free_perturb(p, size - 2 * SIZE_SZ);
add_to_bin(bin, p);
if (cache->tc_size > CACHE_SIZE)
tcache_gc(cache);
--
2.7.0.rc3