C语言 调用 free() 时损坏的未排序块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25767566/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 11:21:38  来源:igfitidea点击:

corrupted unsorted chunks while calling free()

c

提问by Angus

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

我收到上述错误。但我确定释放后我没有使用内存。为什么会出现上述错误?

回答by doron

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.

所有的堆,在其内部存储某些类型的元数据。当你做 malloc 或 free 时,堆往往会在堆上执行一些簿记功能。如果它在元数据中检测到一些完全出乎意料的东西,它通常会崩溃。

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.

一个可能的原因是写入超出了已分配缓冲区的末尾。这种写入很可能被允许,并且极有可能破坏堆元数据。当堆检测到这一点时,您的程序通常会中止。

回答by Cantfindname

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

可能是您尝试使用未正确指向动态分配内存的指针进行释放。