Path: utzoo!attcan!uunet!virtech!cpcahil From: cpcahil@virtech.uucp (Conor P. Cahill) Newsgroups: comp.lang.c Subject: Re: Life after free? Keywords: free malloc Message-ID: <1990Sep28.232247.24199@virtech.uucp> Date: 28 Sep 90 23:22:47 GMT References: <606@oglvee.UUCP> Reply-To: cpcahil@virtech.UUCP (Conor P. Cahill) Organization: Virtual Technologies Inc., Sterling VA Lines: 29 In article <606@oglvee.UUCP> norm@oglvee.UUCP (Norman Joseph) writes: >In quan@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