[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: Got some bugs here
From:       Waldo Bastian <bastian () kde ! org>
Date:       2002-01-31 2:27:29
[Download RAW message or body]

On Wednesday 30 January 2002 12:11 pm, Simon Hausmann wrote:
> On Wed, Jan 30, 2002 at 09:11:01PM +0100, Martijn Klingens wrote:
> > On Wednesday 30 January 2002 20:49, Michael Brade wrote:
> > > But I found that KFileMetaInfo is using a KStaticDeleter as well - so
> > > is it possible that one of the static deleters is deleted too early or
> > > too late? Has anybody a tool for searching already deleted pointers
> > > that are accessed again later?
> >
> > I think a good habit would be to do the C++ equivalent of Delphi's
> > FreeAndNil function, i.e. free the pointer *and* set it to NULL, so the
> > backtrace makes it instantly clear that you are trying to access a null
> > pointer afterwards.
>
> KStaticDeleter does that. Upon registration of your singleton with
> your static deleter you pass a reference to the variable (pointer) holding
> it.

In a cruel twist of faith this actually causes the crashes. You see, "null" 
was used as special value and null-items aren't refcounted. So the destructor 
of the object that owned these refcounted objects only dereffed the object if 
it was != "null", however, after resetting "null" to 0,  object-ptrs which 
were originally "null" now became != "null" since the value of "null" 
changed. So when we later enter the earlier mentioned destructor and the 
object still has a pointer to this null object, the destructor compares the 
pointer against "null" and incorrectly decides that it isn't the "null" 
object and that it should be dereffed. This leads to a crash eventually, 
since it now derefs the null object, which it shouldn't, and which had been 
destroyed already.

Fixed in CVS.

This also seems to imply that there are still KFileMetaInfo objects around 
while KFileMetaInfo::Data::null has been destroyed already. that's ok as long 
as the only thing done with them is destruction. But they might/will cause 
crashes if they are used in any other way.

Cheers,
Waldo
-- 
bastian@kde.org  |   SuSE Labs KDE Developer  |  bastian@suse.com

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic