Bug 474856

Summary: attaching heaptrack to process induces some unwanted side effects on static function pointers
Product: [Applications] Heaptrack Reporter: vincent.lemaout
Component: generalAssignee: Milian Wolff <mail>
Status: REPORTED ---    
Severity: normal    
Priority: NOR    
Version First Reported In: 1.1.0   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: code snippet demonstrating the issue

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