Bug 474856 - attaching heaptrack to process induces some unwanted side effects on static function pointers
Summary: attaching heaptrack to process induces some unwanted side effects on static f...
Status: REPORTED
Alias: None
Product: Heaptrack
Classification: Applications
Component: general (show other bugs)
Version: 1.1.0
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Milian Wolff
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-09-25 14:17 UTC by vincent.lemaout
Modified: 2023-09-25 14:17 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
code snippet demonstrating the issue (480 bytes, text/x-c++src)
2023-09-25 14:17 UTC, vincent.lemaout
Details

Note You need to log in before you can comment on or make changes to this bug.
Description vincent.lemaout 2023-09-25 14:17:28 UTC
Created attachment 161858 [details]
code snippet demonstrating the issue

SUMMARY
After attaching heaptrack to the process, a static function pointer is "redirected" to the heaptrack hook for free() but this pointer doesn't point to libc free()

STEPS TO REPRODUCE
1.  Compile the attached code snippet with g++ -g -fPIC testfree.cpp -o testfree
2.  Run ./testfree
3.  Attach heaptrack to testfree process

OBSERVED RESULT
The output is :
testfree now points to heaptrack hook though it wasn't pointing to libc free anymore

EXPECTED RESULT
I would expect no output since the pointer doesn't point to libc free() anymore (there is therefore no reason why it should point to heaptrack hook), this is a real problem because what you would have allocated with a custom allocator up to the moment heaptrack is attached, will be freed by heaptrack by calling libc free() instead of the custom free()

SOFTWARE/OS VERSIONS
Observed on Scientific Linux release 7.9 (Nitrogen)

ADDITIONAL INFORMATION
Of course, removing -fPIC from the compilation option will neutralize heaptrack but we'd like to use it for profiling our custom allocator