Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-21622

memory leak in qDebug()

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Not Evaluated
    • None
    • 4.8.0
    • Core: Threads
    • 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

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Unassigned Unassigned
            jianliang79 liang jian
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes