summaryrefslogtreecommitdiffstats
path: root/src/xmlpatterns
diff options
context:
space:
mode:
authorHonglei Zhang <honglei.zhang@nokia.com>2011-04-27 06:19:57 (GMT)
committerHonglei Zhang <honglei.zhang@nokia.com>2011-04-27 10:54:37 (GMT)
commit27a24f1d009741b6e712300e7bc58b7e7e7d4c0b (patch)
tree92045141de1fda553cc45a04e020cca73337a32e /src/xmlpatterns
parent0061f7e015b10ccaa45dc35b68cac467ebad424a (diff)
downloadQt-27a24f1d009741b6e712300e7bc58b7e7e7d4c0b.zip
Qt-27a24f1d009741b6e712300e7bc58b7e7e7d4c0b.tar.gz
Qt-27a24f1d009741b6e712300e7bc58b7e7e7d4c0b.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/xmlpatterns')
-rw-r--r--src/xmlpatterns/schema/qxsdattribute.cpp4
-rw-r--r--src/xmlpatterns/schema/qxsdattribute_p.h2
-rw-r--r--src/xmlpatterns/schema/qxsdcomplextype.cpp4
-rw-r--r--src/xmlpatterns/schema/qxsdcomplextype_p.h2
-rw-r--r--src/xmlpatterns/schema/qxsdelement.cpp8
-rw-r--r--src/xmlpatterns/schema/qxsdelement_p.h8
-rw-r--r--src/xmlpatterns/schema/qxsdparticlechecker.cpp6
-rw-r--r--src/xmlpatterns/schema/qxsdsimpletype.cpp4
-rw-r--r--src/xmlpatterns/schema/qxsdsimpletype_p.h2
-rw-r--r--src/xmlpatterns/schema/qxsdstatemachinebuilder.cpp10
10 files changed, 25 insertions, 25 deletions
diff --git a/src/xmlpatterns/schema/qxsdattribute.cpp b/src/xmlpatterns/schema/qxsdattribute.cpp
index 68f9e3d..fb768d4 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 d64d335..a21fe70 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 42aeb60..0932060 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 d28d2fc..d02583c 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 1ebec06..b0c5661 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 93c5983..3794c96 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 15c2afe..d4beae7 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 6fd5658..3e77aca 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 6305fc7..a5b72a7 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 fed8a41..b6c8704 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);
}
}