[Patch] Fix undeleted "static QFont *_font" in kglobalsettings.cpp

Friedrich W. H. Kossebau kossebau at kde.org
Thu Dec 4 13:16:15 GMT 2008


Hi,

while putting Okteta into valgrind's memcheck I found that it looks like all 
the static fonts defined in
	kdelibs/kdeui/kernel/kglobalsettings.cpp
are not cleaned up on program exit.

For practice, good code behaviour and to reduce the ouput of memcheck I would 
like to change that, and here is my first^Wsecond approach:

The attached patch puts all the file-globally declared objects (fonts, 
mousesettings) into a container class, which creates them lazyly as before, 
but now deletes them on destruction. That container is accessed via
	inline GlobalSettingsData* GlobalSettingsData::self()
	{
		K_GLOBAL_STATIC(GlobalSettingsData, s_self)
		return s_self;
	}
This should ensure correct construction and destruction at the lifetime of the 
process, right?

I decided against reusing KGlobalSettings::Private as the container, because 
the old font functions did not create the KGlobalSettings singleton but could 
be used without it. I could not oversee the sideeffects by changing that. Can 
you?
For KDE5 the API of KGlobalSettings might want to be fixed (static vs. 
non-static), I added this as comment.

Additional bonus of the patch: shrinks all repeating font object creation code 
into a single one and collects the default data into a table.

Two best practice questions, for handling the "QFont* mFonts[FontCount]" :
1. How to set an array of pointers all to 0 most efficiently (mFonts)?
2. How to mark the number of entries in an enum, so adding one more increases 
that number (FontCount) automatically?

Cheers
Friedrich
-- 
Okteta - KDE 4 Hex Editor - http://utils.kde.org/projects/okteta
-------------- next part --------------
A non-text attachment was scrubbed...
Name: deleteStaticDataOfKGlobalSettings2.patch
Type: text/x-diff
Size: 17217 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20081204/c682901d/attachment.patch>


More information about the kde-core-devel mailing list