Skip to content

Commit

Permalink
Back to malloc/free - but postpone free until end of function scope...
Browse files Browse the repository at this point in the history
  • Loading branch information
willend committed Feb 26, 2024
1 parent a1fb0d4 commit 1b6d18c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions mcstas-comps/samples/Isotropic_Sqw.comp
Original file line number Diff line number Diff line change
Expand Up @@ -1381,7 +1381,7 @@ struct Sqw_Data_struct *Sqw_readfile(
Sqw->compname, file, Sqw->type=='c' ? "coh" : "inc");
);

double w_file2full[w_bins]; /* lookup table for fast file -> Sqw_full allocation */
double *w_file2full = malloc(w_bins*sizeof(double)); /* lookup table for fast file -> Sqw_full allocation */

for (index_w=0; index_w < w_bins; w_file2full[index_w++]=0);

Expand Down Expand Up @@ -1422,7 +1422,7 @@ struct Sqw_Data_struct *Sqw_readfile(
w_file2full[index_w] = index_w_file;
}

double q_file2full[q_bins];
double *q_file2full=malloc(q_bins*sizeof(double));
for (index_q=0; index_q < q_bins; q_file2full[index_q++]=0);

for (index_q=0; index_q < q_bins; index_q++) {
Expand Down Expand Up @@ -1932,7 +1932,8 @@ struct Sqw_Data_struct *Sqw_readfile(
Sqw->compname, Sqw->lookup_length);
);
}

free(w_file2full);
free(q_file2full);
return(Sqw_Data);
} /* end Sqw_readfile */

Expand Down

0 comments on commit 1b6d18c

Please sign in to comment.