|
From: John R. <jr...@bi...> - 2012-10-22 23:58:45
|
> I was willing to go with the "naughty" way and whatever workarounds it > required, if it meant not having to start wrapping all of our > allocations. The intended way to do this is by "intercepting", "superseding", or "over-riding" the symbol 'malloc': Make your own shared library containing a malloc() routine, and load it into your app via environment variable LD_PRELOAD, so that calls from the app to malloc() go to your LD_PRELOADed library. Your malloc can do whatever it wants, probably including finding the "real" malloc by dlsym(RTLD_NEXT, "malloc") and calling that as a subroutine. See the manual page for dlsym. Remember to "#define _GNU_SOURCE 1" before "#include <dlfcn.h>". -- |