Details
-
Bug
-
Resolution: Done
-
Not Evaluated
-
None
-
4.8.0
-
None
-
windows 7 x64
vs2010 sp1
Description
Using qDebug() to print message in a thread NOT created by QThread will cause memory leak. This leak exist in Qt-4.8.0 but NOT exist in Qt-4.7.4, the following code will produce this problem.
DWORD WINAPI myThreadRoutine(LPVOID) { qDebug() << "Some debug information.\n"; return 0; } int main(int argc, char *argv[]) { QApplication a(argc, argv); QWidget w; w.show(); HANDLE hThread = CreateThread(0, 0, &myThreadRoutine, 0, 0, 0); WaitForSingleObject(hThread, INFINITE); CloseHandle(hThread); int ret = a.exec(); // get the current state of the flag int nCrtDbgFlag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG); // set memory leak check flag nCrtDbgFlag |= _CRTDBG_LEAK_CHECK_DF; // set the new debug flag _CrtSetDbgFlag(nCrtDbgFlag); return ret; }
press F5 to start this program, after exited you will see memory leak report in output window of visual studio