hey guys i have a little project i need to write a program that can calculate two matrix and put the sum in triple pointer,for first i need to allocate memory for triple pointer .
my problem is that when i try to free i got error
i will show you the relevant parts of the code/
the Error is :
__fastfail(FAST_FAIL_STACK_COOKIE_CHECK_FAILURE);
Code:
int mat_mul(float m1[ROWS][COLS], float m2[ROWS][COLS], float *** C){
int i, j;
float temp[6], temp1[6];
float res[ROWS][COLS];
allocate_mem(C);
read_file("data_q.csv", temp, temp1);
for (i = 0; i < 6; i++) {
GetValue(&m1[ROWS][COLS], &m2[ROWS][COLS], temp, temp1, i);
multiply(&m1[ROWS][COLS], &m2[ROWS][COLS], C);
if (C!=NULL)
return 1;
else
return -1;
}
}
Code:
void multiply(float mat1[][COLS], float mat2[][COLS], float res[][COLS]) {
int i, j, k;
for (i = 0; i <= COLS; i++)
{
for (j = 0; j <= COLS; j++)
{
res[i][j] = 0;
for (k = 0; k <= COLS; k++)
res[i][j] += mat1[i][k] * mat2[k][j];
}
}
}
Code:
void deallocate_mem(float*** arr) {
for ( int i = 0; i < COLS; i++)
free((*arr)[i]);
free(*arr);
}
Code:
void allocate_mem(float*** arr){
*arr = (float**)malloc(COLS * sizeof(float*));
for (int i = 0; i < COLS; i++)
(*arr)[i] = (float*)malloc(ROWS * sizeof(float));
Code:
void GetValue(float m1[ROWS][COLS], float m2[ROWS][COLS],float* q1,float* q2,int i) {
m1[0][0] = m1[1][1] = cos(q1[i]);
m2[0][0] = m2[1][1] = cos(q2[i]);
m1[0][2] = m1[1][2] = m2[0][2] = m2[1][2] = 0;
m1[0][1] = sin(q1[i]);
m2[0][1] = sin(q2[i]);
m1[1][0] = -sin(q1[i]);
m2[1][0] = -sin(q2[i]);
m1[2][2] = 1;
m2[2][2] = 1;
m1[2][0] = 0.5*cos(q1[i]);
m2[2][0] = 0.5*cos(q2[i]);
m1[2][1] = 0.5*sin(q1[i]);
m2[2][1] = 0.5*sin(q2[i]);
}