C: Segmentation fault when freeing allocated 2D array
Dear all,
I know that seems to be a common question, but information from the web does not help me. So problem is in the title. Here is what I do: First I declare the pointers. Code:
double **rijx,**rijy,**rijz; Code:
rijx = malloc (atom_number*sizeof(double*)); Code:
Then I free the memory by doing Code:
for (i=0;i<=atom_number-1;i++) { I do not see what's going wrong here. Then I do this Code:
(void)free(rijx);(void)free(rijy);(void)free(rijz); So, some hints are more than welcome. Thanks in advance, Éric. |
Quote:
P.S. I did not see anything wrong in the code you posted. Personally I am not fond of seeing if-statement condition such as i <= (N-1), preferring instead i < N .... but that is beside the point. Your code is probably crashing elsewhere. |
Thanks to your post, I looked for elsewhere and solve the issue.
I initialized an array with an index bigger that its size. |
All times are GMT -5. The time now is 11:10 PM. |