Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uwm.edu!ogicse!oregon!jmeissen From: jmeissen@oregon.oacis.org (John Meissen) Newsgroups: comp.sys.amiga.tech Subject: Re: De-Allocating Memory? Keywords: Lattice 5.04? Message-ID: <492@oregon.oacis.org> Date: 9 May 90 19:05:02 GMT References: <12750@wpi.wpi.edu> Organization: Oregon Advanced Computing Institute (OACIS), Beaverton, OR Lines: 27 In article S.J.Raybould@fulcrum.bt.co.uk (Simon Raybould) writes: >You need a recursive routine to free the whole list, along the lines of > >freelist(ptr) >struct listelement *ptr; >{ > if(ptr->Next) > freelist(ptr->Next); /* Recurse */ > if(ptr) > free(ptr); >} This is exactly the routine the original poster had listed, except he didn't bother to check the validity of 'ptr' before freeing it. In that respect, your routine has a bug, because if there is a chance of the pointer being invalid you should check it BEFORE dereferencing it: if (ptr) { if (ptr-Next) freelist(ptr-Next); free(ptr); } -- John Meissen ............................... Oregon Advanced Computing Institute jmeissen@oacis.org (Internet) | "That's the remarkable thing about life; ..!sequent!oacis!jmeissen (UUCP) | things are never so bad that they can't jmeissen (BIX) | get worse." - Calvin & Hobbes