Hi!, im new in this forum (and programming in c :)) (and sorry, my english is not good enough, I speak spanish)

I have a problem trying to release memory from a Matrix structure.

When I try to release a square matrix there is no problem, i can do it, if I try to realease a Matrix with more columns than rows i have not problem, but if i have more rows than columns my application failed.

Here is my code:**For the creation of the matrix (a matrix of 1s):**

```
Mat* newmatrix(int a,int b)
{
Mat *matri=(Mat*)malloc(sizeof(Mat));
matri->row=a;
matri->co=b;
matri->data=(int**)malloc(a*sizeof(int*));
int j;
for ( j=0 ; j<a ; j++ )
{
matri->data[j] = (int*)malloc(b*sizeof(int));
}
int x,y;
for ( x=0; x<a;x++)
{
for (y=0;y<a;y++)
{
mat_set(matri,x,y,1);
}
}
return matri;
}
```

For matrix release of memory:

```
void freemat (Mat* matrix)
{
int j;
for (j=0;j<(m->row);j++)
{
free(matrix->data[j]);
}
free(matrix->data);
free(matrix);
}
```

I will really appreciate your help, Thank you!!

Carlos.