如何追踪“双重释放或腐败”?错误 [英] How to track down a "double free or corruption" error

查看:63
本文介绍了如何追踪“双重释放或腐败”?错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行我的(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使用<$的容错版本c $ c> 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环境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.

请参见有关$code> malloc() 的手册页,

see the man page for malloc() for more information

这篇关于如何追踪“双重释放或腐败”?错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆