[comp.unix.wizards] free

keogh@nixeid.UUCP (Paul Keogh) (03/08/90)

I had a problem recently with a large application which supports the standard
shell globbing characters. The code for the globbing support was almost
exclusively lifted from the csh source. Under certain conditions, the         
application would crash on the next malloc call after the globbing operations.

Inspection of the code showed that a block freeing routine in the code called
free() whereas the equivalent csh code called a routine called xfree().  

xfree(c)
char *c;
{
	extern char end[];

	if (c >= end && c < (char *) &c)
		free(c);
}

I put this code into my application and the problem disappeared. 

Why is this check necessary ? Does the fix indicate that a previous malloc
/free operation was invalid ?.Opinions please.

Thanx,
Paul Keogh.
keogh@u.nix.ie

chris@mimsy.umd.edu (Chris Torek) (03/10/90)

In article <25@nixeid.UUCP> keogh@nixeid.UUCP (Paul Keogh) writes:
>... code ... lifted from the csh source ... would crash ... [in] malloc ...
>... equivalent csh code called a routine called xfree():

[with] xfree(c) char *c; { if (c >= end && c < (char *) &c) free(c); }

>Why is this check necessary?

The check is necessary because Bill Joy was lazy.

The csh globbing code is wrong (or, if you prefer, `machine dependent').
xfree() is a hack to compensate for this.

-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris@cs.umd.edu	Path:	uunet!mimsy!chris