Life after free?

Stephen Clamage steve at taumet.com
Fri Sep 28 07:18:43 AEST 1990


quan at sol.surv.utas.oz (Stephen Quan) writes:

>  char *tmp;
>  tmp = (char *) malloc(100);
>  ...
>  free(tmp);
>  return tmp;

>Any comments on free-ing tmp before it is return-ed?

I believe this is in the FAQ, which should always be checked before
asking basic questions.  You might also RTFM.

However:  The contents of the malloc'd memory may be changed by free().
In any event, some routine may come along and acquire that space,
possibly asynchronously, and overwrite it even if free() doesn't.
What problem are you trying to solve by using a pointer to free'd space?
-- 

Steve Clamage, TauMetric Corp, steve at taumet.com



More information about the Comp.lang.c mailing list