gpt4 book ai didi

c++ - malloc() 和 malloc_consolidate() 中的段错误

转载 作者:IT老高 更新时间:2023-10-28 12:53:39 30 4
gpt4 key购买 nike

当我查看 gdb 中的回溯时,我的应用程序有时会出现段错误,主要出现在 malloc() 和 malloc_consolidate() 中。

我确认机器有足够的可用内存,它甚至没有开始交换。我检查了 ulimits 的数据段和最大内存大小,两者都设置为“无限制”。我还在 valgrind 下运行了应用程序,没有发现任何内存错误。

现在我不知道还有什么可能导致这些段错误。有什么想法吗?

更新:由于我没有找到任何使用 valgrind(或 ptrcheck)的东西,可能是另一个应用程序正在破坏 libc 的内存结构,还是每个进程都有一个单独的结构?

最佳答案

来自 http://www.gnu.org/s/libc/manual/html_node/Heap-Consistency-Checking.html#Heap-Consistency-Checking :

Another possibility to check for and guard against bugs in the use of malloc, realloc and free is to set the environment variable MALLOC_CHECK_. When MALLOC_CHECK_ is set, a special (less efficient) implementation is used which is designed to be tolerant against simple errors, such as double calls of free with the same argument, or overruns of a single byte (off-by-one bugs). Not all such errors can be protected against, however, and memory leaks can result. If MALLOC_CHECK_ is set to 0, any detected heap corruption is silently ignored; if set to 1, a diagnostic is printed on stderr; if set to 2, abort is called immediately. This can be useful because otherwise a crash may happen much later, and the true cause for the problem is then very hard to track down.

关于c++ - malloc() 和 malloc_consolidate() 中的段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3100193/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com