Details
-
Bug
-
Resolution: Done
-
P3: Somewhat important
-
4.8.1, 4.8.2, 4.8.4
-
None
-
Observed in Qt 4.8.1 and 4.8.4; Problem does _not_ seem to occur in Qt 5.0.0; Tested with official Visual C++ 2010 builds on Windows 7 x64.
Originally observed in custom 32-bit Visual C++ 2010 build of Qt 4.8.2 on Windows 7 x64.
-
a094bf5a893c3cccffff10c1420bfbe3a3c02a7c 40e44d197777cf9a57189d0266540053d36f5ad7
Description
Consider the following code snippet:
QSharedPointer<A> a(new A); QSharedPointer<B> b = a.dynamicCast<B>(); // B and A not compatible
When the dynamic cast above fails and a (source) is destroyed before b (target), A's destructor is never called. Artificial example:
a.clear();
b.clear();
// --> memory is never freed
See attached test case. Sample output from Qt 4.8.4 illustrating the problem:
Failed dynamic cast from a into b; destroy b before a: { A() ~A() } Failed dynamic cast from a into b; destroy a before b: { A() }