Fix for memory leak in ResultStore
authorChristian Strømme <christian.stromme@digia.com>
Tue, 16 Oct 2012 09:34:00 +0000 (11:34 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Wed, 17 Oct 2012 22:58:11 +0000 (00:58 +0200)
In ResultStoreBase::addResults() it possible that the ResultItem we
create is invalid (filter-mode enabled). Since an invalid ResultItem
won't have any result data, we need to make sure that we don't allocate
any data for it.

Task-number: QTBUG-27224
Change-Id: Ic99b191db0e9dd4e29b64911f87d90a8148bb7a5
Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
src/corelib/thread/qresultstore.h

index 3314cd7..d084e24 100644 (file)
@@ -176,7 +176,10 @@ public:
 
     int addResults(int index, const QVector<T> *results, int totalCount)
     {
-        return ResultStoreBase::addResults(index, new QVector<T>(*results), results->count(), totalCount);
+        if (m_filterMode == true && results->count() != totalCount && 0 == results->count())
+            return ResultStoreBase::addResults(index, 0, 0, totalCount);
+        else
+            return ResultStoreBase::addResults(index, new QVector<T>(*results), results->count(), totalCount);
     }
 
     int addCanceledResult(int index)