You need to manage a list of all malloc() you have done with pointer + size. Then you can search for the size in that list, and decrement it in free().

Check for example in that example how they are doing:
http://developers.sun.com/solaris/articles/lib_interposers_code.html#malloc_interposer.c

You might have other possibilities to track memory, like:


Valgrind with massif tool for tracking memory usage over time. You can even generate png output graphics
Interposed libraries. You can found some libraries that you can use by LD_PRELOAD=thelib.so ./yourprogram, and they will output some statistics like jemalloc


(A side note, please accept some answers to your question !)

How to track malloc and free?
I'd like to place all my family's media in one shared folder for everyone to use from any computer.  Whether it's a PC or home server.

What is more appropriate:


Create it in my home folder (/home/lamcro/media/)
Create a new account called media (/home/media/)
or just Create a new folder  (/media/)


As far as I know, there is no "Shared Folder" in Ubuntu, like in Windows.

I'm just looking for the least cumbersome method, in case I ever want to do a full Linux re-install.
