PDA

View Full Version : QMap destructor got CRT detected message



hosseinzolfi
7th February 2017, 07:47
Iam getting CRT Heap corruption detected message, when running the following simple c++ code. The error comes from ::free method called by QMap destrcutor.



void foo() {
QMap<QString, QVariant> map;
map["Sample1"] = 2;
map["Sample2"] = 3;
}

I am using Qt 5.5.1 (It built Qt with Visual Studio 2013 and configure it to target windows xp(using v120_xp toolset)).

Preconditions:

My operating system is Windows 8 64 bit.
I changed the Platform Tools property to Visual Studio 2013 - Windows XP (v120_xp).
When I change the code to following, the error is gone.



void foo() {
QMap<QString, int> map; // Change the second type from QVariant to int
map["Sample1"] = 2;
map["Sample2"] = 3;
}

Any help will be appreciated.


Stacktrace contains following lines:


msvcr120d.dll!_free_dbg_nolock(void * pUserData, int nBlockUse) Line 1376 C++
msvcr120d.dll!_free_dbg(void * pUserData, int nBlockUse) Line 1265 C++
msvcr120d.dll!free(void * pUserData) Line 49 C++
Qt5Cored.dll!qMapDeallocate(QMapNodeBase * node, int alignment) Line 318 C++
Qt5Cored.dll!QMapDataBase::freeTree(QMapNodeBase * root, int alignment) Line 349 C++
Qt5Cored.dll!QMapDataBase::freeTree(QMapNodeBase * root, int alignment) Line 349 C++
Armaghan.exe!QMapData<QString,QVariant>::destroy() Line 225 C++
Armaghan.exe!QMap<QString,QVariant>::~QMap<QString,QVariant>() Line 339 C++
Armaghan.exe!foo() Line 32 C++
Armaghan.exe!main(int argc, char * * argv) Line 37 C++
[External Code]

high_flyer
7th February 2017, 15:12
I have just tested it with Qt5.4.2 MinGWx32 and with Qt5.6.2 Visual Studio 2015, both run without any problem.
Can you post the full project?
Maybe you are doing something not visible in the code you posted.

Does this run for you:

#include <QCoreApplication>
#include <QMap>
#include <QString>
#include <QVariant>

void foo() {
QMap<QString, QVariant> map;
map["Sample1"] = 2;
map["Sample2"] = 3;
}

int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
foo();
return a.exec();
}