title: invalid read of size 4 when using free()
body: <p>I'm new with C and valgrind and trying to learn them.
  When I use following function:</p>
  
  <pre><code>void die(const char *message,struct Connection *conn){
      if (conn){
          free(conn-&gt;file);
          free(conn-&gt;db);
          free(conn);
      }
      if (errno){
          perror(message);
      }else{
          printf("ERROR:$s\n",message);
      }
      exit(1);
  }
  </code></pre>
  
  <p>to print errors and free memory from structs (here is their declaration):</p>
  
  <pre><code>struct Address{
      int id;
      int set;
      char name[MAX_DATA];
      char email[MAX_DATA];
  };
  
  struct Database{
      struct Address rows[MAX_ROWS];
  };
  
  struct Connection{
      FILE *file;
      struct Database *db;
  };
  </code></pre>
  
  <p>i got errors like these from valgrind:</p>
  
  <pre><code>==15471== 2 errors in context 61 of 62
  ==15471== Invalid read of size 4
  ==15471==     at 0x4EA5889: _IO_default_setbuf (genops.c:567)
  ==15471==     by 0x4EA4928: _IO_file_setbuf@@GLIBC_2.2.5 (fileops.c:454)
  ==15471==     by 0x4EA6C32: _IO_unbuffer_write (genops.c:979)
  ==15471==     by 0x4EA6C32: _IO_cleanup (genops.c:1019)
  ==15471==     by 0x4E67F14: exit (exit.c:100)
  ==15471==     by 0x40097F: die (ex17.c:33)
  ==15471==     by 0x400DF4: Database_get (ex17.c:105)
  ==15471==     by 0x40102F: main (ex17.c:139)
  ==15471== Addres 0x51d53f0 is 0 bytes inside a block of size 568 free'd
  ==15471==     at 0x4C2845A: free (vg_replace_malloc.c:473)
  ==15471==     by 0x40091D: die (ex17.c:25)
  ==15471==     by 0x400DF4: Database_get (ex17.c:105)
  ==15471==    by 0x40102F: main (ex17.c:139)
  </code></pre>
  
  <p>but when executing wihout valgrind i don't have memory errors.
  Can it be caused by passing <code>NULL</code> to <code>free()</code>? And is it really an error, cause man says that <code>free(NULL)</code> just do nothing?</p>
  
  <p>Sorry for bad english.</p>