[PATCH][BZ #1349] Return requested size for malloc_usable_size when MALLOC_CHECK_ > 0
Siddhesh Poyarekar
siddhesh@redhat.com
Fri Aug 31 13:03:00 GMT 2012
On Fri, 31 Aug 2012 14:38:22 +0200, Andreas wrote:
> > + memset (p, 0, malloc_usable_size (p));
> > + free (p);
> > + return 0;
>
> In this case malloc_usable_size () should return >= 7, so I suggest
> to check for that value as well. The memset/free is a good idea!
When MALLOC_CHECK_ is exported as a positive value (which I am doing
for this test), malloc_usable_size should return exactly 7, since the
malloc_check code adds a magic number at p[7] if p is the mem pointer.
Anything greater than that and the user may risk writing over the magic
value and tripping an assertion during free.
But I get your point; I will add a check to ensure that usable_size ==
7, lest it returns a value less than 7 due to some future bug. Updated
patch attached.
Regards,
Siddhesh
-------------- next part --------------
A non-text attachment was scrubbed...
Name: malloc-usable.patch
Type: text/x-patch
Size: 5854 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20120831/4cdf3090/attachment.bin>
More information about the Libc-alpha
mailing list