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

Friedrich W. H. Kossebau kossebau at kde.org
Thu Dec 4 20:41:58 GMT 2008


Am Donnerstag, 4. Dezember 2008, um 14:16 Uhr, schrieb Friedrich W. H. 
Kossebau:
> 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.

Fixed are the namespace pollution (added a K-prefix to all classes) and the 
issue with K_GLOBAL_STATIC for KGlobalSettingsData (used outside of function, 
made KGlobalSettingsData constructor public for that). Treated the enum to 
the best of my updated knowledge, thanks for all hints (no FooBegin though, 
as that needs to be 0, used as array index).

Not fixed is the existing wrong use of K_GLOBAL_STATIC for KGlobalSettings, as 
this is not scope of this patch. Should be fixed afterwards.

Any other issues with this patch? If not, I will commit on first "Go!" or 
during the weekend. :)

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


More information about the kde-core-devel mailing list