Question

writing my own version of malloc() (and his best friend Mr. free()), I need to know if I free'd my memory correctly. Seems that I can't use valgrind because it checks for the libc'malloc, and mine is in a shared library loaded with LD_PRELOAD.

Currently if I use valgrind it says "0alloc 0free 0leak, everything is good", because it does not detect the allocations I did with MY malloc. (I use (s)brk() functions)

Does someone know if there's a way to check with valgrind anyways or with sth else ?

Thanks !

Was it helpful?

Solution

Looks like there are two possible solutions:

--soname-synonyms

If your custom allocator functions are still called malloc() and free(), use the --soname-synonyms command line parameter to tell Valgrind to look for these functions in your preloaded library. It can then automatically intercept calls to these functions. Example:

--soname-synonyms=somalloc=mymalloclib.so

See http://valgrind.org/docs/manual/manual-core.html#manual-core.rareopts for details.

Client Requests

If you have a more complicated custom allocator (with an API different from malloc()/free()), you can use special "client requests" in your malloc()/free() implementation to tell Valgrind about the structure of your memory pool. See http://valgrind.org/docs/manual/mc-manual.html#mc-manual.mempools for details.

I haven't tested either of these solutions :-) so would be nice to hear whether it actually works for you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top