validity of free() on later pointer operations

Doug Schmidt schmidt at indetech.com
Wed Jul 4 04:50:32 AEST 1990


Hi,

	Several months ago there was a big discussion on comp.lang.c
about the legality/portability of the following sort of code:

----------------------------------------
void
foo (n)
	int n;
{
	char *malloc ();

	char *s = malloc (n);
	/* ... */
	free (s);
	s = 0; /* Is this assignment always legal? */
	/* ... */
}
----------------------------------------

	I seem to recall there was a problem with the assignment to
char *s *after* the free.  Can someone please refresh my memory
as to what the problem was, and why it is a problem?  Would
replacing s = 0 by s = malloc (n) have the same problem?

	thanks,
	
		Doug
-- 
____*_  Douglas C. Schmidt          schmidt at indetech.com
\  / /  Independence Technologies   {sun,sharkey,pacbell}!indetech!schmidt
 \/ /   42705 Lawrence Place        FAX: 415 438-2034
  \/    Fremont, CA 94538           Voice: 415 438-2023



More information about the Comp.lang.c mailing list