title: Valgrind reports a memory error when trying to free a malloc'ed struct
body: <p>Valgrind always nags that there is a memory error when a previously malloc'ed struct is free'd. The struct looks as follows:</p>
  
  <pre><code>typedef struct bullet
  {
    int x, y;
    struct bullet * next;
  } BULLET;
  </code></pre>
  
  <p>... and I allocate the memory by using</p>
  
  <pre><code>BULLET * b;
  b = malloc(sizeof(BULLET)); // sizeof(BULLET) is 16
  </code></pre>
  
  <p>and later on, the struct is free'd by simply calling <code>free(b);</code>. Valgrind however doesn't seem to be satisfied by this, and so it tells me</p>
  
  <pre><code>==2619== Invalid read of size 8
  ==2619==    at 0x40249F: ctrl_bullets (player.c:89)
  ==2619==    by 0x405083: loop_game (game.c:305)
  ==2619==    by 0x406CCA: main (main.c:47)
  ==2619==  Address 0x5b8d818 is 8 bytes inside a block of size 16 free'd
  ==2619==    at 0x4C29A9E: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
  ==2619==    by 0x402E04: rm_bullet (player.c:329)
  ==2619==    by 0x402485: ctrl_bullets (player.c:95)
  ==2619==    by 0x405083: loop_game (game.c:305)
  ==2619==    by 0x406CCA: main (main.c:47)
  </code></pre>
  
  <p>Of course I can't just allocate only 8 bytes, because that would be the size needed to store the pointer, and not the size of the struct - so why does Valgrind keep telling me that there is an error?</p>
  
  <p><em>Edit</em>: Some more code which could be relevant ...</p>
  
  <pre><code>void
  ctrl_bullets(WINDOW * w_field, BULLETLIST * lb)
  {
    if (lb-&gt;num &gt; 0)
    {
      BULLET * b;
  
      for (b = lb-&gt;head; b != NULL; b = b-&gt;next) // player.c:89
      {
        if (b-&gt;x &gt; CON_FIELDMAXX)
        {
          write_log(LOG_DEBUG, "Bullet %p is outside the playing field; x: %d; "
                    "y: %d\n", (void *) b, b-&gt;x, b-&gt;y);
          rm_bullet(w_field, lb, b);
        }
        else
        {
          mv_bullet(w_field, b);
        }
      }
    }
  }
  </code></pre>