[PATCH] malloc: fix perturb_byte handling for tcache
Joern Engel
joern@purestorage.com
Tue Jan 26 00:27:00 GMT 2016
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
More information about the Libc-alpha
mailing list