From 6ef9cc37f0ea151a54e5c8a19950a6d5b6ff8a96 Mon Sep 17 00:00:00 2001 From: Siddhesh Poyarekar Date: Wed, 5 Sep 2012 21:49:00 +0530 Subject: Return requested size for malloc_usable_size when MALLOC_CHECK_ > 0 [BZ #1349] malloc_usable_size returns the usable size in an allocated chunk, which may be >= the requested size. In the case of MALLOC_CHECK_ being exported to > 0 however, only the requested size is usable, since a magic value is written at the end of the request size to trap writes beyond request bounds. Hence, when MALLOC_CHECK_ is exported to > 0, malloc_usable_size() should return the request size. --- malloc/malloc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'malloc/malloc.c') diff --git a/malloc/malloc.c b/malloc/malloc.c index 0f1796c..bd562df 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -1,5 +1,5 @@ /* Malloc implementation for multiple threads without lock contention. - Copyright (C) 1996-2009, 2010, 2011, 2012 Free Software Foundation, Inc. + Copyright (C) 1996-2012 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Wolfram Gloger and Doug Lea , 2001. @@ -4563,6 +4563,9 @@ musable(void* mem) mchunkptr p; if (mem != 0) { p = mem2chunk(mem); + + if (__builtin_expect(using_malloc_checking == 1, 0)) + return malloc_check_get_size(p); if (chunk_is_mmapped(p)) return chunksize(p) - 2*SIZE_SZ; else if (inuse(p)) -- cgit v1.1