how to free the whole memory chunk for a matrix (which was reserved at once)?
#define ROWS 2
#define COLS 3
int (*p)[COLS] = malloc (sizeof (*p) * ROWS);
// not important
for (size_t i = 0; i < ROWS; i++) {
for (size_t j = 0; j < COLS; j++) {
p[i][j] = rand() % 10;
}
}
// not important
for (size_t i = 0; i < ROWS; i++) {
for (size_t j = 0; j < COLS; j++) {
printf ("%d\t", p[i][j]);
}
putchar ('\n');
}
//is that right ???
free (p);
I know, I could allocate memory for this matrix in another way, but that's not the question.
The question ist, how to work with this chunk of memory in the right way.
EDIT: I'm asking because of this valgrind summary:
==1684==
==1684== LEAK SUMMARY:
==1684== definitely lost: 0 bytes in 0 blocks
==1684== indirectly lost: 0 bytes in 0 blocks
==1684== possibly lost: 0 bytes in 0 blocks
==1684== still reachable: 176 bytes in 1 blocks
==1684== suppressed: 4,096 bytes in 1 blocks
==1684==
I thought I have some memory leaks.