Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!rutgers!mcnc!decvax.dec.com!bacchus.pa.dec.com!rust.zso.dec.com!shlump.nac.dec.com!engage.enet.dec.com!ynotme.enet.dec.com!wallace From: wallace@ynotme.enet.dec.com (Ray Wallace) Newsgroups: comp.lang.c Subject: Re: malloc, a temporary variable, and a linked list (what happens) Message-ID: <2062@engage.enet.dec.com> Date: 19 Sep 90 19:30:41 GMT Sender: news@engage.enet.dec.com Organization: Digital Equipment Corporation Lines: 23 In article <20319@orstcs.CS.ORST.EDU>, duvalj@bionette.cgrb.orst.edu (Joe Duval) writes... >What I really want to know is what happens to the variable temp each time it >is malloced? Does it end up taking up a whole lot of memory or does the >earlier malloced memory get lost? How would I free this? > temp = (linelist *) malloc (sizeof(linelist)); > indata[lines].points = temp; /* retain the top of the list */ You don't want to free the memory that temp is pointing too. The memory is being used to create your list, via indata[lines].points and indata[lines].points->next which keep track of the malloc'ed address'. If at some point you are done using the data from one or all of the lists pointed to by indata[], then you could walk through each of the lists (backwards) and free the memory. --- Ray Wallace (INTERNET,UUCP) wallace@oldtmr.enet.dec.com (UUCP) ...!decwrl!oldtmr.enet!wallace (INTERNET) wallace%oldtmr.enet@decwrl.dec.com ---