john said:
I want to override the global malloc and free and am lacking on
ideas.
You cannot override 'malloc()' and/or 'free()': these functions are
part of the standard C library and the implementation may make
assumption about the implementation of these functions. However, on
typical platforms it is possible to replace the definition by
tweaking the standard library which is normally just some file in a
well defined format, e.g. 'libc.a' on UNIX systems. Of course, you
need to make sure that your library version is used and not some
other one (e.g. 'libc.so' on UNIX systems when building with shared
libraries). Also note, that you need to normally have to replace the
whole family of allocation functions (i.e. also 'realloc()' and
'calloc()' and possibly others) to make it work.
Things are *much* easier if you are using the C++ memory allocation
functions which you should do in C++ anyway: these functions can be
replaced portably! Of course, every class may also individually
provide a pair of allocation/deallocation functions which makes it
effectively impossible to guarantee that your version is used...
I guess you are looking for memory problems. In this case, you might
want to have a look e.g. at "efence" for a free library replacing
the allocation functions for memory debugging (or libhoard for an
example of how the memory functions can be replaced). A much better
approach to memory debugging is, however, the use of somethign like
Purify which unfortunately is not free...