Commit 49aaa21f authored by Ralf Habacker's avatar Ralf Habacker

Fix 'Dangling pointer issue on document close'.

Guard access to UMLObject::m_pSecondary with QPointer.
Also use dynamic_cast instead of static_cast for access
to m_pSecondary to make sure the cast returns zero on
invalid types. Using static_casts may result into
invalid casted objects.

BUG:345388
FIXED-IN:2.15.97 (KDE 15.03.97)
parent 4a9d9bc3
......@@ -1279,7 +1279,7 @@ void UMLClassifier::setOriginType(UMLClassifier *origType)
*/
UMLClassifier * UMLClassifier::originType() const
{
return static_cast<UMLClassifier*>(m_pSecondary);
return dynamic_cast<UMLClassifier*>(m_pSecondary.data());
}
/**
......
......@@ -99,7 +99,7 @@ QString UMLClassifierListItem::toString(Uml::SignatureType::Enum sig)
*/
UMLClassifier * UMLClassifierListItem::getType() const
{
return static_cast<UMLClassifier*>(m_pSecondary);
return dynamic_cast<UMLClassifier*>(m_pSecondary.data());
}
/**
......
......@@ -218,9 +218,7 @@ void UMLPackage::removeAllObjects()
if (pkg)
pkg->removeAllObjects();
removeObject(o);
//delete o;
// CHECK: Direct usage of the destructor crashes on associations.
o->deleteLater();
delete o;
}
}
......
......@@ -2529,6 +2529,8 @@ void UMLDoc::removeAllViews()
*/
void UMLDoc::removeAllObjects()
{
m_root[Uml::ModelType::Logical]->removeObject(m_datatypeRoot);
for (int i = 0; i < Uml::ModelType::N_MODELTYPES; ++i) {
m_root[i]->removeAllObjects();
}
......
......@@ -714,7 +714,7 @@ bool UMLObject::resolveRef()
m_pSecondary = pDoc->findObjectById(Uml::ID::fromString(m_SecondaryId));
if (m_pSecondary != NULL) {
if (m_pSecondary->baseType() == ot_Stereotype) {
m_pStereotype = static_cast<UMLStereotype*>(m_pSecondary);
m_pStereotype = dynamic_cast<UMLStereotype*>(m_pSecondary.data());
m_pStereotype->incrRefCount();
m_pSecondary = NULL;
}
......
......@@ -18,6 +18,7 @@
#include <QDomDocument>
#include <QDomElement>
#include <QObject>
#include <QPointer>
#include <QString>
class UMLStereotype;
......@@ -179,7 +180,7 @@ protected:
bool m_bStatic; ///< flag for instance scope
bool m_bInPaste; ///< caller sets this true when in paste operation
bool m_bCreationWasSignalled; ///< auxiliary to maybeSignalObjectCreated()
UMLObject* m_pSecondary; ///< pointer to an associated object
QPointer<UMLObject> m_pSecondary; ///< pointer to an associated object
///< Only a few of the classes inheriting from UMLObject use this.
///< However, it needs to be here because of inheritance graph
///< disjunctness.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment