title: Invalid read of size 8 - Valgrind + C
body: <p>Valgrind reports error <code>Invalid read of size 8</code> in the following code. </p>
  
  <p>I have an array declared like,</p>
  
  <pre><code>struct symbol *st[PARSER_HASH_SIZE];
  </code></pre>
  
  <p>When my program is initialized, all the elements in this array are initailzied as 0. </p>
  
  <pre><code>memset(&amp;st[0], 0, sizeof(st));
  </code></pre>
  
  <p>My program creates instances of <code>struct symbol</code> and inserts into the above array depending on the hash value. So few of the elements in this array will be NULL and others will be valid value. </p>
  
  <p>The following code tries to delete the allocated items and valgrind complains at the line,
  <code>sym = st[i]; sym != NULL; sym = sym-&gt;next</code></p>
  
  <pre><code>struct symbol *sym = NULL;
  
  /* cleaning the symbol table entries */
  for(i = 0; i &lt; PARSER_HASH_SIZE; i++) {
      for(sym = st[i]; sym != NULL; sym = sym-&gt;next) { /* &lt;-- Valgrind complains here */
          free(sym);
      }
  }
  </code></pre>
  
  <p>I am trying to understand the reason for this error. </p>
  
  <p>Any help would be great!</p>