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

QSharedPointer: Memory leak after failed dynamicCast when source is destroyed before target

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 4.8.5, 5.0.1
    • 4.8.1, 4.8.2, 4.8.4
    • Core: Other
    • 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()
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            elowar Markus Thiele
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes