I want to write a "simple" memory leak checker.
In order to do that I need to count a number of the malloc()
ed memory blocks in a program,
but the problem that I do not want to modify it's source.
In other words, I want to implement the following interface:
memory_check <executable name>
Where I do not have an access to the executable's source.
Firstly I supposed to try intercept a system call. But I read "So malloc doesn't invoke any syscall?" and it doesn't seem to be an idea, also because of it will extremely slow all system (as I can suppose).
Are there any other options to intercept the malloc()
calls?
If you're willing to change your interface to LD_PRELOAD=mymalloc.so <executable>
you can do it like so:
malloc
using dlsym
void *malloc(size_t size)
malloc
via the handle obtained above, and also stores your debug infoThen:
LD_PRELOAD=mymalloc.so ./program
malloc
If you don't want to change your interface but want to use this trick you can make a wrapper program that fork(2)
s, sets up LD_PRELOAD
and then execs your real program using its name.
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