OSDN Git Service

plug QUnifiedTimer, QtFreetypeData and QHttpThreadDelegate memory leaks
authorIvailo Monev <xakepa10@gmail.com>
Mon, 29 Nov 2021 11:56:55 +0000 (13:56 +0200)
committerIvailo Monev <xakepa10@gmail.com>
Mon, 29 Nov 2021 11:56:55 +0000 (13:56 +0200)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
src/core/qcorecommon_p.h
src/gui/animation/qabstractanimation.cpp
src/gui/text/qfontengine_ft.cpp
src/network/access/qhttpthreaddelegate.cpp

index 162b331..f39a906 100644 (file)
@@ -24,6 +24,25 @@ QT_BEGIN_NAMESPACE
     arraytype arrayname[arraysize]; \
     ::memset(arrayname, 0, arraysize * sizeof(arraytype));
 
+template <typename T>
+class QThreadLocalDeleter
+{
+public:
+    T* threadLocal;
+    QThreadLocalDeleter(T* _threadLocal)
+        : threadLocal(_threadLocal)
+    { }
+
+    inline ~QThreadLocalDeleter()
+    {
+        delete threadLocal;
+    }
+};
+
+#define QTHREADLOCAL(localtype, localname) \
+    thread_local localtype* localname(nullptr); \
+    thread_local QThreadLocalDeleter<localtype> localname## _deleter(localname);
+
 static const qreal q_deg2rad = qreal(0.01745329251994329576923690768489); /* pi/180 */
 static const qreal q_rad2deg = qreal(57.295779513082320876798154814105); /* 180/pi */
 
index 227068e..0268fc7 100644 (file)
 #include "qabstractanimation.h"
 #include "qanimationgroup.h"
 #include "qabstractanimation_p.h"
-
-#include <QtCore/qdebug.h>
-#include <QtCore/qmath.h>
-#include <QtCore/qcoreevent.h>
-#include <QtCore/qpointer.h>
+#include "qdebug.h"
+#include "qmath.h"
+#include "qcoreevent.h"
+#include "qpointer.h"
+#include "qcorecommon_p.h"
 
 #ifndef QT_NO_ANIMATION
 
 
 QT_BEGIN_NAMESPACE
 
-thread_local QUnifiedTimer* unifiedTimer = nullptr;
+QTHREADLOCAL(QUnifiedTimer, unifiedTimer);
 
 QUnifiedTimer::QUnifiedTimer() :
     QObject(), lastTick(0), currentAnimationIdx(0), insideTick(false),
index 2477beb..dc2ca00 100644 (file)
@@ -29,6 +29,7 @@
 #include "qharfbuzz_p.h"
 #include "qfontengine_ft_p.h"
 #include "qguicommon_p.h"
+#include "qcorecommon_p.h"
 
 #include <ft2build.h>
 #include FT_FREETYPE_H
@@ -78,7 +79,7 @@ public:
     QHash<QFontEngine::FaceId, QFreetypeFace *> faces;
 };
 
-thread_local QtFreetypeData* theFreetypeData = nullptr;
+QTHREADLOCAL(QtFreetypeData, theFreetypeData);
 
 QtFreetypeData *qt_getFreetypeData()
 {
index 752b693..2eede01 100644 (file)
@@ -160,6 +160,8 @@ QHttpThreadDelegate::~QHttpThreadDelegate()
     // and release the entry for this QHttpNetworkConnection
     if (connections && !cacheKey.isEmpty()) {
         connections->releaseEntry(cacheKey);
+        delete connections;
+        connections = nullptr;
     }
 }
 
@@ -202,6 +204,7 @@ void QHttpThreadDelegate::startRequestSynchronously()
     synchronousRequestLoop.exec();
 
     connections->releaseEntry(cacheKey);
+    delete connections;
     connections = nullptr;
 
 #ifdef QHTTPTHREADDELEGATE_DEBUG