diff options
author | Shane Kearns <ext-shane.2.kearns@nokia.com> | 2012-02-16 17:02:11 +0000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-02-20 17:27:31 +0100 |
commit | 0570a0f3936a2f7d7ec5afef9fcea8193ef3c15c (patch) | |
tree | 7f495208b44a4c01d42d2cfb2e25b9b4959284b9 /src/network/kernel/qnetworkproxy.cpp | |
parent | 0cd1a21f55863740c3c7b4f69a0d73f0089b03aa (diff) | |
download | qt4-tools-0570a0f3936a2f7d7ec5afef9fcea8193ef3c15c.tar.gz |
Remove unnecessary locking from QNetworkProxy constructor
QGlobalNetworkProxy (a singleton) had two phase construction, with
the second phase being called from QNetworkProxy's constructor.
This isn't necessary, and has been reported as causing deadlocks.
Although constructing socket engine handlers has side effects
(they add themselves to a list on construction and remove themselves
on destruction), this appears to be safe. The socket engine handlers
are only used while holding the list mutex, and any socket engines
created don't have any reference to the factory that created them.
With the new version, it is possible that two instances of
QHttpSocketEngineHandler and QSocks5SocketEngineHandler exist
temporarily if a Q_GLOBAL_STATIC initialisation race occurs.
This appears safe, because the loser of the race deletes its
handlers, which remove themselves from the global list as above.
Task-number: QTBUG-13088
Change-Id: I8cf520da717d8ab7d862ab89c6de13aea6d60ac3
Reviewed-by: Richard J. Moore <rich@kde.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit aee4cbf22a5942c7bd4b9545a8fcb7cf2930e0ee)
Diffstat (limited to 'src/network/kernel/qnetworkproxy.cpp')
-rw-r--r-- | src/network/kernel/qnetworkproxy.cpp | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/src/network/kernel/qnetworkproxy.cpp b/src/network/kernel/qnetworkproxy.cpp index 288cab934b..4f294b95c8 100644 --- a/src/network/kernel/qnetworkproxy.cpp +++ b/src/network/kernel/qnetworkproxy.cpp @@ -247,6 +247,12 @@ public: , socks5SocketEngineHandler(0) , httpSocketEngineHandler(0) { +#ifndef QT_NO_SOCKS5 + socks5SocketEngineHandler = new QSocks5SocketEngineHandler(); +#endif +#ifndef QT_NO_HTTP + httpSocketEngineHandler = new QHttpSocketEngineHandler(); +#endif } ~QGlobalNetworkProxy() @@ -257,19 +263,6 @@ public: delete httpSocketEngineHandler; } - void init() - { - QMutexLocker lock(&mutex); -#ifndef QT_NO_SOCKS5 - if (!socks5SocketEngineHandler) - socks5SocketEngineHandler = new QSocks5SocketEngineHandler(); -#endif -#ifndef QT_NO_HTTP - if (!httpSocketEngineHandler) - httpSocketEngineHandler = new QHttpSocketEngineHandler(); -#endif - } - void setApplicationProxy(const QNetworkProxy &proxy) { QMutexLocker lock(&mutex); @@ -430,8 +423,6 @@ template<> void QSharedDataPointer<QNetworkProxyPrivate>::detach() QNetworkProxy::QNetworkProxy() : d(0) { - if (QGlobalNetworkProxy *globalProxy = globalNetworkProxy()) - globalProxy->init(); } /*! @@ -446,8 +437,6 @@ QNetworkProxy::QNetworkProxy(ProxyType type, const QString &hostName, quint16 po const QString &user, const QString &password) : d(new QNetworkProxyPrivate(type, hostName, port, user, password)) { - if (QGlobalNetworkProxy *globalProxy = globalNetworkProxy()) - globalProxy->init(); } /*! |