Sandeep Singh
Sandeep Singh

Reputation: 5191

Converting malloc() calls into external Library Calls in C

I am writing an open-source tool for run-time memory issue debugging:

https://github.com/sandeepsinghmails/S_malloc

The current version requires the user to change his/her wrapper functions for malloc() and free() and call two additional functions from my library.

I want to modify this code so that the user's malloc() and free() calls are automatically mapped to my own implementations. The user need not modify his source code (something which Valgrind provides).

Can somebody please guide me on this?

Upvotes: 0

Views: 202

Answers (1)

Alexander Atanasov
Alexander Atanasov

Reputation: 496

Take a look at malloc_hooks:

http://man7.org/linux/man-pages/man3/malloc_hook.3.html

The GNU C library lets you modify the behavior of malloc(3), realloc(3), and free(3) by specifying appropriate hook functions. You can use these hooks to help you debug programs that use dynamic memory allocation, for example.

Upvotes: 3

Related Questions