Yeah.. if you look in free_extra_descr,
    ed->next = extra_descr_free;
it changes ec->next to the free extra description list.
So the next iteration of the for loop, you'll be freeing something in the free 
list.
Which leads to bad things.

The other problem was that pObj->extra_descr was never being set to NULL.  It 
was
left pointing to a freed, invalid extra description.

----- Original Message ----- 
From: "Richard Lindsey" <[EMAIL PROTECTED]>
To: "Valnir" <[EMAIL PROTECTED]>; <[email protected]>
Sent: Thursday, January 22, 2004 10:59 PM
Subject: RE: Clearing extra descriptions


> i don't know if this same rule applies, but this line has been drilled into 
> my head
over the years:
>
> After extract_char the ch is no longer valid!
>
> This usually is the case anytime you're freeing items in a linked list... if 
> you
run a for loop and cycle through a list and free the item in question each 
iteration,
then when it hits the end of the statement list and tries to loop, item->next is
going to be equal to NULL since the item itself just got freed... this is the 
purpose
of the ed_next, it reserves a spaceholder pointing to the next element in the 
list so
that when the previous one gets freed, it still has a way to reference the next 
one
in the list...
>
> wavewave
> Richard Lindsey.
>
> -----Original Message----- 
> From: Valnir [mailto:[EMAIL PROTECTED]
> Sent: Thu 1/22/2004 10:41 PM
> To: [email protected]
> Cc:
> Subject: Re: Clearing extra descriptions
>
>
>
> Sometimes the "ed = ed_next" and "ed_next = ed->next" has been known to give
> me a few headaches.
>
> Try this method instead.
>
> for ( ed = pObj->extra_descr; ed; ed = ed->next )
> {
>     send_to_char( "Freeing Extra Desc '%s'.\n\r", ed->keyword );
>     free_extra_descr( ed );
> }
>
> ----- Original Message -----
> From: "Hiddukel" <[EMAIL PROTECTED]>
> To: <[email protected]>
> Sent: Thursday, January 22, 2004 10:45 PM
> Subject: RE: Clearing extra descriptions
>
>
> > I also have this in my code but it only deletes one extra description at a
> > time.  I need a clear command to remove all the extra descriptions.
> >
> > -----Original Message-----
> > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Valnir
> > Sent: Thursday, January 22, 2004 7:22 PM
> > To: [email protected]
> > Subject: Re: Clearing extra descriptions
> >
> > Don't know if this will help, but here is how ours is done (using "delete"
> > instead of clear)
> >
> >     if ( !str_cmp( command, "delete" ) )
> >     {
> >         EXTRA_DESCR_DATA *ped = NULL;
> >
> >         if ( keyword[0] == '\0' )
> >         {
> >             send_to_char( "Syntax:  ed delete [keyword]\n\r", ch );
> >             return FALSE;
> >         }
> >
> >         for ( ed = pObj->extra_descr; ed; ed = ed->next )
> >         {
> >             if ( is_name( keyword, ed->keyword ) )
> >                 break;
> >             ped = ed;
> >         }
> >
> >         if ( !ed )
> >         {
> >             send_to_char( "OEdit:  Extra description keyword not
> > found.\n\r", ch );
> >             return FALSE;
> >         }
> >
> >         if ( !ped )
> >             pObj->extra_descr = ed->next;
> >         else
> >             ped->next = ed->next;
> >
> >         free_extra_descr( ed );
> >
> >         send_to_char( "Extra description deleted.\n\r", ch );
> >         return TRUE;
> >     }
> >
> > - Valnir
> > ----- Original Message -----
> > From: "Hiddukel" <[EMAIL PROTECTED]>
> > To: <[email protected]>
> > Sent: Thursday, January 22, 2004 7:16 PM
> > Subject: Clearing extra descriptions
> >
> >
> > I am seriously confused on this. What I am trying to do is clear all of
> the
> > extra descriptions from an object. I can add any number of extra
> > descriptions to an object but when I try to clear them using this code it
> > always leaves the first one. I have seen this exact same method used in
> olc
> > delete functions and I can't for the life of me figure out why it leaves
> the
> > first one in the list. Btw, I also get output saying that it is clearing
> > the first extra description even though it remains after the clear.
> >
> > Here is the code in question:
> > if (!str_cmp(command, "clear"))
> > {
> > EXTRA_DESCR_DATA *ed_next = NULL;
> >
> > for (ed = pObj->extra_descr; ed; ed = ed_next)
> > {
> > ed_next = ed->next;
> > ptc(ch, "Clearing exra description: %s\n\r", ed->keyword);
> > free_extra_descr(ed);
> > }
> >
> > return TRUE;
> > }
> >
> > I will also post the free_extra_descr function even though I believe it is
> > stock.
> >
> > void free_extra_descr(EXTRA_DESCR_DATA * ed)
> > {
> > if (!IS_VALID(ed))
> > return;
> >
> > free_string(ed->keyword);
> > free_string(ed->description);
> > INVALIDATE(ed);
> >
> > ed->next = extra_descr_free;
> > extra_descr_free = ed;
> > }
> >
> > If I am not mistaken clearing affects from objects would be done in a
> > similar way also, if I am mistaken about that then I would like to know
> how
> > that is done as well. I appreciate any and all help on this
> >
> >
> >
> > --
> > ROM mailing list
> > [email protected]
> > http://www.rom.org/cgi-bin/mailman/listinfo/rom
> >
>
>
> --
> ROM mailing list
> [email protected]
> http://www.rom.org/cgi-bin/mailman/listinfo/rom
>
>
>  N2f)+-D  !  0  +   Yb ~


Reply via email to