Glibc 在调用新关键字 C++ 时检测到 malloc() 内存损坏 (0xb6179bb8)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3836664/
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-08-28 13:52:10  来源:igfitidea点击:

Glibc detected malloc() memory corruption (0xb6179bb8) when calling new keyword C++

c++cglibc

提问by Leslieg

My program runs to a point where calling the newkeyword would cause the error stated above. i.e. char* a = new char[100]. The error is reproducible and every time. I run the program until that point of calling the newkeyword. It seems to be the memory location is corrupted at the point, but I'm not sure what he issue is.

我的程序运行到调用new关键字会导致上述错误的程度。即char* a = new char[100]。该错误是可重现的,并且每次都可以重现。我运行程序直到调用new关键字。似乎内存位置此时已损坏,但我不确定他的问题是什么。

What are the possible causes for this error?

此错误的可能原因是什么?

回答by Bart van Ingen Schenau

This error means that you have corrupted the bookkeeping data of the system memory manager. Such corruptions are typically the result of incorrect use of pointers, such as

此错误表示您已损坏系统内存管理器的簿记数据。此类损坏通常是错误使用指针的结果,例如

  • Using an uninitialised pointer
  • Using a pointer after the memory it refers to has been freed (the freeing could have happened through another pointer)
  • Writing outside your array bounds
  • 使用未初始化的指针
  • 在它所指的内存被释放后使用一个指针(释放可能是通过另一个指针发生的)
  • 在数组范围之外写入