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

QWeakPointer's converting move constructor is not threadsafe

XMLWordPrintable

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

      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.)

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

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

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes