OSDN Git Service

guard against QTextCodecCleanup recreation in QTextCodec destructor
authorIvailo Monev <xakepa10@gmail.com>
Wed, 26 Jan 2022 21:17:58 +0000 (23:17 +0200)
committerIvailo Monev <xakepa10@gmail.com>
Wed, 26 Jan 2022 21:17:58 +0000 (23:17 +0200)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
src/core/codecs/qtextcodec.cpp

index d02d648..f9f73b1 100644 (file)
@@ -76,6 +76,7 @@ public:
     ~QTextCodecCleanup();
 };
 
+static bool removecodecs = true;
 /*
     Deletes all the created codecs. This destructor is called just
     before exiting to delete any QTextCodec objects that may be lying
@@ -83,8 +84,9 @@ public:
 */
 QTextCodecCleanup::~QTextCodecCleanup()
 {
-    while (begin() != end()) {
-        delete *begin();
+    removecodecs = false;
+    while (!isEmpty()) {
+        delete takeLast();
     }
     localeMapper = nullptr;
 #ifndef QT_NO_DEBUG
@@ -419,10 +421,12 @@ QTextCodec::QTextCodec()
 */
 QTextCodec::~QTextCodec()
 {
+    if (removecodecs) {
 #ifndef QT_NO_THREAD
-    QMutexLocker locker(textCodecsMutex());
+        QMutexLocker locker(textCodecsMutex());
 #endif
-    qGlobalQTextCodec()->removeAll(this);
+        qGlobalQTextCodec()->removeAll(this);
+    }
 }
 
 /*!