title: GlibC Double free or corruption (fclose)
body: <p>I got an error on my C program on runtime. I found some stuff about "double free or corruption" error but nothing relevant.</p>
  
  <p>Here is my code :</p>
  
  <pre><code>void compute_crc32(const char* filename, unsigned long * destination)
  {
    FILE* tmp_chunk = fopen(filename, "rb");
    printf("\n\t\t\tCalculating CRC...");
    fflush(stdout);
    Crc32_ComputeFile(tmp_chunk, destination);
    printf("\t[0x%08lX]", *destination);
    fflush(stdout);
    fclose(tmp_chunk);
    printf("\t[ OK ]");
    fflush(stdout);
  }
  </code></pre>
  
  <p>It seems the</p>
  
  <pre><code>fclose(tmp_chunk);
  </code></pre>
  
  <p>raises this glibc error :</p>
  
  <pre><code>*** glibc detected *** ./crc32: double free or corruption (out): 0x09ed86f0 ***
  
  ======= Backtrace: =========
  /lib/i386-linux-gnu/libc.so.6(+0x75ee2)[0xb763cee2]
  /lib/i386-linux-gnu/libc.so.6(fclose+0x154)[0xb762c424]
  ./crc32[0x80498be]
  ./crc32[0x8049816]
  ./crc32[0x804919c]
  ./crc32[0x8049cc2]
  /lib/i386-linux-gnu/libc.so.6(__libc_start_main+0xf3)[0xb75e04d3]
  ./crc32[0x8048961]
  </code></pre>
  
  <p>In the console output, the last CRC is displayed but not the last "[ OK ]"...</p>
  
  <p>I never have this type of error and I searched for hours on Google but nothing really interesting in my case... please help :)</p>
  
  <hr>
  
  <p>Now I have another error :</p>
  
  <pre><code>*** glibc detected *** ./xsplit: free(): invalid next size (normal): 0x095a66f0 ***
  ======= Backtrace: =========
  /lib/i386-linux-gnu/libc.so.6(+0x75ee2)[0xb7647ee2]
  /lib/i386-linux-gnu/libc.so.6(fclose+0x154)[0xb7637424]
  ./xsplit[0x80497f7]
  ./xsplit[0x804919c]
  ./xsplit[0x8049cd6]
  /lib/i386-linux-gnu/libc.so.6(__libc_start_main+0xf3)[0xb75eb4d3]
  ./xsplit[0x8048961]
  </code></pre>
  
  <p>What the hell is this ? I'm lost... :(</p>