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

QWeakPointer's converting move constructor is not threadsafe

    XMLWordPrintable

Details

    • 89b6ad3ab (dev), 6bce1ddec (6.6), a7f0c65a5 (6.5)

    Description

      This is the converting constructor for QWeakPointer from rvalues:

          template <class X, IfCompatible<X> = true>
          Q_NODISCARD_CTOR
          QWeakPointer(QWeakPointer<X> &&other) noexcept
              : d(other.d), value(other.value)
          {
              other.d = nullptr;
              other.value = nullptr;
          }
      

      This is wrong, because doing value(other.value) may require access other.value's vtable (in the presence of virtual inheritance). We need to lock() and access only if it's safe.

      Strangely, this protection is already employed by the converting assignment operator.

      (Just so that I can quote this problem in commit messages.)

      Attachments

        For Gerrit Dashboard: QTBUG-117483
        # Subject Branch Project Status CR V

        Activity

          People

            thiago Thiago Macieira
            peppe Giuseppe D'Angelo
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes