程序仅在释放模式下在调试器外崩溃 [英] Program crashes only in Release mode outside debugger

查看:161
本文介绍了程序仅在释放模式下在调试器外崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有相当大的程序(> 10k行的C ++代码)。它在调试模式下或在从Visual Studio中启动时的发布模式下工作完美,但是当从命令行手动启动时,发布模式二进制文件通常崩溃。

I have quite massive program (>10k lines of C++ code). It works perfectly in debug mode or in release mode when launched from within Visual Studio, but the release mode binary usually crashes when launched manually from the command line (not always!!!).

具有delete的行会导致崩溃:

The line with delete causes the crash:

bool Save(const short* data, unsigned int width, unsigned int height, 
          const wstring* implicit_path, const wstring* name = NULL, 
          bool enable_overlay = false)
{
    char* buf = new char[17];
    delete [] buf;
}

编辑:根据要求扩展示例。

Upon request expanded the example.

len在我的测试用例中长度为16。没关系,如果我使用buf做某事,它会在删除时崩溃。

The "len" has length 16 in my test case. It doesn't matter, if I do something with the buf or not, it crashes on the delete.

编辑:应用程序工作正常没有delete []行,但我想它泄漏内存然后(因为块永远不会分配)。 buf中从来没有使用过删除行。它似乎也不会崩溃与任何其他类型比char。现在我真的很困惑。

The application works fine without the delete [] line, but I suppose it leaks memory then (since the block is never unallocated). The buf in never used after the delete line. It also seems it does not crash with any other type than char. Now I am really confused.

崩溃消息是非常不具体的(典型的Windowsxyz.exe已停止工作)。当我单击调试程序选项时,它进入VS,其中错误被指定为访问冲突写入位置xxxxxxxx。它无法找到错误的地方,虽然没有符号被加载任何堆栈帧。

The crash message is very unspecific (typical Windows "xyz.exe has stopped working"). When I click the "Debug the program" option, it enters VS, where the error is specified to be "Access violation writing location xxxxxxxx". It is unable to locate the place of the error though "No symbols were loaded for any stack frame".

我想这是一个相当严重的情况下堆损坏,但如何调试这个?我应该寻找什么?

I guess it is some pretty serious case of heap corruption, but how to debug this? What should I look for?

感谢您的帮助。

推荐答案

你已经在其他地方检查了内存泄漏?

have you checked memory leaks elsewhere?

通常,奇怪的删除行为是由于堆被损坏的一个点造成的,然后很明显,由于另一个堆

usually weird delete behavior is caused by the heap getting corrupted at one point, then much much later on, it becomes apparent because of another heap usage.

调试和发布之间的区别可能是windows在每个上下文中分配堆的方式。例如在调试中,堆可以非常稀疏,并且损坏不会立即影响任何东西。

The difference between debug and release can be caused by the way windows allocate the heap in each context. For example in debug, the heap can be very sparse and the corruption doesn't affect anything right away.

这篇关于程序仅在释放模式下在调试器外崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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