malloc()和malloc_consolidate()中的Segfaults [英] Segfaults in malloc() and malloc_consolidate()

查看:227
本文介绍了malloc()和malloc_consolidate()中的Segfaults的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序有时主要在malloc()和malloc_consolidate()中查看gdb中的回溯。



我验证了机器有足够的内存可用,甚至没有开始交换。
我检查了ulimits数据段和最大内存大小,都设置为unlimited。
我也运行在valgrind下的应用程序,没有发现任何内存错误。



现在我不知道还有什么可能导致这些segfaults。任何想法?



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

解决方案

另一种检查和防范使用malloc,realloc和free的bug是设置环境变量MALLOC_CHECK_,当设置MALLOC_CHECK_时,使用一个特殊的(效率较低的)实现,它被设计为容忍简单的错误,例如相同的参数或超出单个字节(一个错误),并不是所有这样的错误都可以被保护,但是,可能会导致内存泄漏。如果MALLOC_CHECK_设置为0,任何检测到的堆损坏将被默认忽略;如果设置为1,则在stderr上打印诊断;如果设置为2,则立即调用中止,这是有用的,因为否则可能会发生崩溃,并且真正的原因是很难跟踪。



http://www.gnu.org/s/libc/manual/html_node/Heap-Consistency-Checking.html#Heap-一致性检查


My application segfaults sometimes and mainly in malloc() and malloc_consolidate() when I look at the backtrace in gdb.

I verified that the machine has enough memory available, it didn't even start swapping. I checked ulimits for data segement and max memory size and both are set to 'unlimited'. I also ran the application under valgrind and didn't find any memory errors.

Now I'm out of ideas what else might be causing these segfaults. Any Ideas ?

Update: Since I'm not finding anything with valgrind (or ptrcheck), could it be that another application is trashing libc's memory structure or is there a separate structure for each process ?

解决方案

"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."

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

这篇关于malloc()和malloc_consolidate()中的Segfaults的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆