I am using a structure defined as follows
struct gene_square
{
double *x;
double *y;
};
I have class, with a member function which is a pointer of this type:
gene_square* m_Genes;
I am allocating memory in the constructors like this:
m_Genes = new gene_square[square_genome_size];
for (ii=0; ii<square_genome_size; ii++)
{
(m_Genes+ii)->x = new double[POINTS];
(m_Genes+ii)->y = new double[POINTS];
}
And my destructor does this:
if(m_Genes != NULL)
{
for(ii=0; ii<square_genome_size; ii++)
{
if (((m_Genes+ii)->x)!=NULL)
{
delete [] (m_Genes+ii)->x;
}
if (((m_Genes+ii)->y)!= NULL)
{
delete [] (m_Genes+ii)->y;
}
}
delete [] m_Genes;
}
But when the destructor is called I am getting a glibc double free error.
*** glibc detected *** ./Evolution: double free or corruption (fasttop): 0x08055008 ***
And I can't work it out.
Anyone able to help?