title: An alternative for the deprecated __malloc_hook functionality of glibc
body: <p>I am writing a memory profiler for C and for that am intercepting calls to the <code>malloc</code>, <code>realloc</code> and <code>free</code> functions via malloc_hooks. Unfortunately, these are deprecated because of their poor behavior in multi threaded environments. I could not find a document describing the alternative best practice solution to achieve the same thing, can someone enlighten me?</p>
  
  <p>I've read that a simple <code>#define malloc(s) malloc_hook(s)</code> would do the trick, but that does not work with the system setup I have in mind, because it is too intrusive to the original code base to be suitable for use in a profiling / tracing tool. Having to manually change the original application code is a killer for any decent profiler. Optimally, the solution I am looking for should be enabled or disabled just by linking to an optional shared library. For example, my current setup uses a function declared with <code>__attribute__ ((constructor))</code> to install the intercepting <code>malloc</code> hooks.</p>
  
  <p>Thanks</p>