From 3c3f8dd7c6f2a681ed11e941568ecc569377c389 Mon Sep 17 00:00:00 2001 From: Ari Koivisto Date: Wed, 3 Oct 2012 19:29:33 +0300 Subject: Fix XmlListModel memory leak This is a forward port of a memory leak fix committed to Qt 4.8 (QTBUG-15191). The fix includes all changes except changes to qitem_p.h which has changed in Qt 5.0. Additionally fix qxmlquery autotest failure introduced in the original Qt 4.8 patch. Task-number: QTBUG-27357 Change-Id: Ia0e916d9d6bccea014d28920cef48d6e47e8f04f Reviewed-by: Sergio Ahumada --- src/xmlpatterns/expr/qdynamiccontextstore.cpp | 8 ++++---- src/xmlpatterns/expr/qdynamiccontextstore_p.h | 2 +- src/xmlpatterns/expr/qevaluationcache_p.h | 2 +- src/xmlpatterns/expr/qevaluationcache_tpl_p.h | 2 +- src/xmlpatterns/expr/qletclause.cpp | 2 +- tests/auto/qxmlquery/tst_qxmlquery.cpp | 2 +- tests/auto/xmlpatternsdiagnosticsts/xmlpatternsdiagnosticsts.pro | 3 +++ tests/auto/xmlpatternsschemats/xmlpatternsschemats.pro | 3 +++ tests/auto/xmlpatternsxqts/xmlpatternsxqts.pro | 2 ++ 9 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/xmlpatterns/expr/qdynamiccontextstore.cpp b/src/xmlpatterns/expr/qdynamiccontextstore.cpp index 3879cd6..2089456 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 d76e130..ffd4e36 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_p.h b/src/xmlpatterns/expr/qevaluationcache_p.h index 6f49115..2dc8940 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/qevaluationcache_tpl_p.h b/src/xmlpatterns/expr/qevaluationcache_tpl_p.h index 286c077..7aa0ae1 100644 --- a/src/xmlpatterns/expr/qevaluationcache_tpl_p.h +++ b/src/xmlpatterns/expr/qevaluationcache_tpl_p.h @@ -49,7 +49,7 @@ template EvaluationCache::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/qletclause.cpp b/src/xmlpatterns/expr/qletclause.cpp index 3b3ee07..0caa86e 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; } diff --git a/tests/auto/qxmlquery/tst_qxmlquery.cpp b/tests/auto/qxmlquery/tst_qxmlquery.cpp index 928d67b..23af7a2 100644 --- a/tests/auto/qxmlquery/tst_qxmlquery.cpp +++ b/tests/auto/qxmlquery/tst_qxmlquery.cpp @@ -3305,7 +3305,7 @@ void tst_QXmlQuery::bindVariableQXmlQueryInvalidate() const QXmlQuery query2; query2.setQuery("'query2'"); - query.bindVariable(QLatin1String("name"), query); + query.bindVariable(QLatin1String("name"), query2); QVERIFY(!query.isValid()); } diff --git a/tests/auto/xmlpatternsdiagnosticsts/xmlpatternsdiagnosticsts.pro b/tests/auto/xmlpatternsdiagnosticsts/xmlpatternsdiagnosticsts.pro index b534495..f8904cc 100644 --- a/tests/auto/xmlpatternsdiagnosticsts/xmlpatternsdiagnosticsts.pro +++ b/tests/auto/xmlpatternsdiagnosticsts/xmlpatternsdiagnosticsts.pro @@ -24,4 +24,7 @@ wince* { catalog.path = . DEPLOYMENT += catalog } + DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 +requires(contains(QT_CONFIG,private_tests)) + diff --git a/tests/auto/xmlpatternsschemats/xmlpatternsschemats.pro b/tests/auto/xmlpatternsschemats/xmlpatternsschemats.pro index c9fe689..a1e7896 100644 --- a/tests/auto/xmlpatternsschemats/xmlpatternsschemats.pro +++ b/tests/auto/xmlpatternsschemats/xmlpatternsschemats.pro @@ -21,4 +21,7 @@ QT += xml testlib INCLUDEPATH += \ ../xmlpatternsxqts \ ../xmlpatternssdk + DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 +requires(contains(QT_CONFIG,private_tests)) + diff --git a/tests/auto/xmlpatternsxqts/xmlpatternsxqts.pro b/tests/auto/xmlpatternsxqts/xmlpatternsxqts.pro index f6d492e..41e9c68 100644 --- a/tests/auto/xmlpatternsxqts/xmlpatternsxqts.pro +++ b/tests/auto/xmlpatternsxqts/xmlpatternsxqts.pro @@ -17,3 +17,5 @@ INCLUDEPATH += $$(QTDIR)/include/QtXmlPatterns/private \ QT += xml testlib TARGET = tst_xmlpatternsxqts DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 +requires(contains(QT_CONFIG,private_tests)) + -- cgit v1.2.1