https://bugs.kde.org/show_bug.cgi?id=395109
Bug ID: 395109
Summary: Infinite recursion during initialization when stdlib's
atexit() allocates
Product: Heaptrack
Version: 1.1.0
Platform: Other
OS: Linux
Status: UNCONFIRMED
Severity: normal
Priority: NOR
Component: general
Assignee: [email protected]
Reporter: [email protected]
Target Milestone: ---
Trying to use heaptrack with uClibc stdlib crashes immediately on start due to
infinite recursion.
When a heaptrack's allocation function is called for the first time it calls
::hooks::init(), which then calls atexit(). If the atexit() implementation
allocates then the allocation function in heaptrack is called again, which then
calls ::hooks::init() again etc. etc. leading to an infinite recursion.
Calling heaptrack_init() before atexit() in ::hooks::init() solves the problem,
but I'm not sure if it may have any side effects.
Note that even glibc calls memory allocation functions in its atexit()
implementation. However, it has a preallocated static array for 32 exit
handlers, so heaptrack forcing itself at the beginning of LD_PRELOAD is
unlikely to hit the limit (which would force glibc to allocate another array).
In case of uClibc it can be compiled with or without dynamic allocation in
atexit(), ours is compiled with dynamic allocation enabled and as such it has
no preallocated array.
Bit of a backtrace:
#1 0xb6cac238 in __new_exitfn () at libc/stdlib/_atexit.c:241
#2 0xb6cac098 in __GI___cxa_atexit (func=0xb6edf640 <(anonymous
namespace)::hooks::<lambda()>::_FUN(void)>, arg=0x0, dso_handle=0xb6ef6338
<_dl_getenv+88>) at libc/stdlib/_atexit.c:164
#3 0xb6edf694 in (anonymous namespace)::hooks::init () at
/sources/heaptrack-1.1.0/src/track/heaptrack_preload.cpp:126
#4 0xb6edfaf8 in realloc (ptr=0x0, size=320) at
/sources/heaptrack-1.1.0/src/track/heaptrack_preload.cpp:198
#5 0xb6cac298 in __new_exitfn () at libc/stdlib/_atexit.c:246
#6 0xb6cac098 in __GI___cxa_atexit (func=0xb6edf640 <(anonymous
namespace)::hooks::<lambda()>::_FUN(void)>, arg=0x0, dso_handle=0xb6ef6338
<_dl_getenv+88>) at libc/stdlib/_atexit.c:164
#7 0xb6edf694 in (anonymous namespace)::hooks::init () at
/sources/heaptrack-1.1.0/src/track/heaptrack_preload.cpp:126
#8 0xb6edfaf8 in realloc (ptr=0x0, size=320) at
/sources/heaptrack-1.1.0/src/track/heaptrack_preload.cpp:198
#9 0xb6cac298 in __new_exitfn () at libc/stdlib/_atexit.c:246
#10 0xb6cac098 in __GI___cxa_atexit (func=0xb6edf640 <(anonymous
namespace)::hooks::<lambda()>::_FUN(void)>, arg=0x0, dso_handle=0xb6ef6338
<_dl_getenv+88>) at libc/stdlib/_atexit.c:164
#11 0xb6edf694 in (anonymous namespace)::hooks::init () at
/sources/heaptrack-1.1.0/src/track/heaptrack_preload.cpp:126
#12 0xb6edfaf8 in realloc (ptr=0x0, size=320) at
/sources/heaptrack-1.1.0/src/track/heaptrack_preload.cpp:198
#13 0xb6cac298 in __new_exitfn () at libc/stdlib/_atexit.c:246
#14 0xb6cac098 in __GI___cxa_atexit (func=0xb6edf640 <(anonymous
namespace)::hooks::<lambda()>::_FUN(void)>, arg=0x0, dso_handle=0xb6ef6338
<_dl_getenv+88>) at libc/stdlib/_atexit.c:164
#15 0xb6edf694 in (anonymous namespace)::hooks::init () at
/sources/heaptrack-1.1.0/src/track/heaptrack_preload.cpp:126
#16 0xb6edfaf8 in realloc (ptr=0x0, size=320) at
/sources/heaptrack-1.1.0/src/track/heaptrack_preload.cpp:198
--
You are receiving this mail because:
You are watching all bug changes.