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

Windows: Memory leaks when adopting non-Qt thread.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P4: Low
    • None
    • 5.9.2
    • Core: Threads
    • None
    • Windows 10 x64

      Qt 5.9.2 (msvc2013_64)
    • Windows

    Description

      Calling certain Qt functions within a thread which was not created by Qt leads to memory leaks.

      The following minimal example reporduces the issue:

       

      #include <QCoreApplication>
      #include <QThread>
      #include <QtConcurrent/QtConcurrent>
      #include <QTimer>
      #include <future>
      #include <qt_windows.h>
      
      int main(int argc, char *argv[])
      {
      	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
      	QCoreApplication a(argc, argv);
      	QtConcurrent::run(QThread::currentThread).waitForFinished(); // all good, no leak
      	std::async(std::launch::async, QThread::currentThread).get(); // this causes memory leaks
      	QTimer t;
      	QObject::connect(&t, &QTimer::timeout, qApp, &QCoreApplication::quit);
      	t.start(1000);
      	return a.exec();
      }
      

      Note that without a QCoreApplication both calls to 'QThread::currentThread()' cause leaks.

      With the QCoreApplication and event loop present only the 'std::async' case leaks.

      Attachments

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

        Activity

          People

            Unassigned Unassigned
            wwallner Wolfgang Wallner
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes