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

QSharedPointer::create calls destructor when an exception is thrown

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 5.9.1
    • 5.4.2
    • None
    • Windows 7, MSVC 2012
    • 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

              thiago Thiago Macieira
              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