0

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... :(

casperOne
  • 73,706
  • 19
  • 184
  • 253
Mike Choko
  • 91
  • 1
  • 9
  • Don't you have another fclose in Crc32_ComputeFile? It would explain everything. – Anton Kovalenko Jan 07 '13 at 16:02
  • no I already searched that. The "Crc32_ComputeFile" takes a FILE pointer on an opened file and a reference to an unsigned long for the output CRC checksum – Mike Choko Jan 07 '13 at 16:07
  • I just think the **out** word in the glibc error makes a sense... I will test something... – Mike Choko Jan 07 '13 at 16:11
  • Possible duplicate of [How to track down a double free or corruption error in C++ with gdb](https://stackoverflow.com/questions/2902064/how-to-track-down-a-double-free-or-corruption-error-in-c-with-gdb) – Raedwald Dec 06 '18 at 09:09

1 Answers1

2

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

Employed Russian
  • 199,314
  • 34
  • 295
  • 362