I have a program that does operations on a vector, not altering them but just reading once and then writing out what is required based on what is given. My program runs but I get this error at the end;
*** Error in './volimage: double free or corruption (!prev): 0x00000000123c10 ***
I have googled, and it seems the problem is with my destructor, but I can't for the life of me find or solve it.
This is the destructor:
VolImage::~VolImage()
{
std::cout << "Destructor" << std::endl;
//deconstructing the vector of slices
int i, j, k;
for (i = 0; i<size; i++)
{
for (j = 0; j<height; j++)
{
delete[] slices[i][j];
}
delete[] slices[i];
}
slices.clear();
}
The vector was populated using the following:
std::vector<unsigned char**> slices; // data for each slice, in order
//populating vector
int i, j, k;
unsigned char ** rows = new unsigned char*[height];
for (i = 0; i < size; i++)
{
for (j = 0; j < height; j++)
{
unsigned char* cols = new unsigned char[width];
string num = "%d" + j;
fileName = baseName + num + ".raw";
myFile.open(fileName);
for (k = 0; k < width; k++)
{
unsigned char x;
myFile >> x;
cols[k] = x;
}
myFile.close();
rows[i] = cols;
}
slices.push_back(rows);
}
Thanks, a hasty reply would be appreciated as i need to submit this soon