Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!elroy.jpl.nasa.gov!decwrl!mcnc!borg!tsc!warner From: warner@tsc.cs.unc.edu (Byron Warner) Newsgroups: comp.lang.c Subject: Re: Deleting linked lists. Keywords: C, C++. Message-ID: <2655@borg.cs.unc.edu> Date: 27 Mar 91 16:48:15 GMT References: <2636@borg.cs.unc.edu> Sender: news@cs.unc.edu Distribution: na Organization: University of North Carolina, Chapel Hill Lines: 25 Thanks to all of you who responded, to my post. To summarize: In general it is not safe to assume anything about the contents of freed data. Most people suggested using a temporary variable, ie: struct list *next; while (ptr) { next = ptr->next; free(ptr); ptr = next; } but also some one suggested recursion: void listfree(List *l) { if (l->next != NULL) listfree(l->next); free(l->data); free(l); } -- ---- Byron F. Warner warner@cs.unc.edu University of North Carolina - Chapel Hill Computer Sci Department "The opinions expressed here should be yours."