From f2102e1f829d216591a5f49819847c05383305ae Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Mon, 10 Jun 2013 13:20:17 -0500 Subject: Fix incorrect thread termination handling when thread count is greater than two This resolves Bug 1521 Make double free or delete of QString objects more obvious --- src/tools/qstring.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src/tools') diff --git a/src/tools/qstring.cpp b/src/tools/qstring.cpp index 0630cd3..251637d 100644 --- a/src/tools/qstring.cpp +++ b/src/tools/qstring.cpp @@ -1071,13 +1071,20 @@ QStringData::QStringData(QChar *u, uint l, uint m) : QShared(), } QStringData::~QStringData() { - if ( unicode ) delete[] ((char*)unicode); + if ( unicode ) { + delete[] ((char*)unicode); + } if ( ascii && security_unpaged ) { munlock(ascii, LINUX_MEMLOCK_LIMIT_BYTES); } - if ( ascii ) delete[] ascii; + if ( ascii ) { + delete[] ascii; + } #ifdef QT_THREAD_SUPPORT - if ( mutex ) delete mutex; + if ( mutex ) { + delete mutex; + mutex = NULL; + } #endif // QT_THREAD_SUPPORT } @@ -1675,6 +1682,13 @@ QString::QString( QStringData* dd, bool /* dummy */ ) { QString::~QString() { +#if defined(QT_CHECK_RANGE) + if (!d) { + qWarning( "QString::~QString: Double free or delete detected!" ); + return; + } +#endif + #ifdef QT_THREAD_SUPPORT d->mutex->lock(); #endif // QT_THREAD_SUPPORT @@ -1684,6 +1698,7 @@ QString::~QString() d->mutex->unlock(); #endif // QT_THREAD_SUPPORT d->deleteSelf(); + d = NULL; } else { #ifdef QT_THREAD_SUPPORT -- cgit v1.2.1