Life after free?
Eyal Lebedinsky
eyal at delta.canberra.edu.au
Sun Sep 30 10:21:57 AEST 1990
In article <quan.654410256 at sol> quan at sol.surv.utas.oz (Stephen Quan) writes:
>char *funny(ch)
>char ch;
>{
> char *tmp;
> int i;
>
> tmp = (char *) malloc(100);
> for (i=0; i<=99 ; i++) *(tmp+i) = ch;
> free(tmp);
> return tmp;
>}
>
>Any comments on free-ing tmp before it is return-ed?
I hope this is a serious question. You should not use an area after it is freed.
Not only can it be re-used, but some schemes clobber it when it is added to the
free-list (that is, they use some of it for the memory management). Remember that
some C functions allocate memory implicitly, so you cannot trust your memory
just because you do no mallocs after the free().
>
>Stephen Quan (quan at sol.surv.utas.edu.au)
>University of Tasmania.
Regards
Eyal
--
Regards
Eyal
More information about the Comp.lang.c
mailing list