[Kbabel] KBabel project crashes

Nicolas Goutte nicolasg at snafu.de
Sun Jan 29 19:44:55 CET 2006


In KDE Bugs, there are a few bug report about crashes closely related to 
KBabel's projects.

I think that I have finally found the main reason. The core of the problem is 
that the class Project (defined in kdesdk/kbabel/common/kbproject.h) inherits 
from KShared (defined in kdelibs/kdecore/ksharedptr.h).

KShared-derived classes are supposed to be maily handled by the KSharedPtr 
class (also defined in kdelibs/kdecore/ksharedptr.h), which handles the 
reference counter of the KShared-dereived class.

Unfortunately KBabel's ProjectManager class (defined in kdesdk/kbabel/common/
kbprojectmanager.h) does not handle the Project class with the care needed by 
a KShared-deried class.

A KShared-class should be refered and derefered either implicetly by the 
KSharePtr or by calling explicitely the needed functions in KShared.

Unfortunately, ProjectManager::open creates a Project object with new and 
assign it to a KSharedPtr and put that project pointer to QPtrList. However 
at the end of the function the KSharedPtr is destructed too and the reference 
count of the Project object is brought to zero and the project object is 
deleted. So the QPtrList pointer is becoming dangling, main reason of the 
crashes.

*

So now that I have found the problem, I do *not* have a solution, especially a 
binary compatible one. I had tried something by explicitely refering and 
derefering in ProjectManager but missed that we have no derefering function. 
(ProjectManager::remove is not such a function.)

So I am not sure what to do. May be you have an idea. 

Introducing a function in ProjectManager for dereferencing is perhaps a way to 
go but I do not know how much code needs to be changed elsewhere (nor its 
impact on potentially existing third party programs for KBabel, as the 
Project and ProjectManager classes are supposed to be blubic, as their header 
files are installed.

(At least writing that email was already an help, as I have relaised my error 
with ProjectManager::remove.)

Have a nice day!



More information about the kbabel mailing list