diff options
author | Sami Rosendahl <ext-sami.1.rosendahl@nokia.com> | 2012-01-18 08:50:44 (GMT) |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-01-18 17:07:00 (GMT) |
commit | d3145bf9c72951e08e3d574c3bdc7bdf435c8281 (patch) | |
tree | 3fc7b51471a0b5cf88622d4d0f9b9e6bae7b04bf | |
parent | d8d4dc8599fb251ca201f5c3f496df1045d288c3 (diff) | |
download | Qt-d3145bf9c72951e08e3d574c3bdc7bdf435c8281.zip Qt-d3145bf9c72951e08e3d574c3bdc7bdf435c8281.tar.gz Qt-d3145bf9c72951e08e3d574c3bdc7bdf435c8281.tar.bz2 |
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: I8193699779b688fd818439d6ef9f850b3373dcc3
(from Qt5 commit b6a43cfe9c136e298feaa8d48fc252fdb3d4e7c5)
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
-rw-r--r-- | src/xml/dom/qdom.cpp | 1 | ||||
-rw-r--r-- | tests/auto/qdom/tst_qdom.cpp | 4 |
2 files changed, 3 insertions, 2 deletions
diff --git a/src/xml/dom/qdom.cpp b/src/xml/dom/qdom.cpp index 60e976b..8bd41a7 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 03285cb..4ab2805 100644 --- a/tests/auto/qdom/tst_qdom.cpp +++ b/tests/auto/qdom/tst_qdom.cpp @@ -175,7 +175,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" @@ -247,7 +247,7 @@ void tst_QDom::setContent_data() " </b3>\n" "</a1>\n"); - */ QTest::newRow("05") << QString("<message>\n" + QTest::newRow("05") << QString("<message>\n" " <body><b>foo</b>>]]></body>\n" "</message>\n") << QStringList() << QStringList() |