I am trying to use strdup/free in the environment where 'malloc' and 'free' are overloaded in dynamic library libtcmalloc_minimal.dylib from google-perftools.
My program brakes with invalid pointer in 'free' since even though /opt/local/lib/libtcmalloc_minimal.0.dylib is loaded and has 'malloc' but 'strdup' in
/usr/lib/libSystem.B.dylib still uses and old 'malloc' in libSystem.B.dylib.
Someone previously suggested using -Wl,-bind_at_load in link comamnd, but it doesn't help.
What is the correct way to completely overload 'malloc'/'free'?
-- tst.C --
#include <string.h>
#include <stdlib.h>
main() {
char *d = strdup("abc");
free(d);
}
-- link command --
g++ -g -o tst tst.C -L/opt/local/lib -ltcmalloc_minimal
--- error from tst ---
src/tcmalloc.cc:372] Attempt to free invalid pointer: 0x1002a0
Abort trap
My program brakes with invalid pointer in 'free' since even though /opt/local/lib/libtcmalloc_minimal.0.dylib is loaded and has 'malloc' but 'strdup' in
/usr/lib/libSystem.B.dylib still uses and old 'malloc' in libSystem.B.dylib.
Someone previously suggested using -Wl,-bind_at_load in link comamnd, but it doesn't help.
What is the correct way to completely overload 'malloc'/'free'?
-- tst.C --
#include <string.h>
#include <stdlib.h>
main() {
char *d = strdup("abc");
free(d);
}
-- link command --
g++ -g -o tst tst.C -L/opt/local/lib -ltcmalloc_minimal
--- error from tst ---
src/tcmalloc.cc:372] Attempt to free invalid pointer: 0x1002a0
Abort trap