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

Destructor of global variable in shared lib not called after QAudioDeviceInfo::availableDevices(QAudio::AudioOutput) or sending an HTTP(s) request using MSVC 2015

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Done
    • Affects Version/s: 5.9.4, 5.10.1
    • Fix Version/s: 5.11.1
    • Component/s: Multimedia, Network
    • Labels:
      None
    • Environment:
      Windows 10 64bit
      MSVC Qt 5.10.1 32bit
      MSVC Qt 5.9.4

      Description

      I think I found a weird issue while trying to get Visual Leak Detector and Windows CRT collecting the results when shutting down the app with latest Qt version 5.10.1. I created a minimal example that reproduces the issue that I attached. This happens in both debug and release under Windows 10 using MSVC 2015 and Qt 5.10.1 32bit. I was also able to reproduce using MSVC 2015 Qt 5.9.4 32bit as well.

      The idea is simple: just have a global variable in a shared library. I expect the destructor to be called when the library is unloaded when exiting the application. However, that doesn't happen if I call `QAudioDeviceInfo::availableDevices(QAudio::AudioOutput)` or if I send an HTTP(s) request. Apart from setting a log trace, I have also verified that if I set a breakpoint, it doesn't get hit.

      For instance, in my example this is what happens when I don't call `availableDevices`:

      Lib::Lib()
      Lib::foo
      Using Qt version 5.10.1
      Lib::~Lib()

      Then, calling `availableDevices`:

      Lib::Lib()
      Lib::foo
      Using Qt version 5.10.1
      "Speakers (High Definition Audio Device)"
      "Speakers (High Definition Audio Device)"

      This same code works as expected and the destructor is called in Linux, macOS and under Windows using MinGW 5.3.0 Qt 5.10.1 32bit. So, it seems it only affects MSVC. Something interesting is that if instead of linking at compile time I do load the library at runtime using `LoadLibrary`, the destructor is properly called. I imagine this is because the `FreeLibrary` for my shared library is called automagically (and thus, the destructor of my global variable) before something else happens which causes the app to exit not gracefully.

        Attachments

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

          Activity

            People

            Assignee:
            valentyn.doroshchuk Valentyn Doroshchuk
            Reporter:
            pamarcos Pablo Marcos Oltra
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes