I have detected 3 leaks that i dont know how to get rid of. could someone look it over and see if they can tell what i am doing wrong?
3 leaks:
\lab1\winery.cpp (22): winery::winery
\lab1\list.cpp (286): list::node::node
\lab1\list.cpp (125): list::insert
Code:
list::~list()
{
node * curr = headByName;
while(headByName)
{
curr = headByName->nextByName;
delete headByName;
headByName = curr;
}
}
Code:
winery::~winery()
{
if(name)
delete[] name;
if(location)
delete[] location;
}
Now the functions where its showing im having the trouble..
Code:
winery::winery(const char * const name, const char * const location, const int acres, const int rating): name( new char[strlen(name)+1] ), location( new char[strlen(location)+1] ),acres(0),rating(0)
{
strcpy( this->name, name );
strcpy( this->location, location );
this->acres = acres;
this->rating = rating;
}
Code:
list::node::node(const winery &winery) : item(winery.getName(), winery.getLocation(), winery.getAcres(), winery.getRating())
{
}
I know i am creating memory here with new.. However, it wont let me delete that..
Code:
void list::insert(const winery& winery)
{
node* wineryNode = new node(winery); // winerynode for adding and sorting name
node* prev = NULL;
node* prevRating = NULL;
node* check = headByName;
node* checkRating = headByRating;
if ( headByName == NULL )
{
headByName = wineryNode;
}
if ( headByRating == NULL)
{
headByRating = wineryNode;
}
while (check != NULL && (strcmp(check->item.getName(), wineryNode->item.getName() ) < 0))
{
prev = check;
check = check->nextByName;
}
if (prev == NULL)
{
headByName = wineryNode;
}
else
{
prev->nextByName = wineryNode;
}
wineryNode->nextByName = check;
while (checkRating != NULL && (checkRating->item.getRating() > wineryNode->item.getRating()))
{
prevRating = checkRating;
checkRating = checkRating->nextByRating;
}
/// Sort for Rating *******************
if (prevRating == NULL)
{
headByRating = wineryNode;
}
else
{
prevRating->nextByRating = wineryNode;
}
wineryNode->nextByRating = checkRating;
}
[/CODE]