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 <fatzer2@gmail.com>
fix/various
Alexander Golubev 8 months ago
parent fb0d62eec8
commit 676000853b

@ -145,6 +145,7 @@ public:
TQStyleControlElementData* controlElementDataObject(); TQStyleControlElementData* controlElementDataObject();
TQStyleControlElementDataPrivate* controlElementDataPrivateObject(); TQStyleControlElementDataPrivate* controlElementDataPrivateObject();
void cleanupControlElementData();
#ifndef TQT_NO_PROPERTIES #ifndef TQT_NO_PROPERTIES
virtual bool setProperty( const char *name, const TQVariant& value ); virtual bool setProperty( const char *name, const TQVariant& value );

@ -1203,6 +1203,12 @@ TQApplication::~TQApplication()
tqt_desktopWidget = 0; tqt_desktopWidget = 0;
is_app_closing = TRUE; is_app_closing = TRUE;
// Due to hacks to speadup TQStyle engine (see git hash 523c1fd99) TQObjects now contain a
// reference to TQStyleControlElementData object which among other contain TQFont memebers.
// 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 #ifndef TQT_NO_CLIPBOARD
delete tqt_clipboard; delete tqt_clipboard;
tqt_clipboard = 0; tqt_clipboard = 0;

@ -312,6 +312,7 @@ void TQFont::cleanup()
{ {
// delete the global font cache // delete the global font cache
delete TQFontCache::instance; delete TQFontCache::instance;
TQFontCache::instance = 0;
} }
/*! /*!

@ -134,6 +134,13 @@ TQStyleControlElementDataPrivate* TQObject::controlElementDataPrivateObject() {
return d->controlElementDataPrivate; return d->controlElementDataPrivate;
} }
void TQObject::cleanupControlElementData() {
delete d->controlElementData;
d->controlElementData = 0;
delete d->controlElementDataPrivate;
d->controlElementDataPrivate = 0;
}
#if defined(TQT_THREAD_SUPPORT) #if defined(TQT_THREAD_SUPPORT)
void TQObject::moveToThread_helper(TQThread *targetThread) void TQObject::moveToThread_helper(TQThread *targetThread)

@ -337,6 +337,19 @@ int TQTextFormat::pntr_asc=-1;
int TQTextFormat::pntr_hei=-1; int TQTextFormat::pntr_hei=-1;
int TQTextFormat::pntr_dsc=-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 ) void TQTextFormat::setPainter( TQPainter *p )
{ {
pntr = p; pntr = p;
@ -350,10 +363,16 @@ TQPainter* TQTextFormat::painter()
void TQTextFormat::applyFont( const TQFont &f ) void TQTextFormat::applyFont( const TQFont &f )
{ {
TQFontMetrics fm( pntr->fontMetrics() ); TQFontMetrics fm( pntr->fontMetrics() );
if ( !pntr_fm ) {
tqAddPostRoutine( &TQTextFormat::cleanupPrivateData );
}
if ( !pntr_fm if ( !pntr_fm
|| pntr_fm->painter != pntr || pntr_fm->painter != pntr
|| pntr_fm->d != fm.d || pntr_fm->d != fm.d
|| !pntr->font().isCopyOf( f ) ) { || !pntr->font().isCopyOf( f )
) {
pntr->setFont( f ); pntr->setFont( f );
delete pntr_fm; delete pntr_fm;
pntr_fm = new TQFontMetrics( pntr->fontMetrics() ); pntr_fm = new TQFontMetrics( pntr->fontMetrics() );

@ -1561,6 +1561,7 @@ protected:
private: private:
void update(); void update();
static void applyFont( const TQFont &f ); static void applyFont( const TQFont &f );
static void cleanupPrivateData();
private: private:
TQFont fn; TQFont fn;

@ -165,6 +165,10 @@ static TQString TQFrame_static_string("TQFrame");
static TQString TQWidget_static_string("TQWidget"); static TQString TQWidget_static_string("TQWidget");
static TQStyleControlElementData* TQStyleControlElementData_null = NULL; static TQStyleControlElementData* TQStyleControlElementData_null = NULL;
static void tqt_style_control_element_data_null_cleanup() {
delete TQStyleControlElementData_null;
TQStyleControlElementData_null =0;
}
#include <ntqmetaobject.h> #include <ntqmetaobject.h>
@ -805,6 +809,7 @@ const TQStyleControlElementData &populateControlElementDataFromWidget(const TQWi
else { else {
if (!TQStyleControlElementData_null) { if (!TQStyleControlElementData_null) {
TQStyleControlElementData_null = new TQStyleControlElementData(); TQStyleControlElementData_null = new TQStyleControlElementData();
tqAddPostRoutine(tqt_style_control_element_data_null_cleanup);
} }
TQStyleControlElementData &ceData = *TQStyleControlElementData_null; TQStyleControlElementData &ceData = *TQStyleControlElementData_null;
return ceData; return ceData;

Loading…
Cancel
Save