Implementing tool that tracks down C memory errors, finding where my overrided malloc etc is called from

216 views Asked by At

I've been asked to implement a tool ( for linux ) which helps with the memory management of C/C++ programs. Main objective is to track down memory leaks but I am also checking for overlapping arguments to memcpy among other things.

I actually need my versions to intercept all calls to these functions ( from other libraries for example ) so I actually need to override them. So I can't use the #define trick suggested in all the posts. My question is how I am going to find the original source file name , function where the call was made and the line number.

My only idea so far is to compile the program with debugging info and start digging in on the object file ( ELF as I am using linux ). I've never played with object files and I only know the basics of assembly language so this seems a pretty hefty task.

Is there any other easier way to achieve this? If not anyone who has worked on something similar can help me get it started :)?.

Thank you

1

There are 1 answers

0
bdonlan On BEST ANSWER

Since you're on Linux, you can use glibc's malloc hook support. A working example is also provided on that page.