title: Trying to understand behavior when freeing allocated memory
body: <p>I have code that functions like this:</p>
  
  <pre><code>void** array;
  array = malloc(8*sizeof(void*));
  </code></pre>
  
  <p>And if I put, say, three elements into the array and try:</p>
  
  <pre><code>int i = 0;
  for(i; i &lt; 8; i++)
     free(array[i]);
  </code></pre>
  
  <p>It fails after 6 iterations of the loop. But if I populate the entire array (with 8 elements), the for loop executes just fine. I've tried this with 18 as well, and the loop fails after 9 iterations, but if I populate the whole thing it executes fine.</p>
  
  <p>Can someone please explain what's happening here?</p>