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?
I had this same problem when trying to override the malloc function.
For me, I was using printf()
in my function declaration of malloc()
(to see if it was working).
When I switched to write()
instead or printf()
, it worked. This is because some library functions, such as printf, may allocate memory for their operation. Consequently, if you use any of those functions in your library you risk getting into an infinite recursion.
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