Mail Archives: djgpp/1995/04/28/17:35:43
>I think I've traced the leak to the linked list objects I use, can anyone spot
>what is wrong here:
>
>private:
>listnode *Current,*Root
>
>LinkedList::~LinkedList(void)
>{
>for(Current = Root; Current!=NULL; Current=Current->next)
> delete Current;
>}
I do not know that much about C++, but I do know C and you should write the
above as:
listnode *next;
Current = Root;
while (Current != NULL)
{
next = Current->next;
delete Current;
Current = next;
}
There is no guarantee that the next field of current has any meaning once
Current is deleted. The above fragment gets it before Current is deleted.
--John
- Raw text -