free (NULL)

Richard Tobin richard at aiai.ed.ac.uk
Thu May 31 20:55:46 AEST 1990


In article <3078 at goanna.cs.rmit.oz.au> ok at goanna.cs.rmit.oz.au (Richard A. O'Keefe) writes:

 [Description of the all-too-common problem of not knowing whether it's safe
  to free something.]

One approach (which of course only solves part of the problem) is to
write your own allocator, with a free() function that ignores attempts
to free space that it didn't allocate.  It can do this in various
ways, such as looking at the pointer to see whether it's in the range
of addresses it allocates (I suppose this is not strictly portable, as
it will involve comparing pointers to different objects, but maybe you
don't care about *that* sort of processor).

This of course will further enrage those people who object to free(0),
who needn't bother flaming about sloppy programming, thank you.

-- Richard
-- 
Richard Tobin,                       JANET: R.Tobin at uk.ac.ed             
AI Applications Institute,           ARPA:  R.Tobin%uk.ac.ed at nsfnet-relay.ac.uk
Edinburgh University.                UUCP:  ...!ukc!ed.ac.uk!R.Tobin



More information about the Comp.lang.c mailing list