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

QSharedPointer::create calls destructor when an exception is thrown

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3: Somewhat important
    • Resolution: Done
    • Affects Version/s: 5.4.2
    • Fix Version/s: 5.9.1
    • Labels:
      None
    • Environment:
      Windows 7, MSVC 2012
    • Commits:
      d1210281e41008ce2e3510aa5cfb3ebea1c57734

      Description

      QSharedPointer::create() improperly calls the destructor when the constructor throws an exception.

      #include <QSharedPointer>
      
      class MyClass
      {
      public:
          MyClass()
          {
              qDebug("MyClass");
              throw std::exception();
          }
      
          ~MyClass()
          {
              qDebug("~MyClass()");
          }
      };
      
      int main(int argc, char *argv[])
      {
          try
          {
              QSharedPointer<MyClass> withCreate = QSharedPointer<MyClass>::create();
          }
          catch (const std::exception&)
          {
          }
      
          try
          {
              QSharedPointer<MyClass> withoutCreate( new MyClass() );
          }
          catch (const std::exception&)
          {
          }
      }
      

      The output is:

      MyClass()
      ~MyClass()
      MyClass()
      

      The output should be:

      MyClass()
      MyClass()
      

        Attachments

          Issue Links

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

            Activity

              People

              Assignee:
              thiago Thiago Macieira
              Reporter:
              keranen Eric Keranen
              Votes:
              2 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes