[PATCH][BZ #1349] Return requested size for malloc_usable_size when MALLOC_CHECK_ > 0

Siddhesh Poyarekar siddhesh@redhat.com
Fri Aug 31 13:33:00 GMT 2012


On Fri, 31 Aug 2012 15:13:37 +0200, Florian wrote:
> The "7" depends on malloc allocation granularity.  On x86_64, the
> magic number is not 7, but 23, and malloc_usable_size(malloc(7)) ==
> 24.

The magic number is at mem[7], which is chunk[23] for x86_64. For a 4
byte size_t, the magic number will be at chunk[15].

If you check the code of mem2mem_check in hooks.c, you'll see that the
number is explicitly added at mem[requested_size] and not anywhere else:

m_ptr[sz] = MAGICBYTE(p);

so this does not depend on granularity. You have perhaps confused this
with the general case, where malloc_usable_size does depend on
granularity, not in case of MALLOC_CHECK_, where it shouldn't?

Regards,
Siddhesh



More information about the Libc-alpha mailing list