問題描述
當我查看 gdb 中的回溯時,我的應用程序有時會出現段錯誤,主要是在 malloc() 和 malloc_consolidate() 中.
My application segfaults sometimes and mainly in malloc() and malloc_consolidate() when I look at the backtrace in gdb.
我確認機器有足夠的可用內存,它甚至沒有開始交換.我檢查了數據段的 ulimits 和最大內存大小,兩者都設置為無限制".我也在 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.
現在我不知道還有什么可能導致這些段錯誤.有什么想法嗎?
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 ?
推薦答案
來自 http://www.gnu.org/s/libc/manual/html_node/Heap-Consistency-Checking.html#Heap-Consistency-Checking:
檢查和防范使用中的錯誤的另一種可能性malloc、realloc和free是設置環境變量MALLOC_CHECK_.當 MALLOC_CHECK_ 被設置時,一個特殊的(效率較低的)使用了旨在容忍簡單的實現錯誤,例如使用相同參數兩次調用 free,或單個字節的溢出(逐一錯誤).并非所有此類錯誤都可以但是,可能會導致內存泄漏.如果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.
這篇關于malloc() 和 malloc_consolidate() 中的段錯誤的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!