free (NULL)

Peter da Silva peter at ficc.ferranti.com
Sat Jun 2 03:29:47 AEST 1990


In article <270:Jun113:33:1590 at stealth.acf.nyu.edu> brnstnd at stealth.acf.nyu.edu (Dan Bernstein) writes:
> In article <9YT3MP at xds13.ferranti.com> peter at ficc.ferranti.com (Peter da Silva) writes:
> > In article <3466:May3022:56:1890 at stealth.acf.nyu.edu> brnstnd at stealth.acf.nyu.edu (Dan Bernstein) writes:

> > > Namely: Whatever you allocate inside a routine, you also deallocate
> > > inside that routine. If your memory needs are variable, provide enough
> > > information to your callers that they can allocate for you. (This is
> > > called ``passing the buck.'')

> > I disagree with this entirely.

> So what are you disagreeing with?

The paragraph quoted above.

Consider a routine "readline(fp)". this (hypothetical) routine reads in
a line of text and allocates and returns a pointer to it. It appears that
you do not believe that this is a reasonable thing to do. Please correct
me if I am misinterpreting your message.

Consider the commonly implemented routine "strdup" that allocates a copy
of a string and returns a pointer to the copy.

The model of pulling fully-formed "things" out of a pool, manipulating
them, and eventually dropping them back in is perfectly valid and often
useful.

> I don't think I'm totally off base,
> because Boyd Roberts made the same three-way classification in a
> simultaneous article.

He didn't make any hard-and-fast rule about never returning a malloc-ed
chunk of memory to ones parent. Just make sure that the interface is
properly documented and consistent.
-- 
`-_-' Peter da Silva. +1 713 274 5180.  <peter at ficc.ferranti.com>
 'U`  Have you hugged your wolf today?  <peter at sugar.hackercorp.com>
@FIN  Dirty words: Zhghnyyl erphefvir vayvar shapgvbaf.



More information about the Comp.lang.c mailing list