Mail Archives: djgpp/1997/08/21/03:29:18
Bill Currie writes:
> That's your problem: fopen calls malloc which (for you) calls fopen
> which calls malloc... I got tipped off by esp in your stack dump
> being so low.
Been there, done that - my solution was to explicitly test
for recursion, and only do the print if it's not recursing.
So in malloc do something like:
void*
malloc(size_t size)
{
static bool recurse = false;
if (!recurse)
{
recurse = true;
mprintf(...);
recurse = false;
}
/* do alloc stuff... */
}
This stops it trying to print while printing. You might also want to
provide a sparate function to allocate memory while 'recurse' is set,
this can be very simple and reset itself after returning from the
print (on the assumption that the C library functions are well-behaved).
Chris C
- Raw text -