Need more help with malloc() and free() in toolkits

Randy Tidd rtidd at mitre.org
Sat Jan 19 05:21:29 AEST 1991


First let me thank everyone who replied to my previous cry for help
with malloc() bugs so quickly. I got some excellent tools that are not
only public domain, but their authors can be contacted through the
net.

The real problem, I discovered, was with memory that was wasted
through the use of toolkit calls (in this case, the X11 toolkit).
For example, there is a routine called XCreatePixmap() that allocates
space for a pixmap resource and returns a pointer to it. Another call,
XFreePixmap(), will free space previously allocated by a
XCreatePixmap().

Since the actual calls to malloc() and free() are hidden inside the
toolkit routines, tacking a preprocessor-based front end onto the
source code will NOT catch the calls to malloc(), realloc(), calloc(),
etc. that occur in the toolkit code.  However, if a library that
contained routines called malloc(), free(), etc. were linked in, ALL
calls to these routines (including the calls inside the toolkit) can
be caught.

What I need, then, is a way to make a wrapper around the malloc() and
related calls that does NOT require me to recompile the code. Such
wrappers could be used to evaluate ALL calls to the malloc() routines,
wherever they occur.

Doing something like hacking libc.a to rename the already existing
malloc() routines is certainly acceptable, but i'm not sure how to do
that.  I'm desperate!  If I were using ADA it wouldn't be such a
problem...

Again, any help is appreciated.  This is all on a Sun 3/260 running
Sun OS 4.1 with the native cc and gcc 1.39.

Randy Tidd
rtidd at mwunix.mitre.org
"Never mind what's been selling, it's what you're buying."



More information about the Comp.unix.programmer mailing list