Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-14636 QSharedPointer is not exception-safe
  3. QTBUG-14637

QSharedPointer's constructor dereferences uninitialised data in case of exception thrown

XMLWordPrintable

    • 3bb0cf4

      If operator new throws, the following code will dereference uninitialised memory:

          QSharedPointer<A> ptr(new A);
      
      qsharedpointer_impl.h: In function 'int main(int, char**)':
      qsharedpointer_impl.h:337: warning: 'a.QSharedPointer<A>::<anonymous>.QtSharedPointer::ExternalRefCount<A>::d' may be used uninitialized in this function                                                                        
      main.cpp:16: note: 'a.QSharedPointer<A>::<anonymous>.QtSharedPointer::ExternalRefCount<A>::d' was declared here
      qsharedpointer_impl.h:340: warning: 'a.QSharedPointer<A>::<anonymous>.QtSharedPointer::ExternalRefCount<A>::<anonymous>.QtSharedPointer::Basic<A>::value' may be used uninitialized in this function                             
      

      The reason is that QSharedPointer::QSharedPointer(T*) leaves its base uninitialised, then calls a function that may throw (internalConstruct). If that throws, then the parent class's destructor is run, which proceeds to dereference the uninitialised members.

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

            tmacieir Thiago Macieira (closed Nokia identity) (Inactive)
            tmacieir Thiago Macieira (closed Nokia identity) (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes