title: malloc(): memory corruption
body: <p>Here is the simplified program that I think can lead to this error.</p>
  
  <pre><code>char *p = (char*)malloc(8192);
  for(int i = 0; i &lt; 9200; ++i){
    p[i] = '1';
  }
  char *s = (char*)malloc(strlen(p)); 
  </code></pre>
  
  <p>The original project is rather complicated, so I simplified it. I assigned 8192 bytes using malloc. Then my program will write more than 8192 characters in to the array. Then I will allocate memory using malloc.  </p>
  
  <p>This mini program didn't crash. But in the original big project, it crashes with this error:</p>
  
  <blockquote>
    <p>malloc(): memory corruption: 0x0000000007d20bd0 ***</p>
  </blockquote>
  
  <p>What may cause this difference?</p>