Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!rutgers!rochester!pt.cs.cmu.edu!dsl.pitt.edu!pitt!amanue!oglvee!norm From: norm@oglvee.UUCP (Norman Joseph) Newsgroups: comp.lang.c Subject: Re: Life after free? Keywords: free malloc Message-ID: <606@oglvee.UUCP> Date: 28 Sep 90 12:59:11 GMT References: Organization: Oglevee Computer Systems, Connellsville, Pa Lines: 27 In quan@sol.surv.utas.oz (Stephen Quan) writes: >char *funny(ch) >char ch; >{ > char *tmp; > [...] > return tmp; >} >Any comments on free-ing tmp before it is return-ed? 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 variable tmp a number of important properties, one of which is dynamic duration. Dynamic duration means that tmp only "exists" while the function in which it is declared is executing. After returning from the function, there is no guarantee about the value of the now non- existent variable tmp. If you want the variable tmp to retain its value between calls to the function, declare the variable as "static char *tmp". -- Norm Joseph - (amanue!oglvee!norm) cgh!amanue!oglvee!norm@dsi.com, or Oglevee Computer Systems, Inc. ditka!oglvee!norm@daver.bungi.com ---<*>--- "Shucking Usenet oysters in pursuit of a pearl." -- Bill Kennedy