summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Golubev <fatzer2@gmail.com>2024-03-29 18:14:14 +0300
committerAlexander Golubev <fatzer2@gmail.com>2024-03-29 20:18:42 +0300
commit12b826375706155eb61bb66673433878a3578718 (patch)
tree28e3b4b37fcb0f7ede39c587a6ce702bdfce8509
parentfb0d62eec811ab2d4d73550e455944cecbe7e091 (diff)
downloadtqt3-fix/tqtextcodec-locale-destr.tar.gz
tqt3-fix/tqtextcodec-locale-destr.zip
TQTextCodec: avoid dangling pointer to current locale's codecfix/tqtextcodec-locale-destr
This fixes crashes cause by dangling pointer returned from TQTextCodec::codecForLocale(). That might happen when tqWarning() and such are called during final cleanup. Bug: https://mirror.git.trinitydesktop.org/gitea/TDE/tqt3/issues/142 Signed-off-by: Alexander Golubev <fatzer2@gmail.com>
-rw-r--r--src/codecs/qtextcodec.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/codecs/qtextcodec.cpp b/src/codecs/qtextcodec.cpp
index 1c6df695..2e26320a 100644
--- a/src/codecs/qtextcodec.cpp
+++ b/src/codecs/qtextcodec.cpp
@@ -90,12 +90,14 @@
static TQValueList<TQTextCodec*> *all = 0;
static bool destroying_is_ok; // starts out as 0
+static bool codecs_were_cleansed = 0;
static TQTextCodec * localeMapper = 0;
class TQTextCodecCleanup {
public:
~TQTextCodecCleanup() {
TQTextCodec::deleteAllCodecs();
+ codecs_were_cleansed = TRUE;
}
};
static TQTextCodecCleanup qtextcodec_cleanup;
@@ -140,6 +142,8 @@ void TQTextCodec::deleteAllCodecs()
ball->clear();
delete ball;
+ localeMapper = 0;
+
destroying_is_ok = FALSE;
}
@@ -821,7 +825,12 @@ TQTextCodec* TQTextCodec::codecForLocale()
if ( localeMapper )
return localeMapper;
- setup();
+ // codecForLocale() is used by TQString::locale8Bit(), which is used by tqWarning() (and such)
+ // which should be fine to call during final cleanup and in such case we don't want neither to
+ // recreate the codecs again nor complains about codecs being already destroyed.
+ if ( !codecs_were_cleansed ) {
+ setup();
+ }
return localeMapper;
}
@@ -2906,6 +2915,8 @@ static void realSetup()
#if defined(QT_CHECK_STATE)
if ( destroying_is_ok )
tqWarning( "TQTextCodec: creating new codec during codec cleanup!" );
+ if ( codecs_were_cleansed )
+ tqWarning( "TQTextCodec: trying to setup codecs after they already been cleansed!" );
#endif
all = new TQValueList<TQTextCodec*>;