Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
6.5.2
-
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).