From 1bc31fa43ddefe468c9f079156bfad0371e2a61b Mon Sep 17 00:00:00 2001 From: Sami Rosendahl Date: Thu, 5 Jan 2012 13:52:39 +0200 Subject: Fix memory leak in QDomDocument DTD notation declaration handler The created notation 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 DTDNotationDecl to tst_qdom to expose the leak when executed under valgrind memcheck. There was no previous test coverage for the notation declarations in DTD. Task-number: QTBUG-22588 Change-Id: I876186d1277ceb4414f803b58b62f51cc1474367 Reviewed-by: Olivier Goffart --- src/xml/dom/qdom.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/xml/dom') diff --git a/src/xml/dom/qdom.cpp b/src/xml/dom/qdom.cpp index 10f48b1608..d8a7bc5b5a 100644 --- a/src/xml/dom/qdom.cpp +++ b/src/xml/dom/qdom.cpp @@ -7553,6 +7553,8 @@ bool QDomHandler::externalEntityDecl(const QString &name, const QString &publicI bool QDomHandler::notationDecl(const QString & name, const QString & publicId, const QString & systemId) { QDomNotationPrivate* n = new QDomNotationPrivate(doc, 0, name, publicId, systemId); + // keep the refcount balanced: appendChild() does a ref anyway. + n->ref.deref(); doc->doctype()->appendChild(n); return true; } -- cgit v1.2.3