diff options
author | Honglei Zhang <honglei.zhang@nokia.com> | 2011-04-27 06:19:57 (GMT) |
---|---|---|
committer | Qt Commercial Integration <QtCommercial@digia.com> | 2012-01-31 10:24:53 (GMT) |
commit | d56db447348d7b641097bf146d188751ba8a76ae (patch) | |
tree | 81b062ada1c86430788d56c543d21f0a65f96bc0 /src | |
parent | baba87e49b249b05277bb29af3e54f70fcbb3520 (diff) | |
download | Qt-d56db447348d7b641097bf146d188751ba8a76ae.zip Qt-d56db447348d7b641097bf146d188751ba8a76ae.tar.gz Qt-d56db447348d7b641097bf146d188751ba8a76ae.tar.bz2 |
Fix memory leak in XSD component of XmlPatterns
There are couple of memory leaks in XmlPatterns when parsing XSD
files. The reason is that the module over uses the shared data
pointer and generates many cyclic reference loop. Some part of
the code is refactored. Instead of using shared data pointer,
normal C++ pointer is used to break the ownership loop. This is
bug fix for QTBUG-8948.
Task-number: QTBUG-8948
Reviewed-by: Sami Merila and Laszlo Agocs
Diffstat (limited to 'src')
-rw-r--r-- | src/xmlpatterns/schema/qxsdattribute.cpp | 4 | ||||
-rw-r--r-- | src/xmlpatterns/schema/qxsdattribute_p.h | 2 | ||||
-rw-r--r-- | src/xmlpatterns/schema/qxsdcomplextype.cpp | 4 | ||||
-rw-r--r-- | src/xmlpatterns/schema/qxsdcomplextype_p.h | 2 | ||||
-rw-r--r-- | src/xmlpatterns/schema/qxsdelement.cpp | 8 | ||||
-rw-r--r-- | src/xmlpatterns/schema/qxsdelement_p.h | 8 | ||||
-rw-r--r-- | src/xmlpatterns/schema/qxsdparticlechecker.cpp | 6 | ||||
-rw-r--r-- | src/xmlpatterns/schema/qxsdsimpletype.cpp | 4 | ||||
-rw-r--r-- | src/xmlpatterns/schema/qxsdsimpletype_p.h | 2 | ||||
-rw-r--r-- | src/xmlpatterns/schema/qxsdstatemachinebuilder.cpp | 10 |
10 files changed, 25 insertions, 25 deletions
diff --git a/src/xmlpatterns/schema/qxsdattribute.cpp b/src/xmlpatterns/schema/qxsdattribute.cpp index 662f043..4f7d796 100644 --- a/src/xmlpatterns/schema/qxsdattribute.cpp +++ b/src/xmlpatterns/schema/qxsdattribute.cpp @@ -59,12 +59,12 @@ XsdAttribute::Scope::Variety XsdAttribute::Scope::variety() const void XsdAttribute::Scope::setParent(const NamedSchemaComponent::Ptr &parent) { - m_parent = parent; + m_parent = parent.data(); } NamedSchemaComponent::Ptr XsdAttribute::Scope::parent() const { - return m_parent; + return NamedSchemaComponent::Ptr(m_parent); } void XsdAttribute::ValueConstraint::setVariety(Variety variety) diff --git a/src/xmlpatterns/schema/qxsdattribute_p.h b/src/xmlpatterns/schema/qxsdattribute_p.h index 169c48a..e0e00a5 100644 --- a/src/xmlpatterns/schema/qxsdattribute_p.h +++ b/src/xmlpatterns/schema/qxsdattribute_p.h @@ -131,7 +131,7 @@ namespace QPatternist private: Variety m_variety; - NamedSchemaComponent::Ptr m_parent; + NamedSchemaComponent *m_parent; }; diff --git a/src/xmlpatterns/schema/qxsdcomplextype.cpp b/src/xmlpatterns/schema/qxsdcomplextype.cpp index 6577232..32e420a 100644 --- a/src/xmlpatterns/schema/qxsdcomplextype.cpp +++ b/src/xmlpatterns/schema/qxsdcomplextype.cpp @@ -140,12 +140,12 @@ SchemaType::Ptr XsdComplexType::wxsSuperType() const void XsdComplexType::setContext(const NamedSchemaComponent::Ptr &component) { - m_context = component; + m_context = component.data(); } NamedSchemaComponent::Ptr XsdComplexType::context() const { - return m_context; + return NamedSchemaComponent::Ptr(m_context); } void XsdComplexType::setContentType(const ContentType::Ptr &type) diff --git a/src/xmlpatterns/schema/qxsdcomplextype_p.h b/src/xmlpatterns/schema/qxsdcomplextype_p.h index 5e2a8dc..1b90e5d 100644 --- a/src/xmlpatterns/schema/qxsdcomplextype_p.h +++ b/src/xmlpatterns/schema/qxsdcomplextype_p.h @@ -386,7 +386,7 @@ namespace QPatternist private: SchemaType::Ptr m_superType; - NamedSchemaComponent::Ptr m_context; + NamedSchemaComponent *m_context; DerivationMethod m_derivationMethod; bool m_isAbstract; XsdAttributeUse::List m_attributeUses; diff --git a/src/xmlpatterns/schema/qxsdelement.cpp b/src/xmlpatterns/schema/qxsdelement.cpp index df11c91..dda0f54 100644 --- a/src/xmlpatterns/schema/qxsdelement.cpp +++ b/src/xmlpatterns/schema/qxsdelement.cpp @@ -57,12 +57,12 @@ XsdElement::Scope::Variety XsdElement::Scope::variety() const void XsdElement::Scope::setParent(const NamedSchemaComponent::Ptr &parent) { - m_parent = parent; + m_parent = parent.data(); } NamedSchemaComponent::Ptr XsdElement::Scope::parent() const { - return m_parent; + return NamedSchemaComponent::Ptr(m_parent); } void XsdElement::ValueConstraint::setVariety(Variety variety) @@ -233,10 +233,10 @@ XsdElement::List XsdElement::substitutionGroupAffiliations() const void XsdElement::addSubstitutionGroup(const XsdElement::Ptr &element) { - m_substitutionGroups.insert(element); + m_substitutionGroups.insert(element.data()); } -XsdElement::List XsdElement::substitutionGroups() const +XsdElement::WeakList XsdElement::substitutionGroups() const { return m_substitutionGroups.toList(); } diff --git a/src/xmlpatterns/schema/qxsdelement_p.h b/src/xmlpatterns/schema/qxsdelement_p.h index ac1755a..3b9dd88 100644 --- a/src/xmlpatterns/schema/qxsdelement_p.h +++ b/src/xmlpatterns/schema/qxsdelement_p.h @@ -85,7 +85,7 @@ namespace QPatternist public: typedef QExplicitlySharedDataPointer<XsdElement> Ptr; typedef QList<XsdElement::Ptr> List; - + typedef QList<XsdElement *> WeakList; /** * Describes the <a href="http://www.w3.org/TR/xmlschema11-1/#ed-value_constraint">constraint type</a> of the element. @@ -138,7 +138,7 @@ namespace QPatternist private: Variety m_variety; - NamedSchemaComponent::Ptr m_parent; + NamedSchemaComponent *m_parent; }; /** @@ -379,7 +379,7 @@ namespace QPatternist /** * Returns the substitution groups of the element. */ - XsdElement::List substitutionGroups() const; + XsdElement::WeakList substitutionGroups() const; private: SchemaType::Ptr m_type; @@ -392,7 +392,7 @@ namespace QPatternist SchemaType::DerivationConstraints m_substitutionGroupExclusions; XsdIdentityConstraint::List m_identityConstraints; XsdElement::List m_substitutionGroupAffiliations; - QSet<XsdElement::Ptr> m_substitutionGroups; + QSet<XsdElement *> m_substitutionGroups; }; } diff --git a/src/xmlpatterns/schema/qxsdparticlechecker.cpp b/src/xmlpatterns/schema/qxsdparticlechecker.cpp index d5f6731..748e4d5 100644 --- a/src/xmlpatterns/schema/qxsdparticlechecker.cpp +++ b/src/xmlpatterns/schema/qxsdparticlechecker.cpp @@ -309,12 +309,12 @@ static bool hasDuplicatedElementsInternal(const XsdParticle::Ptr &particle, cons const XsdTerm::Ptr term = particle->term(); if (term->isElement()) { const XsdElement::Ptr mainElement(term); - XsdElement::List substGroups = mainElement->substitutionGroups(); + XsdElement::WeakList substGroups = mainElement->substitutionGroups(); if (substGroups.isEmpty()) - substGroups << mainElement; + substGroups << mainElement.data(); for (int i = 0; i < substGroups.count(); ++i) { - const XsdElement::Ptr element = substGroups.at(i); + const XsdElement::Ptr element(substGroups.at(i)); if (hash.contains(element->name(namePool))) { if (element->type()->name(namePool) != hash.value(element->name(namePool))->type()->name(namePool)) { conflictingElement = element; diff --git a/src/xmlpatterns/schema/qxsdsimpletype.cpp b/src/xmlpatterns/schema/qxsdsimpletype.cpp index 03a16d4..5b8bb57 100644 --- a/src/xmlpatterns/schema/qxsdsimpletype.cpp +++ b/src/xmlpatterns/schema/qxsdsimpletype.cpp @@ -72,12 +72,12 @@ SchemaType::Ptr XsdSimpleType::wxsSuperType() const void XsdSimpleType::setContext(const NamedSchemaComponent::Ptr &component) { - m_context = component; + m_context = component.data(); } NamedSchemaComponent::Ptr XsdSimpleType::context() const { - return m_context; + return NamedSchemaComponent::Ptr(m_context); } void XsdSimpleType::setPrimitiveType(const AnySimpleType::Ptr &type) diff --git a/src/xmlpatterns/schema/qxsdsimpletype_p.h b/src/xmlpatterns/schema/qxsdsimpletype_p.h index 9d5a047..11b7394 100644 --- a/src/xmlpatterns/schema/qxsdsimpletype_p.h +++ b/src/xmlpatterns/schema/qxsdsimpletype_p.h @@ -202,7 +202,7 @@ namespace QPatternist private: SchemaType::Ptr m_superType; - NamedSchemaComponent::Ptr m_context; + NamedSchemaComponent* m_context; AnySimpleType::Ptr m_primitiveType; AnySimpleType::Ptr m_itemType; AnySimpleType::List m_memberTypes; diff --git a/src/xmlpatterns/schema/qxsdstatemachinebuilder.cpp b/src/xmlpatterns/schema/qxsdstatemachinebuilder.cpp index df81ea6..3570cc6 100644 --- a/src/xmlpatterns/schema/qxsdstatemachinebuilder.cpp +++ b/src/xmlpatterns/schema/qxsdstatemachinebuilder.cpp @@ -166,14 +166,14 @@ XsdStateMachine<XsdTerm::Ptr>::StateId XsdStateMachineBuilder::buildTerm(const X const XsdElement::Ptr element(term); if (m_mode == CheckingMode) { - const XsdElement::List substGroups = element->substitutionGroups(); + const XsdElement::WeakList substGroups = element->substitutionGroups(); for (int i = 0; i < substGroups.count(); ++i) - m_stateMachine->addTransition(b, substGroups.at(i), endState); + m_stateMachine->addTransition(b, XsdElement::Ptr(substGroups.at(i)), endState); } else if (m_mode == ValidatingMode) { - const XsdElement::List substGroups = element->substitutionGroups(); + const XsdElement::WeakList substGroups = element->substitutionGroups(); for (int i = 0; i < substGroups.count(); ++i) { - if (XsdSchemaHelper::substitutionGroupOkTransitive(element, substGroups.at(i), m_namePool)) - m_stateMachine->addTransition(b, substGroups.at(i), endState); + if (XsdSchemaHelper::substitutionGroupOkTransitive(element, XsdElement::Ptr(substGroups.at(i)), m_namePool)) + m_stateMachine->addTransition(b, XsdElement::Ptr(substGroups.at(i)), endState); } } |