Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bizarre Seg Fault

Status
Not open for further replies.

csjay

Programmer
Apr 17, 2003
1
US
I'm using a simple linked list class and have found that the delete statement is causing a seg fault- the program using it periodically calls the clear function, and on certain inputs the program crashes at the delete statement. I have no idea what is causing it and would appreciate any suggestions~

bool clear()
{
bool isCleared=false;
Node * curNode=Head;

if(Head != NULL)
isCleared=true;

while(curNode != NULL)
{
Head=curNode->next;
delete curNode; <-------
curNode=Head;
}
curNode=NULL;

CurPos=-1;
SizeOf=0;
Current=NULL;
Head=NULL;
Tail=NULL;

return isCleared;
}
 
It may be impossible to tell from what you have posted, but a wild guess would be that if some of your other code could ever cause the condition curNode == curNode->next i think you would see the behavior you describe.

-pete

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top