Large memory allocation errors

Russ Allbery rra at stanford.edu
Sun Oct 31 10:28:39 UTC 1999


brister <brister at iengines.com> writes:

> I'll put this in. __FILE__ gets expanded to a string by cpp, and
> __LINE__ turns into an integer:

> 	fprintf(stderr, "%s:%d some error message\n", __FILE__, __LINE__);

> I never seen a cpp that didn't do this.

In that case, don't we want something like this?

In macros.h, change:

#define NEW(T, c)                       \
        ((T *)xmalloc((unsigned int)(sizeof (T) * (c))))

to:

#define NEW(T, c)                       \
        ((T *)xmalloc((unsigned int)(sizeof (T) * (c)), __FILE__, __LINE__))

and likewise for RENEW.  Then fix xmalloc in libinn.h and in lib/xmalloc.c
to take three arguments instead of one, and likewise for xrealloc.  Pass
those arguments to xmemerror if called.  Then you can get the actual file
and line number where the call to NEW() or RENEW() was located.  You'll
need to fix the error handlers in expire/fastrm.c and innd/innd.c as well.

If you just modify the fprintf(), I think you'd always get xmalloc.c as
the file, since it'll be compiled into xmemerr....

-- 
Russ Allbery (rra at stanford.edu)         <URL:http://www.eyrie.org/~eagle/>


More information about the inn-workers mailing list