如何使用gdb跟踪C ++中的双重自由或损坏错误 [英] How to track down a double free or corruption error in C++ with gdb

查看:101
本文介绍了如何使用gdb跟踪C ++中的双重自由或损坏错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


*检测到glibc * ./加载:双重免费或损坏(!prev):
0x0000000000c6ed50 ***


我正在尝试跟踪它使用cout声明,但我发现很难。 gdb可以使这更容易吗?如何完成?

解决方案

如果您使用glibc,可以设置 MALLOC_CHECK _ 环境变量为 2 ,这将导致glibc使用容错版本的 malloc 将导致您的程序在双重空闲完成的时候中止。



您可以使用设置环境从gdb设置此值MALLOC_CHECK_ 2 命令运行您的程序之前;程序应该中止,在回调中可以看到 free()调用。



请参阅 man page for 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屋!

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