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.

Bug: https://mirror.git.trinitydesktop.org/gitea/TDE/tqt3/issues/142
Signed-off-by: Alexander Golubev <fatzer2@gmail.com>
fix/tqtextcodec-locale-destr
Alexander Golubev 1 month ago
parent fb0d62eec8
commit 12b8263757

@ -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*>;

Loading…
Cancel
Save