Details
-
Bug
-
Resolution: Done
-
P2: Important
-
4.7.1
-
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; }