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

QFutureWatcher::setFuture: Not clear who is responsible for keeping the future alive

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 6.5.2
    • Core: QtConcurrent
    • None

    Description

      https://doc.qt.io/qt-5/qfuturewatcher.html#setFuture
      void QFutureWatcher::setFuture(const QFuture<T> &future)

      setFuture take a reference which indicates that the caller is responsible for keeping the passed QFuture alive.

      https://doc.qt.io/qt-5/qfuturewatcher.html#future
      QFuture<T> QFutureWatcher::future() const

      future returns a copy, so somewhere copying takes place.

      The question is: who is responsible to keep the QFuture object alive to avoid a use-after-free:

      • the caller of setFuture
      • the QFutureWatcher internally

      As I learned that the QFutureWatcher internally keeps a
      QFuture<T> m_future member
      it seems that the QFutureWatcher keeps the QFuture alive thus the caller of setFuture can just destroy its copy.

      It would be nice if this would be documented so that the usage is clear and this behavior is guaranteed (not depending on implementation details in the source).

      Attachments

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

        Activity

          People

            cnn Qt Core & Network
            anloth An Loth
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes