summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOlivier Goffart <olivier.goffart@nokia.com>2010-11-04 12:37:48 (GMT)
committerOlivier Goffart <olivier.goffart@nokia.com>2010-11-22 14:09:06 (GMT)
commited8f3b6c98f1b305f0d183bc70c5f810a9c45ef2 (patch)
tree22aef970e281ab956b34d1f25ca6f7d037f57caa /src
parentfb026f81bfe64be232a819fdac5b8dbcdd4fae4d (diff)
downloadQt-ed8f3b6c98f1b305f0d183bc70c5f810a9c45ef2.zip
Qt-ed8f3b6c98f1b305f0d183bc70c5f810a9c45ef2.tar.gz
Qt-ed8f3b6c98f1b305f0d183bc70c5f810a9c45ef2.tar.bz2
QThreadStorage: fix memory leak if thread storage are added while destroying
The destructor(q) function could use itself and create new QThreadStorage. This might be the case for example, when using qDebug in a destructor. Task-number: QTBUG-14579 Reveiwed-by: Joao Reviewed-by: Brad
Diffstat (limited to 'src')
-rw-r--r--src/corelib/thread/qthreadstorage.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/corelib/thread/qthreadstorage.cpp b/src/corelib/thread/qthreadstorage.cpp
index 2fc04f5..2222427 100644
--- a/src/corelib/thread/qthreadstorage.cpp
+++ b/src/corelib/thread/qthreadstorage.cpp
@@ -178,11 +178,12 @@ void QThreadStorageData::finish(void **p)
return; // nothing to do
DEBUG_MSG("QThreadStorageData: Destroying storage for thread %p", QThread::currentThread());
-
- for(int i = tls->size() - 1; i >= 0; i--) {
- void *&value = (*tls)[i];
+ while (!tls->isEmpty()) {
+ void *&value = tls->last();
void *q = value;
value = 0;
+ int i = tls->size() - 1;
+ tls->resize(i);
if (!q) {
// data already deleted