Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

corrupted unsorted chunks while calling free()

Tags:

c

*** glibc detected *** ./a.out: free(): corrupted unsorted chunks: 0x00000000007646b0 ***
*** glibc detected *** ./a.out: malloc(): memory corruption: 0x00000000007635a0 ***

I'm getting the above error. But I'm sure that I'm not using the memory after freeing. Why do I get the above error ?

like image 863
Angus Avatar asked Sep 10 '14 14:09

Angus


2 Answers

All heaps, store certain kinds of meta-data inside itself. When you do a malloc or free, the heap will often perform some book-keeping functions on the heap. If it detects something totally unexpected in the meta-data, it will normally crash.

Normal heap operations are highly unlikely to cause such problems, so your program is most likely to be the cause. Since your program has access to all the memory in the process including the heap meta-data, your program could have accidentally overwritten some of the meta-data.

A likely cause is writing beyond the end of an allocated buffer. This write will most probably be allowed and is extremely likely to corrupt the heap meta-data. When this detected by the heap, your program will normally abort.

like image 181
doron Avatar answered Sep 17 '22 07:09

doron


It could be that you are trying to free with a pointer that does not correctly point to dynamically alocated memory.

like image 43
Cantfindname Avatar answered Sep 18 '22 07:09

Cantfindname