title: VALGRIND invalid read of size 8, linked list, freeing nodes
body: <p>I'm trying to identify the reason why Valgrind is complaining.</p>
  
  <p>If somebody could give me a hint so that I can understand why my code is generating bad behaviour I would be very grateful.</p>
  
  <p>I've created an array of structures. Each entry is the beginning of a linked list made out of structs. Now I'm at the Point where I want to free the elements of each linked list of that array of structs.</p>
  
  <p>But Valgrind is saying:</p>
  
  <pre><code>==15084== Memcheck, a memory error detector
  ==15084== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
  ==15084== Using Valgrind-3.10.0 and LibVEX; rerun with -h for copyright info
  ==15084== Command: /tmp/3RKi4ZeFa74f-a.out tests/16_allPositive output/ausgabe_16_allPositive
  ==15084== 
  ==15084== Invalid read of size 8
  ==15084==    at 0x402006: reset (1441261801.c:807)
  ==15084==    by 0x402489: main (1441261801.c:927)
  ==15084==  Address 0x51e0de8 is 8 bytes inside a block of size 16 free'd
  ==15084==    at 0x4C29E90: free (vg_replace_malloc.c:473)
  ==15084==    by 0x401FF5: reset (1441261801.c:809)
  ==15084==    by 0x402489: main (1441261801.c:927)
  ==15084== 
  ==15084== Invalid read of size 8
  ==15084==    at 0x401FEA: reset (1441261801.c:809)
  ==15084==    by 0x402489: main (1441261801.c:927)
  ==15084==  Address 0x51e0d48 is 8 bytes inside a block of size 16 free'd
  ==15084==    at 0x4C29E90: free (vg_replace_malloc.c:473)
  ==15084==    by 0x401FF5: reset (1441261801.c:809)
  ==15084==    by 0x402489: main (1441261801.c:927)
  ==15084== 
  ==15084== Invalid read of size 8
  ==15084==    at 0x401FFA: reset (1441261801.c:807)
  ==15084==    by 0x402489: main (1441261801.c:927)
  ==15084==  Address 0x51e0d48 is 8 bytes inside a block of size 16 free'd
  ==15084==    at 0x4C29E90: free (vg_replace_malloc.c:473)
  ==15084==    by 0x401FF5: reset (1441261801.c:809)
  ==15084==    by 0x402489: main (1441261801.c:927)
  ==15084== 
  ==15084== 
  ==15084== HEAP SUMMARY:
  ==15084==     in use at exit: 0 bytes in 0 blocks
  ==15084==   total heap usage: 119 allocs, 119 frees, 7,787 bytes allocated
  ==15084== 
  ==15084== All heap blocks were freed -- no leaks are possible
  ==15084== 
  ==15084== For counts of detected and suppressed errors, rerun with: -v
  ==15084== ERROR SUMMARY: 51 errors from 3 contexts (suppressed: 0 from 0)
  </code></pre>
  
  <p>That seems to be the faulty function</p>
  
  <pre><code>    void reset()
   784: {
   785:   //lösche alle (zeiger)char *arrays der conti structs
   786:   for(int i = 0; i &lt; zeile1; i++)
   787:   {
   788:   struct node *p = &amp;conti[i];
   789:   if((*p).next != NULL)
   790:   {
   791:       for(; (*p).next != NULL; p=(*p).next)
   792:       {
   793:                   free((*p).volume);
   794:       }
   795:                   free((*p).volume);
   796:   }else if ((*p).next == NULL)
   797:   {
   798:                   free((*p).volume);
   799:       }
   800:   }
   801:   //lösche die listenelemente der jeweiligen container
   802:   for(int i = 0; i &lt; zeile1; i++)
   803:   {
   804:   struct node *p = &amp;conti[i];
   805:   if((*p).next != NULL)
   806:   {
   807:       for(; (*p).next != NULL; p=(*p).next)
   808:       {
   809:                   free((*p).next);
   810:       }
   811:   }
   812:   }
   813:   //lösche die (zeiger)input char *arrays
   814:   for (int j = 0; j &lt; zeile2; j++)
   815:   {
   816:       free(input[j].volume);
   817:       }
   818:   //lösche die struct arrays
   819:       free(conti);
   820:       free(input);
   821: }
  </code></pre>
  
  <p>The structures look like this:</p>
  
  <pre><code>  16: struct node {
    17:   char *volume;
    18:   struct node *next;
    19:   };
  </code></pre>
  
  <p>I'm looking forward for your help.</p>