Hi!

I'm supposed to do some matrix handling functions for a school project. But i'm having trouble with function that frees memory allocated for the matrix. I use

to allocate the memory. AndCode:`retMatrix=(double **)malloc(rows*sizeof(double *));`

for(i=0;i<rows;i++)

{

retMatrix[i]=(double *)malloc(columns*sizeof(double));

}

to free it but the destructor gives a memory handling error when i run it my program with walgrind. I know that the problem is matrix[i]!=NULL but i cant think of any other way to determine what is the last row of the matrix. Use of global variables is not allowed. Anyone got ideas?Code:`void matrixDestruct(double **matrix)`

{

int i=0;

while(matrix[i]!=NULL)

{

free(matrix[i]);

i++;

}

free(matrix);

}