summaryrefslogtreecommitdiffstats
path: root/src/xml/dom
diff options
context:
space:
mode:
authorSami Rosendahl <ext-sami.1.rosendahl@nokia.com>2012-01-05 13:56:53 +0200
committerQt by Nokia <qt-info@nokia.com>2012-01-06 02:59:59 +0100
commitd55cdcd59fdddd660193ddff40fbd52bef57c0c9 (patch)
tree275e89ad2fbd56faf367b609231c1e3981013ad3 /src/xml/dom
parent1bc31fa43ddefe468c9f079156bfad0371e2a61b (diff)
Fix memory leak in QDomDocument DTD entity declaration handler
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. Also added autotest DTDEntityDecl to tst_qdom to expose the leak when executed under valgrind memcheck. There was no previous direct test case for unparsed entity declarations in DTD, only indirect coverage via regression test cloneDTD_QTBUG8398. Task-number: QTBUG-22587 Change-Id: I394ae9fc32d5b84e4ca287c5db4dd7effde6128b Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'src/xml/dom')
-rw-r--r--src/xml/dom/qdom.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/xml/dom/qdom.cpp b/src/xml/dom/qdom.cpp
index d8a7bc5b5a..25638717a0 100644
--- a/src/xml/dom/qdom.cpp
+++ b/src/xml/dom/qdom.cpp
@@ -7541,6 +7541,8 @@ bool QDomHandler::unparsedEntityDecl(const QString &name, const QString &publicI
{
QDomEntityPrivate* e = new QDomEntityPrivate(doc, 0, name,
publicId, systemId, notationName);
+ // keep the refcount balanced: appendChild() does a ref anyway.
+ e->ref.deref();
doc->doctype()->appendChild(e);
return true;
}