GlibC Double free or corruption (fclose)

二次信任 提交于 2019-12-02 21:46:10

问题


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:


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



来源:https://stackoverflow.com/questions/14199441/glibc-double-free-or-corruption-fclose

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!