M
Michael Goerz
Hi,
how can I free a matrix that was created with this function:
double **my_matrix(long number_of_rows, long number_of_columns){
double **matrix;
matrix = calloc(number_of_rows, sizeof(double *));
int i;
for (i = 0; i < number_of_rows; i++){
matrix = calloc(number_of_columns, sizeof(double));
}
return matrix;
}
My guess was this,
void my_free_matrix(double **m, long number_of_rows, long
number_of_columns){
int row;
for (row = 0; row < number_of_rows; row++){
free(m[row]);
}
free(m);
}
but it fails with "*** glibc detected *** double free or corruption
(out): 0xbfbbaa58 ***"
Many Thanks,
Michael Goerz
how can I free a matrix that was created with this function:
double **my_matrix(long number_of_rows, long number_of_columns){
double **matrix;
matrix = calloc(number_of_rows, sizeof(double *));
int i;
for (i = 0; i < number_of_rows; i++){
matrix = calloc(number_of_columns, sizeof(double));
}
return matrix;
}
My guess was this,
void my_free_matrix(double **m, long number_of_rows, long
number_of_columns){
int row;
for (row = 0; row < number_of_rows; row++){
free(m[row]);
}
free(m);
}
but it fails with "*** glibc detected *** double free or corruption
(out): 0xbfbbaa58 ***"
Many Thanks,
Michael Goerz