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 21:31:02 +0300
commit10bd40911eed8b1bc37d56797c46d52f4357bc65 (patch)
treecec9616a6523fefbeecdfd723c665529929b67ce
parentfa52f57da125cb9003526976f53656197a930879 (diff)
downloadtqt3-10bd40911eed8b1bc37d56797c46d52f4357bc65.tar.gz
tqt3-10bd40911eed8b1bc37d56797c46d52f4357bc65.zip
TQTextCodec: avoid dangling pointer to current locale's codec
This fixes crashes cause by dangling pointer returned from TQTextCodec::codecForLocale(). That might happen when tqWarning() and such are called during final cleanup. 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 1c6df6953..dd92d1cfe 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 cleansed!" );
#endif
all = new TQValueList<TQTextCodec*>;