i have a multithreaded program that does the following:

i'm getting all sorts of weird errors. i'm not sure what more i need. do i need to have a malloc and a free for aa? do i need to do additional allocation or deallocation for S? please help.Code://global variables double ***T; //T is the temporary array of matrices double ***S; //S is the global version of A for the thread function int *aa; //aa is the global version of a for the thread function int matrnum; //the number of the matrix currently being calculated //function called by each thread void *calc_row(void * t_num) { ..... ..... ..... } double **programY(double ***A, int *a, int mat_num) { #ifdef SESC sesc_init(); #endif double **result; int i, j; T = (double ***) malloc((mat_num)*sizeof(double **)); S = (double ***) malloc((mat_num)*sizeof(double **)); T[0] = A[0]; S=A; aa=a; for(i=1; i<mat_num; i++) { T[i] = (double **)malloc(a[0]*sizeof(double *)); for(j=0; j<a[0]; j++) { T[i][j] = (double *)malloc(a[i+1] * sizeof(double)); } } ....... ....... ....... for(i=1; i<mat_num-1;i++) { for(j=0; j<a[0]; j++) { free(T[i][j]); } free(T[i]); } free(T); return result; }

this file (programy.c) is actually accessed by a different program (matmult.c) using:

extern double **programY(double ***A, int *a, int mat_num);

i don't know if that makes a difference.

here's a variable list:

Tis an array of matrices used for storing results and is accessed in calc_row()

Ais an array of matrices

Sis a global version ofAaccessed in calc_row()

ais an array of integers

aais a global version ofaaccessed in calc_row()

matrnumis not the same asmat_num, but is incremented in programY() after the threads finish

t_numis the number of the row currently being worked on

mat_numis the number of matrices inA