On OS X, setting the MallocStackLogging environment variable before running a program will cause malloc(3) and free(3) to record the stack each time they are called for each memory region. This is particularly useful for debugging memory corruption issues, as you can go back through the history of the region that has been corrupted and figure out what part of the code was/should have been responsible for the memory.
I understand that I could use __malloc_hook on Linux to write my own implementation of this debugging facility, but I wonder if there isn't some easier way to accomplish the same thing? What's the recommended way to track allocations on Linux?
I have never heard of that feature. If it weren't possible, though, you could still wrap them around some function which would accomplish that.
Or, consider a memory analyzer (heap-user-after-free, memory leak, buffer overflow and so on) such as valgrind or AddressSanitizer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With