How to track down a quot;double free or corruptionquot; error(如何追查“双重免费或腐败?错误)
问题描述
当我运行我的 (C++) 程序时,它会因此错误而崩溃.
When I run my (C++) program it crashes with this error.
* 检测到 glibc * ./load: 双重释放或损坏 (!prev):0x0000000000c6ed50 ***
* glibc detected * ./load: double free or corruption (!prev): 0x0000000000c6ed50 ***
如何追踪错误?
我尝试使用 print (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
这篇关于如何追查“双重免费或腐败"?错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何追查“双重免费或腐败"?错误


基础教程推荐
- C++ 程序在执行 std::string 分配时总是崩溃 2022-01-01
- C++,'if' 表达式中的变量声明 2021-01-01
- 如何定义双括号/双迭代器运算符,类似于向量的向量? 2022-01-01
- 您如何将 CreateThread 用于属于类成员的函数? 2021-01-01
- 什么是T&&(双与号)在 C++11 中是什么意思? 2022-11-04
- C++ 标准:取消引用 NULL 指针以获取引用? 2021-01-01
- 设计字符串本地化的最佳方法 2022-01-01
- 运算符重载的基本规则和习语是什么? 2022-10-31
- 调用std::Package_TASK::Get_Future()时可能出现争用情况 2022-12-17
- 如何在 C++ 中处理或避免堆栈溢出 2022-01-01