For debugging purposes, it can sometimes be easier to include a header file &quot;mem_debug.h&quot; or whatever, and redefine malloc:<p><pre><code>  &gt;#define malloc(a) debug_malloc(a, __FILE__, __LINE__)
  &gt;#define free(a)   debug_free(a, __FILE__, __LINE__)
  &gt;.
  &gt;.
  &gt;.
</code></pre>
Then in your debug_malloc() function you can track where every allocation took place. Not always applicable but nice when it works.