Re: Problems with Linked Lists

From: Sammy (samedi@DHC.NET)
Date: 09/25/97


On Thu, 25 Sep 1997, Rasdan wrote:

> void load_player_index(void)
> {
>   struct player_index_element pie;
>
>   /* Open file stuff here -- This part is easy */
>
>   while (fscanf(index, "%s %s", name, idnum) != EOF) {
>     if (pie.name) {
>       free (pie.name);
>       pie.name = NULL;
>     }

It's also the broke part :)  First, you can't assume that pie.name will
be initialized to NULL on the first pass.  It's ok now, but you may have
problems with another compiler when you try to free a nonexistant pointer.

As for your name problem, look at what you're doing here.  On each pass
after the first, you're freeing pie.name.  Since pie.name is the name of
the last player you loaded from the index, you're destroying what you've
just done.  You can safely take that whole if(pie.name) part out without
worrying about a memory leak.

Sam


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/08/00 PST