Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!uakari.primate.wisc.edu!aplcen!uunet!ontek!mikey From: mikey@ontek.com (michelle (krill-woman) lee) Newsgroups: comp.lang.c Subject: Re: Why 'life after free'. Message-ID: <1384@ontek.com> Date: 5 Oct 90 00:51:34 GMT References: <1990Sep30.163824.12974@ibmpcug.co.uk> <1990Oct2.104509.1744@funet.fi> Followup-To: emptiness Organization: Ontek Corporation -- Laguna Hills, California Lines: 27 | > char * | > funny(c) | > char c; | > { | > static char a[100]; | > int i; | > | > for (i=0 ; i<99 ; i++) a[i] = c; | > a[99] = '\0'; | > return (&a[0]); | > } | > | | With this function call's like | printf( "%s %s\n", funny( 'x' ), funny( 'y' ) ); | do not work as expected. This sort of thing wouldn't work with malloc/free as originally proposed either. If funny freed the block its return pointer pointed at, the second invocation (not necessarily the one for y, btw) might cause malloc to stomp on the thing that was just freed, before printf even has a chance to print it. It's either that or don't free it and get a memory leak. Better solutions have been mentioned elsewhere in this thread of articles, i.e. using variables in the caller to store the result. the krill, i/o bound