summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHonglei Zhang <honglei.zhang@nokia.com>2011-04-19 14:29:27 (GMT)
committerHonglei Zhang <honglei.zhang@nokia.com>2011-04-19 14:29:27 (GMT)
commit986ab48f1128bdd56fa408fca8f4a564e874dd4d (patch)
tree46d5e20dbf23fbbc0d95b0a4bf111f301a45fa99 /src
parent6dcb0028e44cba2a00c2fb867fb1757ad5b1a254 (diff)
downloadQt-986ab48f1128bdd56fa408fca8f4a564e874dd4d.zip
Qt-986ab48f1128bdd56fa408fca8f4a564e874dd4d.tar.gz
Qt-986ab48f1128bdd56fa408fca8f4a564e874dd4d.tar.bz2
Fix memory leak bugs in XmlPatterns
In XmlPatterns implementation, QExplicitlySharedDataPointer and QSharedData classes are widely used. The over use of these classes has cuased couple of cyclic references. Some codes are refactored to use plain C++ pointer to break the reference loop. Task-number: QTBUG-15191 Reviewed-by: Laszlo Agocs and Sami Merila
Diffstat (limited to 'src')
-rw-r--r--src/xmlpatterns/data/qitem_p.h4
-rw-r--r--src/xmlpatterns/expr/qdynamiccontextstore.cpp8
-rw-r--r--src/xmlpatterns/expr/qdynamiccontextstore_p.h2
-rw-r--r--src/xmlpatterns/expr/qevaluationcache.cpp2
-rw-r--r--src/xmlpatterns/expr/qevaluationcache_p.h2
-rw-r--r--src/xmlpatterns/expr/qletclause.cpp2
6 files changed, 12 insertions, 8 deletions
diff --git a/src/xmlpatterns/data/qitem_p.h b/src/xmlpatterns/data/qitem_p.h
index 8184b25..fb3866e 100644
--- a/src/xmlpatterns/data/qitem_p.h
+++ b/src/xmlpatterns/data/qitem_p.h
@@ -408,6 +408,10 @@ namespace QPatternist
inline void reset()
{
+ /* Delete the atomicValue if necessary*/
+ if(isAtomicValue() && !atomicValue->ref.deref())
+ delete atomicValue;
+
/* Note that this function should be equal to the default
* constructor. */
node.model = 0;
diff --git a/src/xmlpatterns/expr/qdynamiccontextstore.cpp b/src/xmlpatterns/expr/qdynamiccontextstore.cpp
index 762b7d6..7e7ead7 100644
--- a/src/xmlpatterns/expr/qdynamiccontextstore.cpp
+++ b/src/xmlpatterns/expr/qdynamiccontextstore.cpp
@@ -51,24 +51,24 @@ using namespace QPatternist;
DynamicContextStore::DynamicContextStore(const Expression::Ptr &operand,
const DynamicContext::Ptr &context) : SingleContainer(operand),
- m_context(context)
+ m_context(context.data())
{
Q_ASSERT(context);
}
bool DynamicContextStore::evaluateEBV(const DynamicContext::Ptr &) const
{
- return m_operand->evaluateEBV(m_context);
+ return m_operand->evaluateEBV(DynamicContext::Ptr(m_context));
}
Item::Iterator::Ptr DynamicContextStore::evaluateSequence(const DynamicContext::Ptr &) const
{
- return m_operand->evaluateSequence(m_context);
+ return m_operand->evaluateSequence(DynamicContext::Ptr(m_context));
}
Item DynamicContextStore::evaluateSingleton(const DynamicContext::Ptr &) const
{
- return m_operand->evaluateSingleton(m_context);
+ return m_operand->evaluateSingleton(DynamicContext::Ptr(m_context));
}
SequenceType::Ptr DynamicContextStore::staticType() const
diff --git a/src/xmlpatterns/expr/qdynamiccontextstore_p.h b/src/xmlpatterns/expr/qdynamiccontextstore_p.h
index 1d5d035..40bfcd1 100644
--- a/src/xmlpatterns/expr/qdynamiccontextstore_p.h
+++ b/src/xmlpatterns/expr/qdynamiccontextstore_p.h
@@ -86,7 +86,7 @@ namespace QPatternist
virtual const SourceLocationReflection *actualReflection() const;
private:
- const DynamicContext::Ptr m_context;
+ DynamicContext *m_context;
};
}
diff --git a/src/xmlpatterns/expr/qevaluationcache.cpp b/src/xmlpatterns/expr/qevaluationcache.cpp
index 2d1bb56..cb95af6 100644
--- a/src/xmlpatterns/expr/qevaluationcache.cpp
+++ b/src/xmlpatterns/expr/qevaluationcache.cpp
@@ -49,7 +49,7 @@ template<bool IsForGlobal>
EvaluationCache<IsForGlobal>::EvaluationCache(const Expression::Ptr &op,
const VariableDeclaration::Ptr &varDecl,
const VariableSlotID aSlot) : SingleContainer(op)
- , m_declaration(varDecl)
+ , m_declaration(varDecl.constData())
, m_varSlot(aSlot)
{
Q_ASSERT(m_declaration);
diff --git a/src/xmlpatterns/expr/qevaluationcache_p.h b/src/xmlpatterns/expr/qevaluationcache_p.h
index 86aeaf8..af4cfa0 100644
--- a/src/xmlpatterns/expr/qevaluationcache_p.h
+++ b/src/xmlpatterns/expr/qevaluationcache_p.h
@@ -124,7 +124,7 @@ namespace QPatternist
private:
static DynamicContext::Ptr topFocusContext(const DynamicContext::Ptr &context);
- const VariableDeclaration::Ptr m_declaration;
+ const VariableDeclaration* m_declaration;
/**
* This variable must not be called m_slot. If it so, a compiler bug on
* HP-UX-aCC-64 is triggered in the constructor initializor. See the
diff --git a/src/xmlpatterns/expr/qletclause.cpp b/src/xmlpatterns/expr/qletclause.cpp
index d3e939b..b789b48 100644
--- a/src/xmlpatterns/expr/qletclause.cpp
+++ b/src/xmlpatterns/expr/qletclause.cpp
@@ -60,7 +60,7 @@ LetClause::LetClause(const Expression::Ptr &operand1,
DynamicContext::Ptr LetClause::bindVariable(const DynamicContext::Ptr &context) const
{
- context->setExpressionVariable(m_varDecl->slot, Expression::Ptr(new DynamicContextStore(m_operand1, context)));
+ context->setExpressionVariable(m_varDecl->slot, m_operand1);
return context;
}