Life after free?
Conor P. Cahill
cpcahil at virtech.uucp
Sat Sep 29 09:22:47 AEST 1990
In article <606 at oglvee.UUCP> norm at oglvee.UUCP (Norman Joseph) writes:
>In <quan.654410256 at sol> quan at sol.surv.utas.oz (Stephen Quan) writes:
>
>>char *funny(ch)
>>char ch;
>>{
>> char *tmp;
>> [...]
>> return tmp;
>>}
>
>No, but I -do- have a comment on returning tmp at all. The storage
>class in the declaration of tmp defaults to "auto". This gives the
However, if tmp is a pointer and you return the value contained in
the pointer, who cares about tmp. It is just used during the
exection of the function. The fact that tmp is no longer a valid
variable outside of this function will have no effect on the
availability of the data at the malloc'd region that tmp pointed to
while it existed.
Note that I am NOT saying that you can free(tmp) and then return it. If
the free was not there, the use of tmp would be totally correct.
--
Conor P. Cahill (703)430-9247 Virtual Technologies, Inc.,
uunet!virtech!cpcahil 46030 Manekin Plaza, Suite 160
Sterling, VA 22170
More information about the Comp.lang.c
mailing list