From 17bea1689abc695d88f13cd15f73b0a59fcffdff Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Sun, 4 Nov 2012 21:21:31 +0200 Subject: QtConcurrent: 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. backported from qt/qtbase commit 731ba8ed08f80644b403556638c7f6229e678ebe Original commit by Christian Strømme Task-number: QTBUG-27224 Change-Id: I0c6b525cf241b5c559a1bab4e0066cd4de556ea8 Reviewed-by: Christian Stromme --- src/corelib/concurrent/qfutureinterface.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/corelib/concurrent/qfutureinterface.h') diff --git a/src/corelib/concurrent/qfutureinterface.h b/src/corelib/concurrent/qfutureinterface.h index 30bfbdb60e..dfe79416de 100644 --- a/src/corelib/concurrent/qfutureinterface.h +++ b/src/corelib/concurrent/qfutureinterface.h @@ -132,6 +132,8 @@ public: protected: bool referenceCountIsOne() const; + bool refT() const; + bool derefT() const; public: #ifndef QFUTURE_TEST @@ -150,13 +152,17 @@ class QFutureInterface : public QFutureInterfaceBase public: QFutureInterface(State initialState = NoState) : QFutureInterfaceBase(initialState) - { } + { + refT(); + } QFutureInterface(const QFutureInterface &other) : QFutureInterfaceBase(other) - { } + { + refT(); + } ~QFutureInterface() { - if (referenceCountIsOne()) + if (!derefT()) resultStore().clear(); } @@ -165,7 +171,8 @@ public: QFutureInterface &operator=(const QFutureInterface &other) { - if (referenceCountIsOne()) + other.refT(); + if (!derefT()) resultStore().clear(); QFutureInterfaceBase::operator=(other); return *this; -- cgit v1.2.3