title: Where to free memory, while creating 2d array? valgrind error
body: <p>I am starting to learn dynamic memory allocation. In this code, I have created in <strong>main</strong> function 2d array:</p>
  <pre><code>int r, c;
  scanf(&quot;%d %d\n&quot;, &amp;r, &amp;c);
  size_t row = (size_t) r;
  size_t col = (size_t) c;
  int **board = malloc(row * sizeof(*board));                                                                       
  for (int i = 0; i &lt; r; i++) {                                                                                                     
     board[i] = malloc(col * sizeof(*board[i]));
  }
  </code></pre>
  <p>(I need both int and size_t because of for loops, especially when r&gt;=0, which is always true for size_t).</p>
  <p>Then I change the board with other functions. Valgrind returs:</p>
  <pre><code>==59075== 364 (56 direct, 308 indirect) bytes in 1 blocks are definitely lost in loss record 2 of 2                    
  ==59075==    at 0x483577F: malloc (vg_replace_malloc.c:299)                                                             
  ==59075==    by 0x10B4DB: main (name22.c:122)                                                                        
  ==59075==  
  </code></pre>
  <p>122 line is:</p>
  <pre><code>int **board = malloc(row*sizeof( *board));
  </code></pre>
  <p>I suppose I have to use free(), but after checking other answers I don't know, where is my mistake and where to put free(), if use use this table through the rest of the program. I would appreciate your hints and explanations.
  `</p>