~KDirLister accessing already destroyed object

David Faure faure at kde.org
Mon Oct 1 10:29:34 BST 2007


On Monday 01 October 2007, Olivier Goffart wrote:
> Le lundi 1 octobre 2007, David Faure a écrit :
> > On Monday 01 October 2007, Dennis Nienhüser wrote:
> > > I'm trying to fix a crash that occurs when closing Kopete and think it's
> > > caused by the KDirLister destructor. ~KDirLister calls stop() on its
> > > cache, which is a singleton created by the K_GLOBAL_STATIC macro and
> > > seems to get destroyed before ~KDirLister is called on my system.
> >
> > Why is that? Your KDirLister is a global static too? That seems like a very
> > strange idea....
> 
> The KDirLister is a child object of a global static singleton.

We have to limit our use of global statics. Their order of deletion is undefined, which
gives problems such as this one.
But OK for the patch, since others will for sure hit this problem one day or another.
+ if (KDirListerCache::self())
reads a bit strange, one would never expect it to return 0, maybe better to use
 if (s_pCache.isDestroyed()) directly instead? Or is the self() fix required anyway
for other places?

-- 
David Faure, faure at kde.org, sponsored by Trolltech to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).




More information about the kde-core-devel mailing list