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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting Assert errors when my Linked List cleanup method is run

Status
Not open for further replies.

Karl Blessing

Programmer
Feb 25, 2000
2,936
US
for a while this method seemed to do fine, fixed it up a bit<br>debuged it, the pointer addresses seemed valid(not NULL or those 0xdddddd) but yet I get an assertion error in the DebugHeap header file which didnt seem to happen the first couple of times, heres the routine.<br><br>void FileStorage::cleanup()<br>{<br> if(FHead != NULL)<br> {<br> FilePtr* DelMe = NULL;<br> FCurrent = FHead;<br> while(FCurrent != NULL)<br> {<br> DelMe = FCurrent;<br> FCurrent = FCurrent-&gt;next;<br> delete DelMe;<br> }<br> FHead = FCurrent = FEnd = DelMe = NULL;<br> }<br>}<br><br>at the delete DelMe; line is where it crashes, the address before I allowed it to continue past the breakpoint seemed like a valid address each time, and did match the Head pointer. Tho uncertain why this would cause a crash. <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in , or have messed with : VC++, Borland C++ Builder, VJ++6(starting),VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML, ASP(somewhat), QBasic(least i didnt start with COBOL)
 
a bit more detailed info<br>the linked list which i wrote down the address of each node as they were added and double checked before the cleanup function was ran, is read as so:<br><br>0x014b2800 -&gt; 0x014b26d0 -&gt; 0x014b25a0 -&gt; 0x014b2470 .... -&gt; NULL<br><br>now when the command reaches delete DelMe<br>FCurrent = 0x014b26d0<br>DelMe = 0x01462800<br>and FCurrent-&gt;next = 0x014b25a0<br><br>the error i get is<br><br>&quot;<br>DEBUG ERROR!<br>Program: ...OGRAM FILES\MICROSOFT VISUAL STUDIO\COMMON\TOOLS\TSTCON32.EXE<br>DAMAGE: after normal block (#199) at 0x014B2800<br>&quot;<br><br>I notice the error has something do do about the location of the first node, but i dont know what exactly and how to fix it.<br> <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in , or have messed with : VC++, Borland C++ Builder, VJ++6(starting),VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML, ASP(somewhat), QBasic(least i didnt start with COBOL)
 
also i removed the = NULL from where it declares DelMe since its going to be assigned to anyways. <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in , or have messed with : VC++, Borland C++ Builder, VJ++6(starting),VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML, ASP(somewhat), QBasic(least i didnt start with COBOL)
 
I think I notice the problem, gona test it out a bit. it seems I did not put -&gt;next = NULL whenever I add a new node, which would have been obvious to see if i traverse the list, but instead i kept a tail pointer, so the tail was always hanging to some unknown memory address instead of NULL. <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in , or have messed with : VC++, Borland C++ Builder, VJ++6(starting),VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML, ASP(somewhat), QBasic(least i didnt start with COBOL)
 
With giving a null -&gt;next to every new node i create, fixes the prob, only if i comment out the character array in the node, (in otherwords an empty node, with a pointer to the next one) So something with my charater array is causing the problem. <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in , or have messed with : VC++, Borland C++ Builder, VJ++6(starting),VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML, ASP(somewhat), QBasic(least i didnt start with COBOL)
 
if this helps you help me, heres the function that adds a new node<br><br>void FileStorage::add(char &chunker, int count)<br>{<br> FilePtr* TmpPtr = new FilePtr;<br> strcpy(TmpPtr-&gt;AByte,&chunker);<br> TmpPtr-&gt;next = NULL;<br><br> if(FHead == NULL)<br> {<br> FHead=TmpPtr;<br> FEnd = FHead;<br> }<br> else<br> {<br> FEnd-&gt;next = TmpPtr;<br> FEnd = FEnd-&gt;next;<br> }<br> chunks++;<br> bytes+=count;<br>}<br><br>AByte is of type Char[256] <p>Karl<br><a href=mailto:kb244@kb244.8m.com>kb244@kb244.8m.com</a><br><a href= </a><br>Experienced in , or have messed with : VC++, Borland C++ Builder, VJ++6(starting),VB-Dos, VB1 thru VB6, Delphi 3 pro, Borland C++ 3(DOS), Borland C++ 4.5, HTML, ASP(somewhat), QBasic(least i didnt start with COBOL)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top