diff options
author | Alexander Golubev <[email protected]> | 2024-03-19 05:56:36 +0300 |
---|---|---|
committer | Alexander Golubev <[email protected]> | 2024-03-29 20:43:05 +0300 |
commit | ffbaaf0e1c181dd0f0d8ad7b273530f7cda086da (patch) | |
tree | 97be39accc7e8ba326d6e36d335405b69e810049 /src | |
parent | fb0d62eec811ab2d4d73550e455944cecbe7e091 (diff) | |
download | tqt3-ffbaaf0e1c181dd0f0d8ad7b273530f7cda086da.tar.gz tqt3-ffbaaf0e1c181dd0f0d8ad7b273530f7cda086da.zip |
Improve TQFont-related cleanup
Improve TQFont cleanup making sure that all instances of TQFont are
destroyed before TQApplication (or specifically before disconnect from
X11). This gets reed of several valgrind complains about leaks deep
inside fontconfig.
Signed-off-by: Alexander Golubev <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/kernel/ntqobject.h | 1 | ||||
-rw-r--r-- | src/kernel/qapplication.cpp | 6 | ||||
-rw-r--r-- | src/kernel/qfont_x11.cpp | 1 | ||||
-rw-r--r-- | src/kernel/qobject.cpp | 7 | ||||
-rw-r--r-- | src/kernel/qrichtext_p.cpp | 21 | ||||
-rw-r--r-- | src/kernel/qrichtext_p.h | 1 | ||||
-rw-r--r-- | src/styles/qcommonstyle.cpp | 5 |
7 files changed, 41 insertions, 1 deletions
diff --git a/src/kernel/ntqobject.h b/src/kernel/ntqobject.h index fc16c50bd..19df54726 100644 --- a/src/kernel/ntqobject.h +++ b/src/kernel/ntqobject.h @@ -237,6 +237,7 @@ public: #endif private: + void cleanupControlElementData(); #ifdef TQT_THREAD_SUPPORT void moveToThread_helper(TQThread *targetThread); void setThreadObject_helper(TQThread *targetThread); diff --git a/src/kernel/qapplication.cpp b/src/kernel/qapplication.cpp index e8658cdab..87d4fd7d0 100644 --- a/src/kernel/qapplication.cpp +++ b/src/kernel/qapplication.cpp @@ -1203,6 +1203,12 @@ TQApplication::~TQApplication() tqt_desktopWidget = 0; is_app_closing = TRUE; + // Due to hacks to spead up TQStyle engine (see git hash 523c1fd99) TQObjects now contain a + // reference to TQStyleControlElementData object which among other contain TQFont members. + // But for a proper cleanup all fonts should be destroyed before disconnecting from X11 (in + // tqt_cleanup()). So we will have to cleanup up the data explicitly. + cleanupControlElementData(); + #ifndef TQT_NO_CLIPBOARD delete tqt_clipboard; tqt_clipboard = 0; diff --git a/src/kernel/qfont_x11.cpp b/src/kernel/qfont_x11.cpp index 9f86734a4..3cd207c65 100644 --- a/src/kernel/qfont_x11.cpp +++ b/src/kernel/qfont_x11.cpp @@ -312,6 +312,7 @@ void TQFont::cleanup() { // delete the global font cache delete TQFontCache::instance; + TQFontCache::instance = 0; } /*! diff --git a/src/kernel/qobject.cpp b/src/kernel/qobject.cpp index 3ab2d9b97..bb4c848b8 100644 --- a/src/kernel/qobject.cpp +++ b/src/kernel/qobject.cpp @@ -134,6 +134,13 @@ TQStyleControlElementDataPrivate* TQObject::controlElementDataPrivateObject() { return d->controlElementDataPrivate; } +void TQObject::cleanupControlElementData() { + delete d->controlElementData; + d->controlElementData = 0; + delete d->controlElementDataPrivate; + d->controlElementDataPrivate = 0; +} + #if defined(TQT_THREAD_SUPPORT) void TQObject::moveToThread_helper(TQThread *targetThread) diff --git a/src/kernel/qrichtext_p.cpp b/src/kernel/qrichtext_p.cpp index 4411b4d45..022eb13de 100644 --- a/src/kernel/qrichtext_p.cpp +++ b/src/kernel/qrichtext_p.cpp @@ -337,6 +337,19 @@ int TQTextFormat::pntr_asc=-1; int TQTextFormat::pntr_hei=-1; int TQTextFormat::pntr_dsc=-1; +void TQTextFormat::cleanupPrivateData() { + delete TQTextFormat::pntr_fm; + TQTextFormat::pntr_fm = 0; + TQTextFormat::pntr = 0; + + // Not really necessary, but better to tidy-up everything + TQTextFormat::pntr_fm = 0; + TQTextFormat::pntr_ldg=-1; + TQTextFormat::pntr_asc=-1; + TQTextFormat::pntr_hei=-1; + TQTextFormat::pntr_dsc=-1; +} + void TQTextFormat::setPainter( TQPainter *p ) { pntr = p; @@ -350,10 +363,16 @@ TQPainter* TQTextFormat::painter() void TQTextFormat::applyFont( const TQFont &f ) { TQFontMetrics fm( pntr->fontMetrics() ); + + if ( !pntr_fm ) { + tqAddPostRoutine( &TQTextFormat::cleanupPrivateData ); + } + if ( !pntr_fm || pntr_fm->painter != pntr || pntr_fm->d != fm.d - || !pntr->font().isCopyOf( f ) ) { + || !pntr->font().isCopyOf( f ) + ) { pntr->setFont( f ); delete pntr_fm; pntr_fm = new TQFontMetrics( pntr->fontMetrics() ); diff --git a/src/kernel/qrichtext_p.h b/src/kernel/qrichtext_p.h index df6b0a272..428b0ec5d 100644 --- a/src/kernel/qrichtext_p.h +++ b/src/kernel/qrichtext_p.h @@ -1561,6 +1561,7 @@ protected: private: void update(); static void applyFont( const TQFont &f ); + static void cleanupPrivateData(); private: TQFont fn; diff --git a/src/styles/qcommonstyle.cpp b/src/styles/qcommonstyle.cpp index a9bfbcf28..f5c57d46f 100644 --- a/src/styles/qcommonstyle.cpp +++ b/src/styles/qcommonstyle.cpp @@ -165,6 +165,10 @@ static TQString TQFrame_static_string("TQFrame"); static TQString TQWidget_static_string("TQWidget"); static TQStyleControlElementData* TQStyleControlElementData_null = NULL; +static void tqt_style_control_element_data_null_cleanup() { + delete TQStyleControlElementData_null; + TQStyleControlElementData_null =0; +} #include <ntqmetaobject.h> @@ -805,6 +809,7 @@ const TQStyleControlElementData &populateControlElementDataFromWidget(const TQWi else { if (!TQStyleControlElementData_null) { TQStyleControlElementData_null = new TQStyleControlElementData(); + tqAddPostRoutine(tqt_style_control_element_data_null_cleanup); } TQStyleControlElementData &ceData = *TQStyleControlElementData_null; return ceData; |