Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Okay well I have a method that adds nodes to my linked list, now this seems to be written the same was that everyone else online writes their linked list, however when my program exits I always get a bunhc of memory leaks from the line in my code where "temp = new SatID;". I have tried many different ways to delete this pointer, however the program always crashes if I do. Can you guys tell me why no one else seems to have to delete this pointer, and yet I keep getting error msgs??? Thanks for the help,
void CEmailDownloaderDlg::OnCheckAndAdd()
{
// THIS SECTION IS FOR GETTING RESULTS FROM THE DATABASE ////////////
MYSQL_RES *result;
MYSQL_ROW row;
unsigned int num_fields;
char * qry = new char[300];
//SELECT CONCAT(last_name,', ',first_name) AS full_name FROM mytable ORDER BY full_name;
sprintf(qry, "SELECT SatelliteID, SatEmail from satellite");
//int slt = mysql_query(conn33,qry);if (mysql_query(conn33, qry)) {
//Error querry didn't complete
return;
}
else { // query succeeded, process any data returned by it
result = mysql_store_result(conn33);
if (!result) {// there are no rows
//error
return;
}
num_fields = mysql_num_fields(result);while ((row = mysql_fetch_row(result))) {
SatID * temp;
SatID * temp2;
unsigned long *lengths;
lengths = mysql_fetch_lengths(result);
for(int i = 0; i < (int)num_fields; i++)
{
sprintf(qry, "[%.*s] ", (int) lengths[i], row[i]);
CString mystring = qry;
}temp = new SatID;
temp->SatelliteID=atoi(row[0]);
temp->SatEmail=row[1];
temp->next_SatID=NULL;
if (mySatIDs==NULL) {
mySatIDs = temp;
continue;
}
temp2=mySatIDs;
while (temp2->next_SatID!=NULL)
temp2=temp2->next_SatID;temp2->next_SatID=temp;
}
}
delete [] qry;
}(BTW - my structure is defined as)
struct SatID {
int SatelliteID;
CString SatEmail;
SatID * next_SatID;
};and mySatIDs is originally set to = NULL

I hope i am following your code correctly, if so, in your deconstructor try something like this:
SatID *temp;
while(MySatIDs != null)
{
while(MySatIDs->next_SatID != null){
temp = MySatIDs->next_SatID;
}
temp = null;
delete temp;
}
MySatIDs = null;
delete MySatIDs;
ChiThey mostly come at night...mostly

Chi, thank you very much for the response, that is EXACTLY correct. I kept wondering how I could delete that pointer without it deleting the things it was pointing to...LoL, now I know :) Thanks for the help.

i think there may be an issue actually:
SatID *temp;
while(MySatIDs != null)
{
temp = MySatIDs;
while(temp->next_SatID != null){
temp = temp->next_SatID;
}
temp = null;
delete temp;
}
MySatIDs = null;
delete MySatIDs;
try this.Chi
They mostly come at night...mostly

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |