title: C crypt function, malloc and valgrind
body: <p>My man page for the crypt function states that:</p>
  
  <p>"The return value points to static data whose content is overwritten by each call."</p>
  
  <p>However, when using the SHA512 version (ie, the salt starts $6$...), valgrind does not seem to agree. Unless I free the pointer that crypt returns, it gets upset:</p>
  
  <pre><code>120 bytes in 1 blocks are still reachable in loss record 1 of 1
  at 0x4C2BBA0: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
  by 0x4C2DF4F: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
  by 0x521F4D4: __sha512_crypt (sha512-crypt.c:437)
  </code></pre>
  
  <p>Conversely, valgrind is fine if I use the DES version (so salt does not start with $6$ or similar).</p>
  
  <p>What's going on here and is this behaviour explained anywhere?</p>
  
  <p>Thanks in advance.</p>
  
  <p>EDIT: Platform is Ubuntu 15.04 64-bit. Here's a program:</p>
  
  <pre><code>#define _XOPEN_SOURCE 700
  #include &lt;unistd.h&gt;
  
  int main(int argc, char** argv) {
      char *hash = crypt("password", "$6$Salty");
      return 0;
  }
  </code></pre>