[PATCH][BZ #1349] Return requested size for malloc_usable_size when MALLOC_CHECK_ > 0
Siddhesh Poyarekar
siddhesh@redhat.com
Fri Aug 31 06:03:00 GMT 2012
Hi,
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. The attached patch
does exactly that.
There is also a test case included in the patch to verify that the
problem is fixed. I have verified on Fedora-16 x86_64 that this does
not cause any regressions.
Regards,
Siddhesh
ChangeLog:
* malloc/Makefile (tests): Add tst-malloc-usable test case.
(tst-malloc-usable-ENV): Set environment for test case.
* malloc/hooks.c (malloc_check_get_size): New function to get
requested size.
* malloc/malloc.c (musable): Use malloc_check_get_size.
* malloc/tst-malloc-usable.c: New test case.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: malloc-usable.patch
Type: text/x-patch
Size: 5664 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20120831/4ff2eef4/attachment.bin>
More information about the Libc-alpha
mailing list