-1

I understand that heap corruption can happen from wide variety of causes.

I have a QT C++ project in Visual Studio. If I run in Debug or Release mode from Visual Studio, everything goes smoothly.

If I run the released executable (outside of Visual Studio), I get an application has stopped working error, followed by a prompt that asks if I want to Debug. This brings up Visual Studio Just-in-Time Debugger window stating that: An unhandled win32 exception occured in my_qt_application.exe[8812]

If I choose to Debug, I get the message: Unhandled exception at (...) (ntdll.dll) (...) A heap has been corrupted.

So I keep searching in the code for causes. The problem is that this error happens at very random occasions, not very consistent.

My question is; can the cause of this be missing dlls? (I've added the dlls that allows the program to run.)

remi
  • 937
  • 3
  • 18
  • 45
  • 1
    You could have dlls in your path that are built from a different compiler than what you built your code from. If these are being loaded with your project you will have UB because of more than 1 CRT being used at the same time and also possible stl incompatibilities. – drescherjm Mar 29 '18 at 16:36
  • 1
    Rather than just copying the DLLs, I would recommend using [windeployqt](http://doc.qt.io/qt-5/windows-deployment.html) which automatically grabs dependencies for you. That way you're guaranteed to have the same libraries in your deployment as in your development machine – docsteer Mar 29 '18 at 17:29

1 Answers1

2

No. The cause cannot be missing dlls. It could be a proximate cause. Example: If some image plugins are not available, and your code doesn't check that QImage loading had succeeded, and then tries to operate on the null image - there may be problems.

Most likely, though, you have a plain old memory error that you should squish using e.g. Valgrind.

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
  • You won't find Valgrind for Windows, but you may find some substitutes that do sort of the same thing. See [this question on Valgrind Substitute for Windows](https://stackoverflow.com/questions/413477/is-there-a-good-valgrind-substitute-for-windows) for some ideas. – jwernerny Mar 29 '18 at 18:46
  • You were of course right, it was some memory/wrong casting errors. Didn't get Valgrind to work as stated above. Tried to get Windbg to work, but not luck. I ended up spending half a day on this issue by checking the code, think it is solved now! – remi Mar 29 '18 at 19:07
  • You should have little trouble compiling it on a Linux platform, I'd think - unless you use some Windows APIs directly. Even then, you might be able to link with wine libraries to cover them. – Kuba hasn't forgotten Monica Mar 30 '18 at 15:12