Corrupted heap space using QtXmld4.dll (VS 2010)
-
hello all,
to make a long story short, here is the code:
@
#include <QtXml\qdom.h>
#include <qdebug.h>
#include <crw.h>int main(int argc, char *argv[])
{
QFile f(".\app.xml");
QString errorMsg;
int a, b;
QDomDocument doc( "appsettings" );
if( !f.open( QIODevice::ReadOnly ) )
return -1;
if( !doc.setContent( &f, &errorMsg, &a, &b ) ) //here is where I get the exception
{
f.close();
return -2;
}
f.close();
return 0;
}
@linking libraries : qtmaind.lib, QtCored4.lib, QtXmld4.lib
and, th callstack looks like:
@
ntdll.dll!77690844()
[Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]
ntdll.dll!77652a74()
ntdll.dll!7760cd87()QtXmld4.dll!_unlock(int locknum) Line 375 C
QtXmld4.dll!_free_dbg(void * pUserData, int nBlockUse) Line 1270 + 0x7 bytes C++
KernelBase.dll!7582468e()
QtXmld4.dll!_CrtIsValidHeapPointer(const void * pUserData) Line 2036 C++
QtXmld4.dll!_free_dbg_nolock(void * pUserData, int nBlockUse) Line 1322 + 0x9 bytes C++
QtXmld4.dll!_free_dbg(void * pUserData, int nBlockUse) Line 1265 + 0xd bytes C++
QtXmld4.dll!operator delete(void * pUserData) Line 54 + 0x10 bytes C++
QtXmld4.dll!QTextDecoder::`scalar deleting destructor'() + 0x21 bytes C++
QtXmld4.dll!QXmlInputSource::~QXmlInputSource() Line 1357 + 0x22 bytes C++
QtXmld4.dll!QDomDocument::setContent(QIODevice * dev, bool namespaceProcessing, QString * errorMsg, int * errorLine, int * errorColumn) Line 6755 + 0x31 bytes C++
QtXmld4.dll!QDomDocument::setContent(QIODevice * dev, QString * errorMsg, int * errorLine, int * errorColumn) Line 6815 C++
test.exe!main(int argc, char * * argv) Line 17 + 0x19 bytes C++
test.exe!__tmainCRTStartup() Line 278 + 0x19 bytes C
test.exe!mainCRTStartup() Line 189 C
kernel32.dll!76c23677()
ntdll.dll!775f9f02()
ntdll.dll!775f9ed5()
@
(test.exe is main.cpp)...any ideas?
Thanks,
G -
Thank you for the replay.
I build it myself, the only thing that I changed was the runtime-library flag from /MDd to /MTd so my client (to be) will not need to install the redistribution, but I used the configuration provided with the source for vs2010...also, there is no .NET at all here, and, other things, like qtsqlite and gui that I use work perfectly.
-
Qt and the client code must be compiled and linked with the same linker flags. Do not mix them, otherwise you might end up using two different C/C++ runtimes, which leads to memory corruption when new is called in one implementation and delete in the other.
-
Are you sure, your Qt libs were build with /MTd and your binary also for debug and all with /MT for release?
It looks (from the defect behavior) very like these do not fit together...How did you change the flags for Qt? Did you use dependency viewer to verify, Qt dies not use the redistributables?
-
according to the build log (all 5Meg of it) there is no indication of any use of -MDd or -MD, just MT.
I am not that strong in c/c++ but,
according to the callstack we can see that the heap corruption is due to a call of a distructor of the passed &file, or one of it's components. so, we can say that the code itself cannot work with such parameters as -M, because of such call, right? -
Hi,
I thopught a bit about this, /MT means link against a static library, that means you add it to all binaries, you create. If you link a dll with /MT, the code is added to that dll. Then you link your executable againtst that and it is also added there. Then you have two different heaps, which leads to that crash. If you use /MT, you MUST use Qt as static library or use /MD (and the vc redistributables).
-
thank you Gerolf, after sleeping on it, I came also to the same conclusion.
In order for QT to be used in such a way the code must be created with 'awareness' of two (or more) different heap spaces, so, I will be linking QT statically for the xml parser..
and, the more I think about it, the more it makes sense also.
so, thank you all for the help