如何使用gdb跟踪C ++中的双重自由或损坏错误 [英] How to track down a double free or corruption error in C++ with gdb
问题描述
当我运行我的C ++程序时,崩溃时出现此错误。
0x0000000000c6ed50 *
尝试使用cout语句跟踪它,但我发现它很难。 gdb能使这更容易吗?
如果您使用glibc,可以设置 MALLOC_CHECK _
环境变量到 2
,这将导致glibc使用容错版本 malloc
您可以使用设置环境MALLOC_CHECK_ 2从gdb中设置此操作
命令;程序应该中止,在回溯中显示 free()
。
请参阅 的man页面malloc()
了解更多信息
When I run my C++ program it crashes with this error.
* glibc detected ./load: double free or corruption (!prev): 0x0000000000c6ed50 **
I'm trying to track it down using cout statement but am finding it difficult. Could gdb make this easier? How is it done?
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.
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.
see the man page for malloc()
for more information
这篇关于如何使用gdb跟踪C ++中的双重自由或损坏错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!