Mail Archives: djgpp/1997/12/02/19:16:46
jstuder AT flash DOT net wrote:
>
> On Thu, 27 Nov 1997 16:35:47 GMT, Christopher Croughton
> <crough45 AT amc DOT de> wrote:
>
> >Try tracing each malloc() and free().
> >
> >Chris C
> Is there any 'easier' way to trace each malloc and free? I am not
> sure I am freeing everything like I want to and wondered if there was
> any easier way of tracing rather than looking for each malloc and free
> line by line.
>
write wrapper functions my_debug_malloc, my_debug_realloc, my_debug_free
do a
#ifdef DEBUG
#define malloc my_debug_malloc
#define realloc my_debug_realloc
#define free my_debug_free
e.g.
void* my_debug_malloc(size_t n)
{
char *p;
fprintf(debug_file, "Request for %lu bytes:", n);
p = malloc(n);
fprintf(debug_file, "Allocated at %p\n", p);
return p;
}
this is probably no the best way to implement this, but if all you are
doing is to match up malloc's and free's its quick, and works ok.
--
----------------------------------------------------------------------
A. Sinan Unur
Department of Policy Analysis and Management, College of Human Ecology,
Cornell University, Ithaca, NY 14853, USA
mailto:sinan DOT unur AT cornell DOT edu
http://www.people.cornell.edu/pages/asu1/
- Raw text -