[PATCH] glibc: Apply patch for easy analysis of malloc issue
Akash Hadke
hadkeakash4@gmail.com
Wed Jan 20 15:42:02 GMT 2021
The function __malloc_tcache_walk added in this patch provides
information of entire heap memory chunk in the core file.
This patch provides the address and value of the memory chunk illegally
written, which can help to understand and debug the issue.
Used below CPP code for testing purpose.
============================================================================
typedef std::size_t Item;
const std::size_t nItemsWanted = 64 / sizeof (Item);
Item *const paItems1 = new Item [nItemsWanted];
{
std::fill (paItems1, paItems1 + nItemsWanted, Item
(0x8899AABBCCDDEEFF));
}
delete [] paItems1;
paItems1 [0] = 0x00214E414D544142;
Item *const paItems3 = new Item [nItemsWanted];
Item *const paItems4 = new Item [nItemsWanted];
============================================================================
This code fails and produce coredump below is the log of backtrace
Without proposed patch:
(gdb) bt
#0 0x00007ff12b8f8407 in _GI__libc_malloc (bytes=64) at
/usr/src/debug/glibc/2.27-r0/git/malloc/malloc.c:3068
#1 0x00007ff12c261b48 in operator new(unsigned long) () from
/usr/lib/libstdc++.so.6
#2 0x000055c2db586645 in main () at
/usr/src/debug/qtbase/5.6.2+gitAUTOINC+b4ada3f0d8-r0/Example-of-Buggy-Program-v2.cpp:22
(gdb) x/8gx e
Value can't be converted to integer.
With proposed patch:
(gdb) bt
#0 __malloc_tcache_walk (ptcache=0x55b28b3d0010, tc_idx=tc_idx@entry=3,
e=e@entry=0x55b28b3e1e70)
at /usr/src/debug/glibc/2.27-r0/git/malloc/malloc.c:2949
#1 0x00007f90e5abc53a in tcache_get (tc_idx=3) at
/usr/src/debug/glibc/2.27-r0/git/malloc/malloc.c:2984
#2 _GI__libc_malloc (bytes=64) at
/usr/src/debug/glibc/2.27-r0/git/malloc/malloc.c:3096
#3 0x00007f90e6425b48 in operator new(unsigned long) () from
/usr/lib/libstdc++.so.6
#4 0x000055b28a44263b in main () at
/usr/src/debug/qtbase/5.6.2+gitAUTOINC+b4ada3f0d8-r0/Example-of-Buggy-Program-v2.cpp:21
(gdb) x/8gx e
0x55b28b3e1e70: 0x00214e414d544142 0x000055b28b3d0010
0x55b28b3e1e80: 0x8899aabbccddeeff 0x8899aabbccddeeff
0x55b28b3e1e90: 0x8899aabbccddeeff 0x8899aabbccddeeff
0x55b28b3e1ea0: 0x8899aabbccddeeff 0x8899aabbccddeeff
ChangeLog:
2021-01-20 Akash Hadke <hadkeakash4@gmail.com>
[BZ #27216]
* malloc/malloc.c: Add new function __malloc_tcache_walk.
--
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Patch-for-better-analysis-of-malloc-issue.patch
Type: text/x-patch
Size: 3595 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20210120/7c72194a/attachment.bin>
More information about the Libc-alpha
mailing list