Details
-
Bug
-
Resolution: Done
-
Not Evaluated
-
5.9.7, 5.11.2, 5.12.0 Beta 3
-
None
-
Windows 10
-
-
3b8075de3b3c842311c157476a85d2cf9ddff403 (qt/qtbase/5.11) 928e77fa14e18773f994be7cf9dcf0da52f39055 (qt/qtbase/5.9)
Description
I've been getting random crashes caused by a failing assertion in QWeakPointer, used internally by QPointer:
ASSERT: "!weakref.load()" in file c:\users\qt\work\qt\qtbase\include\qtcore\../../src/corelib/tools/qsharedpointer_impl.h line 155
I was able to isolate the crash into a simple test case, attached to this bug. The crash is very easy to trigger, usually after a couple iterations.
The crash is caused by a bug in QtSharedPointer::ExternalRefCountData::getAndRef() that only occurs with specific timing of multiple threads trying to create the QPointer to the same object at the same time, thus the use of a thread pool in my test program.
I have a simple fix ready to submit on gerrit already. I'm just baffled because git blame shows that this code hasn't changed in the last 8 years, so I guess this is an 8-year-old bug that somehow nobody managed to hit until I did?
Also interestingly, the test program doesn't hit the assert on Linux. However it happens pretty easily on Windows. Maybe a difference in how quickly QThreadPool spins the worker threads on each platform?
I've also verified that QPointer is meant to be thread-safe so my usage is correct, which is the case and in fact the bug is part of the code meant to handle the thread safety.