One more question to kstaticdelter

Ingo Klöcker kloecker at kde.org
Tue May 1 13:10:06 BST 2007


On Tuesday 01 May 2007 11:04, Christian Ehrlicher wrote:
> Ingo Klöcker schrieb:
> > On Monday 30 April 2007 23:15, Thiago Macieira wrote:
> >> Christian Ehrlicher wrote:
> >>> Hi,
> >>>
> >>> kconfig_compiler creates code like this:
> >>>
> >>> Settings *Settings::mSelf = 0;
> >>> static KStaticDeleter<Settings> staticSettingsDeleter;
> >>>
> >>> Settings *Settings::self()
> >>> {
> >>>   if ( !mSelf ) {
> >>>     staticSettingsDeleter.setObject( mSelf, new Settings() );
> >>>     mSelf->readConfig();
> >>>   }
> >>>
> >>>   return mSelf;
> >>> }
> >>>
> >>> Settings::Settings(  )
> >>>
> >>>   : KConfigSkeleton( QLatin1String( "kgetrc" ) )
> >>>
> >>> {
> >>>   mSelf = this;
> >>>   ..
> >>>
> >>> }
> >>>
> >>> Settings::~Settings()
> >>> {
> >>>   if ( mSelf == this )
> >>>     staticSettingsDeleter.setObject( mSelf, 0, false );
> >>> }
> >>>
> >>> What's the best way to replace this? I would use a
> >>> QBasicAtomicPointer and qAddPostRoutine()... but I won't break
> >>> kconfig_compiler so I ask you
> >>>
> >>> :)
> >>
> >> Yes, that looks like it's the best option.
> >>
> >> However, if someone calls the constructor twice, it leaks memory.
> >> So, something is wrong.
> >
> > The constructor is not supposed to be called directly, but only
> > through self().
>
> But this can't be guaranteed because the ctor is not private.

That seems to be a bug then.

Regards,
Ingo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20070501/3534055d/attachment.sig>


More information about the kde-core-devel mailing list