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

Initialization of QWindowsSystemProxy is not thread safe

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 4.8.x, 5.0.0
    • 4.7.1
    • Network: Proxies
    • None
    • 2cf8e487a5c546382daaa954c23d3926668b0a85 (5.0), 70545d13e2f97b84e84cab17610209cfc45fc410 (4.8)

    Description

      Using QNetworkProxyFactory::systemProxyForQuery simultaneously in different threads can lead to a crash. The cause is as follows:

      The system proxy unter Windows is initialized with the macro

        Q_GLOBAL_STATIC(QWindowsSystemProxy, systemProxy)
      

      Among other things, this macro contains the lines

                  TYPE *x = new TYPE;                                         \
                  if (!this_##NAME.pointer.testAndSetOrdered(0, x))           \
                      delete x;                                               \
      

      This means, if two different threads call systemProxy() "at the same time", one of them calls the destructor of QWindowsSystemProxy immediately after the constructor. This class is howevered not prepared for this; the destructor works only correctly if the method QWindowsSystemProxy::init is called inbetween:

        QWindowsSystemProxy::~QWindowsSystemProxy()
        {
            if (hHttpSession)
                ptrWinHttpCloseHandle(hHttpSession);
        }
      

      This crashes since the member hHttpSession is not initialized by the constructor.

      Solution is simple - initialize the member:

        QWindowsSystemProxy::QWindowsSystemProxy()
            : hHttpSession (NULL), initialized(false), functional(false), isAutoConfig(false)
        {
            defaultResult << QNetworkProxy::NoProxy;
        }
      

      Attachments

        For Gerrit Dashboard: QTBUG-15765
        # Subject Branch Project Status CR V

        Activity

          People

            shkearns Shane Kearns
            bgehrmann Bernd Gehrmann
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes