LD_PRELOAD causing Segmentation fault for linux commands
I have a .so file which is used for finding memory leaks. I set the LD_PRELOAD env variable in the session in which I want to execute my target binary. export LD_PRELOAD=./memleakfinder.so But once this environment variable is set, even a simple linux command like ls or ps is causing a Segmentation fault (core dumped). Why is that happening?I've overloaded versions of malloc(),calloc(),realloc(),free(),new,new etc. in that .so file. The automatic bug reporting tool of CentOS6 is saying: source:coreutils Problem:process /bin/ls was killed by signal 11(SIGSEGV). Clearly the library injection is causing the problem here. How can I avoid it?
Instead of exporting an environmental variable, prepend the variable to the command you want to run/debug.
And the library will only be loaded for this one invocation of a.out instead of all commands in the current shell.
We cannot help you determine the cause of the segmentation fault without seeing some code.