This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH][BZ #1349] Return requested size for malloc_usable_sizewhen MALLOC_CHECK_ > 0


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]