title: Why valgrind report my memory as "definitely lost"?
body: <p>Consider this code:</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  
  int* alloc()
  {
      return malloc(250 * sizeof(int));
  }
  
  int main()
  {
      int i;
      int *vars[3];
      for(i = 0; i &lt; 3; ++i) {
          vars[i] = alloc();
      }
  }
  </code></pre>
  
  <p>Valgrind output:
  </p>
  
  <pre class="lang-none prettyprint-override"><code>$ valgrind --leak-check=full ./lala
  ==16775== Memcheck, a memory error detector
  ==16775== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
  ==16775== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
  ==16775== Command: ./lala
  ==16775== 
  ==16775== 
  ==16775== HEAP SUMMARY:
  ==16775==     in use at exit: 3,000 bytes in 3 blocks
  ==16775==   total heap usage: 3 allocs, 0 frees, 3,000 bytes allocated
  ==16775== 
  ==16775== 3,000 bytes in 3 blocks are definitely lost in loss record 1 of 1
  ==16775==    at 0x4C2BBA0: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
  ==16775==    by 0x4005B3: alloc (lala.c:5)
  ==16775==    by 0x4005DF: main (lala.c:13)
  ==16775== 
  ==16775== LEAK SUMMARY:
  ==16775==    definitely lost: 3,000 bytes in 3 blocks
  ==16775==    indirectly lost: 0 bytes in 0 blocks
  ==16775==      possibly lost: 0 bytes in 0 blocks
  ==16775==    still reachable: 0 bytes in 0 blocks
  ==16775==         suppressed: 0 bytes in 0 blocks
  ==16775== 
  ==16775== For counts of detected and suppressed errors, rerun with: -v
  ==16775== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
  </code></pre>
  
  <p>According to <a href="http://valgrind.org/docs/manual/mc-manual.html#mc-manual.leaks" rel="nofollow noreferrer">Valgrind's manual</a>:</p>
  
  <blockquote>
    <p>If --leak-check is set appropriately, for each remaining block,
    Memcheck determines if the block is reachable from pointers within the
    root-set. The root-set consists of (a) general purpose registers of
    all threads, and (b) initialized, aligned, pointer-sized data words in
    accessible client memory, including stacks.</p>
  </blockquote>
  
  <p>For what I understand, since the "definitely lost" memory are still pointed to from the <code>main()</code> function's stack, they should be categorized as "still reachable", right?</p>
  
  <p>If not, how can I configure Valgrind to try to reach memory blocks from <code>main</code>'s stack, to determine if they are "still reachable"?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Please don't tell me to <code>free</code> the pointers at the end of <code>main</code>, that is not what I am asking about. For the distinction between "still reachable" and "definitely lost" on Valgrind terms, see this answer: <a href="https://stackoverflow.com/a/3857638/578749">https://stackoverflow.com/a/3857638/578749</a></p>