title: Valgrind... 4 bytes inside a block of size 8 free'd
body: <p>I'm getting this error in Valgrind after attempting to free a list.  print_list dumps the list to the syslog.  I'm pretty confident that output is correct.</p>
  
  <p>Valgrind:</p>
  
  <pre><code>==7028== 1 errors in context 1 of 10:
  ==7028== Invalid read of size 4
  ==7028==    at 0x8049603: free_list (list.c:239)
  ==7028==    by 0x80488B5: m61_close_for_valgrind (m61.c:36)
  ==7028==    by 0x8048825: main (mytest.c:19)
  ==7028==  Address 0x420006c is 4 bytes inside a block of size 8 free'd
  ==7028==    at 0x4028F0F: free (vg_replace_malloc.c:446)
  ==7028==    by 0x804960C: free_list (list.c:239)
  ==7028==    by 0x80488B5: m61_close_for_valgrind (m61.c:36)
  ==7028==    by 0x8048825: main (mytest.c:19)
  ==7028== 
  </code></pre>
  
  <p>mytest.c:</p>
  
  <pre><code>15  char *temp = malloc(10);
  16  char *temp2 = malloc(10);
  17  free(temp);
  18  free(temp2);
  19  m61_close_for_valgrind();
  </code></pre>
  
  <p>list.h</p>
  
  <pre><code>typedef struct lnode {
      ACTIVE_ALLOCATION *value;
      struct lnode *next;
  } lnode;
  </code></pre>
  
  <p>list.c (Called by m61_close_for_valgrind()</p>
  
  <pre><code>void free_list(LIST *s) {
  
      lnode **nptr = &amp;s-&gt;head;
  
      print_list(s);
      while (*nptr) {
          lnode **tmp = nptr;
          tmp = nptr;
  
          if ((*tmp)-&gt;value) {
              syslog(LOG_NOTICE,"Freeing (*tmp)-&gt;value=%p\n", (*tmp)-&gt;value);
              //printf("%p\n",(*nptr)-&gt;value);
              free((*tmp)-&gt;value);    //Free active allocation metadata
          }
  
          nptr = &amp;(*nptr)-&gt;next;
          syslog(LOG_NOTICE,"New *nptr value=%p\n", (*nptr));
  
          syslog(LOG_NOTICE,"Freeing (*tmp)=%p\n", (*tmp));
          free(*tmp);             //Free node
  
      }
  
  }
  </code></pre>
  
  <p>syslog</p>
  
  <pre><code>Sep 19 00:37:02 appliance mytest[7759]:   -- Start List Dump --
  Sep 19 00:37:02 appliance mytest[7759]:   (*nptr)=0x903f220 (*nptr)-&gt;value=0x903f208   (*nptr)-&gt;next=0x903f260  (*nptr)-&gt;value-&gt;ptr=0x903f1f0
  Sep 19 00:37:02 appliance mytest[7759]: (*nptr)-&gt;value-&gt;ptr=0x903f1f0
  Sep 19 00:37:02 appliance mytest[7759]:   (*nptr)=0x903f260 (*nptr)-&gt;value=0x903f248   (*nptr)-&gt;next=(nil)  (*nptr)-&gt;value-&gt;ptr=0x903f230
  Sep 19 00:37:02 appliance mytest[7759]: (*nptr)-&gt;value-&gt;ptr=0x903f230
  Sep 19 00:37:02 appliance mytest[7759]:   -- End List Dump --
  Sep 19 00:37:02 appliance mytest[7759]: Freeing (*tmp)-&gt;value=0x903f208
  Sep 19 00:37:02 appliance mytest[7759]: New *nptr value=0x903f260
  Sep 19 00:37:02 appliance mytest[7759]: Freeing (*tmp)=0x903f220
  Sep 19 00:37:02 appliance mytest[7759]: Freeing (*tmp)-&gt;value=0x903f248
  Sep 19 00:37:02 appliance mytest[7759]: New *nptr value=(nil)
  Sep 19 00:37:02 appliance mytest[7759]: Freeing (*tmp)=0x903f260
  </code></pre>