Commit c8dc17c6 authored by François Trigaux's avatar François Trigaux
Browse files

🐛 fixed mem leaks: free all strings "line", deallocate TFs, correct initialize of init_cond

parent 9720d189
......@@ -15,7 +15,7 @@ void initBeam(Beam *bm)
char *section;
dataINI fileBeam = readINIFile("Beam.ini");
char* line = NULL;
char* line = NULL; // don't forget to free!
ssize_t read;
int frmt;
size_t len = 0;
......@@ -204,50 +204,48 @@ void initBeam(Beam *bm)
// Initialize conditions from file
ALLOCATE2(bm->init_cond , double , bm->nelem , 12);
if(bm->analysis_flag==2){
if (bm->initFromFile==1)
for (i=0;i<bm->nelem;i++)
{
for (j=0;j<2*NSTRN;j++)
{
// READ INITIAL CONIDITIONS FROM THE FILE
FILE *INIT = fopen("Beam_initCond.ini","r");
if (INIT==NULL)
{
printf("Cannot read %s\n","Beam_init.dat");
exit(EXIT_FAILURE);
}
for (i=0;i<bm->nelem;i++)
{
READL(line,len,INIT);
frmt = sscanf(line,"%lf %lf %lf %lf %lf %lf",&bm->init_cond[i][0],&bm->init_cond[i][1],&bm->init_cond[i][2],&bm->init_cond[i][3],&bm->init_cond[i][4],&bm->init_cond[i][5]); CHKFRMT(frmt,6);
}
for (i=0;i<bm->nelem;i++)
{
READL(line,len,INIT);
frmt = sscanf(line,"%lf %lf %lf %lf %lf %lf",&bm->init_cond[i][6],&bm->init_cond[i][7],&bm->init_cond[i][8],&bm->init_cond[i][9],&bm->init_cond[i][10],&bm->init_cond[i][11]); CHKFRMT(frmt,6);
}
fclose(INIT);
bm->init_cond[i][j] = 0.0;
}
else
{
for (i=0;i<bm->nelem;i++)
{
for (j=0;j<2*NSTRN;j++)
{
bm->init_cond[i][6] = 0.0;
}
}
}
if((bm->analysis_flag==2) && (bm->initFromFile==1))
{
// READ INITIAL CONIDITIONS FROM THE FILE
FILE *INIT = fopen("Beam_initCond.ini","r");
FILE *INIT = fopen("Beam_initCond.ini","r");
FILE *INIT = fopen("Beam_initCond.ini","r");
if (INIT==NULL)
{
printf("Cannot read %s\n","Beam_init.dat");
exit(EXIT_FAILURE);
}
for (i=0;i<bm->nelem;i++)
{
READL(line,len,INIT);
frmt = sscanf(line,"%lf %lf %lf %lf %lf %lf",&bm->init_cond[i][0],&bm->init_cond[i][1],&bm->init_cond[i][2],&bm->init_cond[i][3],&bm->init_cond[i][4],&bm->init_cond[i][5]); CHKFRMT(frmt,6);
}
for (i=0;i<bm->nelem;i++)
{
READL(line,len,INIT);
frmt = sscanf(line,"%lf %lf %lf %lf %lf %lf",&bm->init_cond[i][6],&bm->init_cond[i][7],&bm->init_cond[i][8],&bm->init_cond[i][9],&bm->init_cond[i][10],&bm->init_cond[i][11]); CHKFRMT(frmt,6);
}
fclose(INIT);
}
ALLOCATE3(bm->sol_pt , double , bm->nstep , bm->nkp , NDIM + NDOF_ND); //for each point there are 12 variables
ALLOCATE3(bm->sol_mb , double , bm->nstep , bm->nelem, NDIM + bm->ndof_el); // for each element, there are 18 variables
free(line);
}
......@@ -543,7 +541,7 @@ void beam_setTwistFromFile(Beam *bm, char *fname)
double coeff;
double x,*xp,*twistp,*twist;
char* line = NULL;
char* line = NULL; //don't forget to free!
ssize_t read;
int frmt;
size_t len = 0;
......@@ -603,6 +601,8 @@ void beam_setTwistFromFile(Beam *bm, char *fname)
DEALLOCATE1(twistp);
DEALLOCATE1(xp);
free(line);
fclose(fid);
......@@ -684,8 +684,7 @@ void beam_analysis(Beam *bm)
{
int i;
char *error;
int nev;
char *error="";
// Transform every pointer >1D into 1D pointers
......@@ -720,7 +719,7 @@ void beam_analysis(Beam *bm)
bm->ncurv,&rav_coord,&rav_member,&(bm->pt_condition),&material_tmp,bm->niter,bm->nstep,
&rav_sol_pt,&rav_sol_mb,error,bm->ncond_mb,bm->ntimefun,&rav_frame,&(bm->mb_condition),&rav_distr_fun,
&rav_curvature,bm->omega_a0,bm->omega_a_tf,bm->v_root_a0,bm->v_root_a_tf,bm->simu_time,
&bm->time_function,bm->analysis_flag,&rav_init_cond,&nev,&rav_eigen_val,&rav_eigen_vec_pt,&rav_eigen_vec_mb,bm->initialize);
&bm->time_function,bm->analysis_flag,&rav_init_cond,&bm->nev,&rav_eigen_val,&rav_eigen_vec_pt,&rav_eigen_vec_mb,bm->initialize);
// Transform 1D pointers to 2D pointers if necessary
UNRAVEL2(bm,coord,bm->nkp,NDIM,double);
......@@ -830,7 +829,7 @@ void freeBeam(Beam *bm)
// Free time-functions
//for (i=0;i<bm->ntimefun;i++)
// freeTimeFunction(&time_function[i]);
//DEALLOCATE1(time_function); // freeTF
DEALLOCATE1(bm->time_function); // freeTF
DEALLOCATE1(bm->mb_condition); // freePrescriInf
DEALLOCATE1(bm->pt_condition); //freePrescriInf
......@@ -901,7 +900,7 @@ static void beam_setMaterial(Beam *bm)
double *xcomp, *xmass;
double x;
char* line = NULL;
char* line = NULL; //don't forget to free!
ssize_t read;
int frmt;
size_t len = 0;
......@@ -994,6 +993,9 @@ static void beam_setMaterial(Beam *bm)
DEALLOCATE1(xmass);
DEALLOCATE3(matMass,ncomp,NSTRN);
}
free(line);
fclose(COMP);
fclose(MASS);
}*/
......@@ -1002,7 +1004,7 @@ static void beam_setMaterial(Beam *bm)
static void beam_setMaterial(Beam *bm)
{
int i,j,k;
char* line = NULL;
char* line = NULL; //don't forget to free
ssize_t read;
int frmt;
size_t len = 0;
......@@ -1115,6 +1117,8 @@ static void beam_setMaterial(Beam *bm)
// DEALLOCATE1(xmass);
// DEALLOCATE3(matMass,1,1);
//}
free(line);
fclose(COMP);
fclose(MASS);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment