Uploaded image for project: 'Qt Creator'
  1. Qt Creator
  2. QTCREATORBUG-24885

[Windows] qtcreator will block memory leaks reported by debug version of MSVC runtime on exit

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • Not Evaluated
    • None
    • Qt Creator 4.13.2
    • Debugger
    • None
    • windows 10 x64
      qtcreator 4.13.2
      qt-5.15.1 windows
    • Windows

    Description

          When developing app under Windows we usually detect memory leaks rely on the leak detection capability of debug version of MSVC runtime. For example:

      #include "widget.h"
      
      #include <QApplication>
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          Widget w;
          w.show();
      
          // leak some memory
          char *mem = new char[250];
          Q_UNUSED(mem);
      
          const int ret = a.exec();
      
      #ifdef _MSC_VER
          //////////////////////////////////////////////////////////////////////////
          // memory leak detection
          //////////////////////////////////////////////////////////////////////////
      
          // 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);
      #endif
      
          return ret;
      } 

      On exit the above program will report a memory leak in the output window of qtcreator:

      11:44:04: Starting D:\test_proj\build-testleak-Desktop_win64-Debug\debug\testleak.exe ...
      Detected memory leaks!
      Dumping objects ->
      Unknown macro: {11717}
      normal block at 0x00000279EFD9CA50, 250 bytes long.
      Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
      Object dump complete.
      11:44:05: D:\test_proj\build-testleak-Desktop_win64-Debug\debug\testleak.exe exited with code 0

      But with recently released qtcreator the leak message will be blocked once I have opened a native windows dialog in the program which seems to be a regression of qtcreator.

          I have attached a sample program to reproduce this issue, run the program with debug version of qt-windows:
      1) For the first time, don't press the button on the widget, press close button to exit the app and you will see the leak message in the output window of qtcreator
      2) The second time, press the button on the widget, a native windows dialog show up, exit the app, the leak message won't show

      Attachments

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

        Activity

          People

            davschul David Schulz
            jianliang79 liang jian
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes