Why use -lmalloc

Ken Nelson nelson at wrl.epi.com
Thu Apr 4 03:02:44 AEST 1991


 We just ported our product to HP-UX and could not get it
 to work with the normal allocation routines.  In fact
 we couldn't get it to work with -lmalloc as well.  BUT
 when we used -lmalloc we got error messages out that made
 sense (other than core dump) and we were able to fix the
 problem.

 -lmalloc offered diagnostic warnings that normal
  alloc didn't.  It notified us when the program
  tried to allocate a block of space of size 0.  The
  normal alloc just returned a bad address that we
  used until we corrupted something and the program
  died far away from the bad code.


Of course we could have prevented this by putting a wrapper
around any call to malloc that checked for valid requests and
valid answers. Normally we do, but this code was inherited from
another company (Sun Microsystems XView library).  By the way
the request for zero space works okay on every other system
we have ported XView to (Sun3, Sun4, Dec, Concurrent, Apollo,
Convex, and more).

So this isn't just a testimonial for -lmalloc, but a call
for more defensive programming.


 --------------------------------------------------------------------
| Ken Nelson  (nelson at wrl.epi.com) | No thoughts today, sorry.	     | 
| Computer Systems Manager         |				     |
| Entropic Research Laboratory     |				     |	
| Washington, D.C.		   |				     |
|--------------------------------------------------------------------



More information about the Comp.lang.c mailing list