summaryrefslogtreecommitdiffstats
path: root/src/corelib/concurrent/qfutureinterface.h
diff options
context:
space:
mode:
authorOrgad Shaneh <orgad.shaneh@audiocodes.com>2012-11-04 21:21:31 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-11-08 15:11:56 +0100
commit17bea1689abc695d88f13cd15f73b0a59fcffdff (patch)
tree3686d3b4face64fb47fdb643a8bb73c887481101 /src/corelib/concurrent/qfutureinterface.h
parenta4b5cd2893a5eef09d615340ae899f785de84858 (diff)
QtConcurrent: Fix for leak in QFuture
To avoid leaking when converting a QFuture<T> to a QFuture<void> we need to have a separate ref. counter for QFuture<T>. When the last QFuture<T> 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 <christian.stromme@digia.com>
Diffstat (limited to 'src/corelib/concurrent/qfutureinterface.h')
-rw-r--r--src/corelib/concurrent/qfutureinterface.h15
1 files changed, 11 insertions, 4 deletions
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;