Assuming that we have already allocated a 2D array of doubles with both dimensions > 1, using this to free it will result in a memory leak, yes?Code:void free_2D(double **array) { free(array[0]); free(array); }
Because I was sure that you needed to loop over the second dimensions and free each array[i] separately before freeing array, but this is part of a code that seems to work. So am i wrong about how things are freed, or is it working only because it coincidentally doesnt run out of memory?
it should be (I think?)
Code:void free_2D(double **array, int xdim) { int i = 0; for (i = 0; i < xdim; i++) { free(array[i]); } free(array) }