QtXml: fix leak in QDomText::splitText
QDomText::splitText() needs to unref() the newly created QDomText instance as it does not use it by itself Pick-to: 6.7 6.6 6.5 6.2 5.15 Fixes: QTBUG-40561 Change-Id: I593011b63c39f2310204d97ec61da7cf78a0fc14 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>bb10
parent
398a51686e
commit
de0230467c
|
|
@ -4671,6 +4671,10 @@ QDomTextPrivate* QDomTextPrivate::splitText(int offset)
|
|||
value.truncate(offset);
|
||||
|
||||
parent()->insertAfter(t, this);
|
||||
Q_ASSERT(t->ref.loadRelaxed() == 2);
|
||||
|
||||
// We are not interested in this node
|
||||
t->ref.deref();
|
||||
|
||||
return t;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@
|
|||
#include <QtXml/qtxmlglobal.h>
|
||||
#include <QtCore/qstring.h>
|
||||
|
||||
class tst_QDom;
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
||||
|
|
@ -201,6 +203,7 @@ protected:
|
|||
QDomNode(QDomNodePrivate*);
|
||||
|
||||
private:
|
||||
friend class ::tst_QDom;
|
||||
friend class QDomDocument;
|
||||
friend class QDomDocumentType;
|
||||
friend class QDomNodeList;
|
||||
|
|
|
|||
|
|
@ -24,5 +24,6 @@ qt_internal_add_test(tst_qdom
|
|||
tst_qdom.cpp
|
||||
LIBRARIES
|
||||
Qt::Xml
|
||||
Qt::XmlPrivate
|
||||
TESTDATA ${test_data}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
#include <QtXml>
|
||||
#include <QVariant>
|
||||
#include <cmath>
|
||||
#include <QtXml/private/qdom_p.h>
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QDomDocument)
|
||||
QT_FORWARD_DECLARE_CLASS(QDomNode)
|
||||
|
|
@ -106,6 +107,7 @@ private slots:
|
|||
void DTDInternalSubset_data() const;
|
||||
void QTBUG49113_dontCrashWithNegativeIndex() const;
|
||||
void standalone();
|
||||
void splitTextLeakMemory() const;
|
||||
|
||||
void cleanupTestCase() const;
|
||||
|
||||
|
|
@ -2315,5 +2317,19 @@ void tst_QDom::DTDInternalSubset_data() const
|
|||
<< internalSubset0;
|
||||
}
|
||||
|
||||
void tst_QDom::splitTextLeakMemory() const
|
||||
{
|
||||
QDomDocument doc;
|
||||
QDomElement top = doc.createElement("top");
|
||||
QDomText text = doc.createTextNode("abcdefgh");
|
||||
top.appendChild(text);
|
||||
QDomText end = text.splitText(2);
|
||||
QCOMPARE(text.data(), "ab"_L1);
|
||||
QCOMPARE(end.data(), "cdefgh"_L1);
|
||||
// only the parent node and the document have a reference on the nodes
|
||||
QCOMPARE(text.impl->ref.loadRelaxed(), 2);
|
||||
QCOMPARE(end.impl->ref.loadRelaxed(), 2);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QDom)
|
||||
#include "tst_qdom.moc"
|
||||
|
|
|
|||
Loading…
Reference in New Issue