問題描述
當我運行我的 (C++) 程序時,它會因為這個錯誤而崩潰.
When I run my (C++) program it crashes with this error.
* glibc 檢測到 * ./load: double free or corruption (!prev):0x0000000000c6ed50 ***
* glibc detected * ./load: double free or corruption (!prev): 0x0000000000c6ed50 ***
如何追蹤錯誤?
我嘗試使用打印 (std::cout
) 語句,但沒有成功.gdb
能讓這更容易嗎?
I tried using print (std::cout
) statements, without success. Could gdb
make this easier?
推薦答案
如果你使用 glibc,你可以將 MALLOC_CHECK_
環境變量設置為 2
,這將導致 glibc 使用 malloc
的容錯版本,這將導致您的程序在雙釋放完成時中止.
If you're using glibc, you can set the MALLOC_CHECK_
environment variable to 2
, this will cause glibc to use an error tolerant version of malloc
, which will cause your program to abort at the point where the double free is done.
您可以在運行程序之前使用 set environment MALLOC_CHECK_2
命令從 gdb 設置它;程序應該中止,free()
調用在回溯中可見.
You can set this from gdb by using the set environment MALLOC_CHECK_ 2
command before running your program; the program should abort, with the free()
call visible in the backtrace.
請參閱 malloc()
的手冊頁,了解更多信息
see the man page for malloc()
for more information
這篇關于如何追查“雙重免費或腐敗"錯誤的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!