GlibC Double free or corruption (fclose)

2019-03-06 05:31发布

I got an error on my C program on runtime. I found some stuff about "double free or corruption" error but nothing relevant.

Here is my 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);
}

It seems the

fclose(tmp_chunk);

raises this glibc error :

*** 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]

In the console output, the last CRC is displayed but not the last "[ OK ]"...

I never have this type of error and I searched for hours on Google but nothing really interesting in my case... please help :)


Now I have another error :

*** 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]

What the hell is this ? I'm lost... :(

1条回答
Melony?
2楼-- · 2019-03-06 06:07

*** glibc detected *** ./crc32: double free or corruption

Glibc is telling you that you've corrupted heap.

The tools to find such corruption on Linux are Valgrind and AddressSanitizer.

Chances are, either one of them will immediately tell you what your problem is.

查看更多
登录 后发表回答