From 731ba8ed08f80644b403556638c7f6229e678ebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Str=C3=B8mme?= Date: Thu, 25 Oct 2012 12:32:52 +0200 Subject: Fix for leak in QFuture MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To avoid leaking when converting a QFuture to a QFuture we need to have a separate ref. counter for QFuture. When the last QFuture goes out of scope, we need to clean out the result data. Task-number: QTBUG-27224 Change-Id: I965a64a11fffbb191ab979cdd030a9aafd4436c2 Reviewed-by: Jędrzej Nowacki --- src/corelib/thread/qfutureinterface_p.h | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/corelib/thread/qfutureinterface_p.h') diff --git a/src/corelib/thread/qfutureinterface_p.h b/src/corelib/thread/qfutureinterface_p.h index a9081d4c89..ece5e56768 100644 --- a/src/corelib/thread/qfutureinterface_p.h +++ b/src/corelib/thread/qfutureinterface_p.h @@ -129,7 +129,31 @@ class QFutureInterfaceBasePrivate public: QFutureInterfaceBasePrivate(QFutureInterfaceBase::State initialState); - QAtomicInt refCount; + // When the last QFuture reference is removed, we need to make + // sure that data stored in the ResultStore is cleaned out. + // Since QFutureInterfaceBasePrivate can be shared between QFuture + // and QFuture objects, we use a separate ref. counter + // to keep track of QFuture objects. + class RefCount + { + public: + inline RefCount(int r = 0, int rt = 0) + : m_refCount(r), m_refCountT(rt) {} + // Default ref counter for QFIBP + inline bool ref() { return m_refCount.ref(); } + inline bool deref() { return m_refCount.deref(); } + inline int load() const { return m_refCount.load(); } + // Ref counter for type T + inline bool refT() { return m_refCountT.ref(); } + inline bool derefT() { return m_refCountT.deref(); } + inline int loadT() const { return m_refCountT.load(); } + + private: + QAtomicInt m_refCount; + QAtomicInt m_refCountT; + }; + + RefCount refCount; mutable QMutex m_mutex; QWaitCondition waitCondition; QList outputConnections; -- cgit v1.2.3