summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSami Rosendahl <ext-sami.1.rosendahl@nokia.com>2012-01-19 10:16:27 +0200
committerThiago Macieira <thiago.macieira@intel.com>2012-04-05 15:43:57 +0200
commitaf66796c0327b1f215a843cedf03918fc40c4077 (patch)
treeb00dfd8bc0225d744af74ffc463d413fbc8c5b77
parentceb6b7cc0b5b4b60d12e7c6b2e6cdc8530f5030f (diff)
Fix memory leak in QDomDocument entity text expansion
The created entity node's reference count needs to be decremented to 0 before it is added as a child, because appendChild will increment the reference count to correct value of 1. Re-enabled commented-out test data of tst_QDom::setContent to exercise the code path with the leak. Change-Id: Ia77b81e4f02cd29c7cd82430a21db5b882bdbfc2 (cherry picked from commit d3145bf9c72951e08e3d574c3bdc7bdf435c8281) Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r--src/xml/dom/qdom.cpp1
-rw-r--r--tests/auto/qdom/tst_qdom.cpp4
2 files changed, 3 insertions, 2 deletions
diff --git a/src/xml/dom/qdom.cpp b/src/xml/dom/qdom.cpp
index 8009832a1f..f12e849d0f 100644
--- a/src/xml/dom/qdom.cpp
+++ b/src/xml/dom/qdom.cpp
@@ -7461,6 +7461,7 @@ bool QDomHandler::characters(const QString& ch)
QScopedPointer<QDomEntityPrivate> e(new QDomEntityPrivate(doc, 0, entityName,
QString(), QString(), QString()));
e->value = ch;
+ e->ref.deref();
doc->doctype()->appendChild(e.data());
e.take();
n.reset(doc->createEntityReference(entityName));
diff --git a/tests/auto/qdom/tst_qdom.cpp b/tests/auto/qdom/tst_qdom.cpp
index c4ca8637a4..a9c819c601 100644
--- a/tests/auto/qdom/tst_qdom.cpp
+++ b/tests/auto/qdom/tst_qdom.cpp
@@ -176,7 +176,7 @@ void tst_QDom::setContent_data()
QTest::addColumn<QStringList>("featuresFalse");
QTest::addColumn<QString>("res");
-/* QTest::newRow( "01" ) << doc01
+ QTest::newRow( "01" ) << doc01
<< QStringList()
<< QString("http://trolltech.com/xml/features/report-whitespace-only-CharData").split(' ')
<< QString("<!DOCTYPE a1>\n"
@@ -248,7 +248,7 @@ void tst_QDom::setContent_data()
" </b3>\n"
"</a1>\n");
- */ QTest::newRow("05") << QString("<message>\n"
+ QTest::newRow("05") << QString("<message>\n"
" <body>&lt;b&gt;foo&lt;/b&gt;>]]&gt;</body>\n"
"</message>\n")
<< QStringList() << QStringList()