Corrupted Unsorted Chunks While Calling Free()

Corrupted Unsorted Chunks While Calling Free()
*** 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 ?

1

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.

1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

David Miller
Author

David Miller

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.