I am using Valgrind to debug my c program. The error I receive is:
==2765== 8,000 bytes in 2 blocks are definitely lost in loss record 1 of 1
==2765== at 0x4C274A8: malloc (vg_replace_malloc.c:236)
==2765== by 0x404123: main (mycode.cpp:352)
Here is the code near line 352:
int **matrix;
matrix = (int**)malloc(2*sizeof(int*));
for (i=0; i<2; i++){
matrix[i] = (int*)malloc(size*sizeof(int)); //line 352
}
for (i=0; i<2; i++){ //inizialization
for (k=0; k<size; k++)
matrix[i][k] = 0;
}
That is my way to allocate memory for a matrix. What is wrong with this?
Update: At the end of the program, I used:
free(matrix);