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

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

问题描述

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

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

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

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.

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

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

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

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 ?

推荐答案

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

"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天全站免登陆