PDA

View Full Version : Best way to fix a memory corruption issue?



agarny
2nd April 2012, 16:32
Hi,

I was wondering what you guys use to detect/fix memory corruption issues?

Basically, my Qt application uses a third-party library and it all works fine on Linux and Mac OS X, but not on a Windows machine which has a fully up-to-date version of Microsoft Office 2010 on it. Note that the fully up-to-date bit is very important, since everything works fine with a vanilla version of Microsoft Office 2010.

Now, I have managed to create a basic Qt application which reproduces the problem. All I needed was a QTreeView widget which uses QFileSystemModel as a model. From there, if I try to do something with the aforementioned third-party library, the basic Qt application crashes...

If anything, this tells me that the issue has nothing to do with my Qt application, but is it an issue with Microsoft Office, Qt and/or the third-party library? Well, considering that Microsoft Office and Qt are widely used, I would say that the issue is related to the third-party library, but how to be certain and, most importantly, how to determine what is causing the problem? (FWIW, everything works as expected using the previous version of the third-party library.)

For those interested/curious/etc., I have uploaded the source code (http://www.opencor.ws/OpenCOR_Test_1.11.zip) and binaries (http://www.opencor.ws/OpenCOR_Test_1.11_Binaries.zip) for the basic Qt application (using the previous version of the third-party library: source code (http://www.opencor.ws/OpenCOR_Test_1.10.zip) and binaries (http://www.opencor.ws/OpenCOR_Test_1.10_Binaries.zip)).

Cheers, Alan.

wysota
2nd April 2012, 18:17
On Linux I would suggest to use Valgrind, the best available tool for the job. Unfortunately it is not available for Windows however the latter has its own solutions (not as good though, at least from what I heard). As for fixing -- if the problem lies within a 3rd party library you can't rebuild, there is nothing you can do apart submitting a bug report to the author of the library.

agarny
2nd April 2012, 18:41
Yes, I know about valgrind, but I am on Windows indeed and well I have yet to come across something which is free and good. As for the third-party library, I know the people involved, so no problem there.

d_stranz
3rd April 2012, 02:55
If you ever look at the debug output in Visual Studio when you use Qt (or any other GUI layer) to interact with the file system (like post a QFileDialog), you would be amazed at the number of DLLs that get loaded because they have hooks into the OS. DLLs that have absolutely nothing to do with your application or what the app is trying to do. Office, McAfee, AV codecs or drivers, you name it, everybody wants to take a look at the files before you do, so it can decorate them with icons or check them for spyware. So it could be Office 2010 that is the culprit, or any one of the file translators or filters it uses.

If you debug using Visual Studio, set a breakpoint just before you enter into the code that crashes, and follow it down until you see where it crashes. It you can't do that, then wait until it does crash and look at the call stack to see where it is when the crash occurs. It might have stopped somewhere down in the kernel, and that usually isn't the cause, it's just where whatever broke prior to that had its effect. Look back up the stack a bunch of steps until your see something that looks like the name of a DLL you might recognize.

If you use mingw, supposedly the newest release includes gdb, which I have hear is a very good debugger.

agarny
3rd April 2012, 07:20
Sorry, I guess I should have mentioned that I use Qt Creator with MinGW and therefore GDB (so, what comes with Qt SDK 1.2). As for when things crash (using the basic Qt application I mentioned in my first message), I get the following stack information:


0 ntdll!KiRaiseUserExceptionDispatcher C:\Windows\system32\ntdll.dll 0 0x7715e696
1 ?? 0 0x209e0a54
2 libstdc++-6!_ZGVNSt9money_putIwSt19ostreambuf_iteratorIwSt11 char_traitsIwEEE2idE D:\Dropbox\OpenCOR_Test\OpenCOR_Test_1.11\build\li bstdc++-6.dll 0 0x6fcc8f80
3 ?? 0 0xa30000
4 ntdll!LdrAddRefDll C:\Windows\system32\ntdll.dll 0 0x7715f5c9
5 ?? 0 0xc0000374
6 ntdll!_itow C:\Windows\system32\ntdll.dll 0 0x77194268
7 ?? 0 0x28cf1c
8 ntdll!LdrAddRefDll C:\Windows\system32\ntdll.dll 0 0x7715f6a9
9 ?? concurrence.h 75 0x2
10 ?? 0
Now, that libstdc++-6.dll is not the one that ships with MinGW in Qt SDK 1.2 (as could have guessed from its path), but one that is used by the aforementioned third-party library which was compiled using a different version of MinGW. Indeed, it's a bit of a nightmare to build that third-party library, so I use binaries instead. So, could it be the cause of my problems?...