PDA

View Full Version : QMap <QString, QString> deleting and RtlValidateHeap exception



MaxoBik
7th January 2016, 16:39
Hi.
I am faced with the strange behavior, which is occurs when removing QMap <QString, QString>:


QFile file("some.xml");

if (file.open(QIODevice::ReadOnly))
{
QByteArray data = file.readAll();

QDomDocument domDoc;
QMap<QString,QString> nodeMap;
if (domDoc.setContent( data ))
{
QDomNode topNode = domDoc.documentElement().firstChild();
while ( !topNode.isNull()) {
nodeMap.insert( topNode.toElement().tagName(), topNode.toElement().text() );
topNode = topNode.nextSibling();
}
}
qDebug() << nodeMap;
}
// <- Right here, after the local variable nodeMap was deleted from stack, I getting the exception RtlValidateHeap


Here is Call Stack when RtlValidateHeap exception is happening:



ntdll.dll!RtlpNtEnumerateSubKey() + 0x3947 byte
ntdll.dll!RtlUlonglongByteSwap() + 0x1561a byte
ntdll.dll!RtlValidateHeap() + 0x7a byte
KernelBase.dll!HeapValidate() + 0x14 byte
> msvcr100d.dll!_CrtIsValidHeapPointer(const void * pUserData) Line 2036 C++
msvcr100d.dll!_free_dbg_nolock(void * pUserData, int nBlockUse) Line 1322 + 0x9 byte C++
msvcr100d.dll!_free_dbg(void * pUserData, int nBlockUse) Line 1265 + 0xd byte C++
msvcr100d.dll!free(void * pUserData) Line 49 + 0xb byte C++
Qt5Cored.dll!QByteArray:: operator>=() + 0x7db14 byte
Qt5Cored.dll!QByteArray:: operator>=() + 0x17b77 byte
Qt5Cored.dll!QByteArray:: operator>=() + 0x14fea byte
MyApp.exe!QString::`scalar deleting destructor'() + 0x10 byte C++
MyApp.exe!QMapNode<QString,QString>::destroySubTree() Line 261 C++
MyApp.exe!QMapData<QString,QString>::destroy() Line 223 C++
MyApp.exe!QMap<QString,QString>::~QMap<QString,QString>() Line 339 + 0x22 byte C++
MyApp.exe!QMap<QString,QString>::`scalar deleting destructor'() + 0xf byte C++
MyApp.exe!main(int argc, char * * argv) Line 49 + 0x2e byte C++
MyApp.exe!WinMain(HINSTANCE__ * __formal, HINSTANCE__ * __formal, HINSTANCE__ * __formal, HINSTANCE__ * __formal) Line 113 + 0xd byte C++
MyApp.exe!__tmainCRTStartup() Line 547 + 0x2c byte C
MyApp.exe!WinMainCRTStartup() Line 371 C
kernel32.dll!BaseThreadInitThunk() + 0x12 byte
ntdll.dll!RtlInitializeExceptionChain() + 0x63 byte
ntdll.dll!RtlInitializeExceptionChain() + 0x36 byte


It looks like an double delete or access to the dangling pointers in QByteArray:: operator>=(), but I can't figure out how to solve this problem.

yeye_olive
7th January 2016, 17:50
I cannot see any obvious corruption of the heap in this snippet of code; it may be in another part of the program.

By the way, your code calls topNode.toElement() without checking that topNode is an element.

MaxoBik
7th January 2016, 18:13
Problem was in the project settings - under debug version of the project, was set load QtXml.dll instead of QtXmld.dll.