QXmlStreamReader: fix memory leak

On some inputs a QXmlStreamReaderPrivate may allocate another
QXmlStreamReaderPrivate as its entityResolver. Which, recursively,
may allocate yet another one.

This "chain" of QXmlStreamReaderPrivate objects was managed using
raw pointers, and a leak was possible by resetting one of
these pointers to nullptr without freeing the corresponding object.

Change-Id: I2c6e1f023a2ed68b2b1857db25c53cce7f6bd3e7
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
bb10
Giuseppe D'Angelo 2020-01-21 14:43:01 +01:00
parent 4d8a515a23
commit e83c4e8138
2 changed files with 5 additions and 4 deletions

View File

@ -69,6 +69,8 @@ public: \
{ return QString::fromLatin1(sourceText); } \
private:
#endif
#include <private/qmemory_p.h>
QT_BEGIN_NAMESPACE
#include "qxmlstream_p.h"
@ -848,7 +850,7 @@ void QXmlStreamReaderPrivate::init()
#endif
attributeStack.clear();
attributeStack.reserve(16);
entityParser = nullptr;
entityParser.reset();
hasCheckedStartDocument = false;
normalizeLiterals = false;
hasSeenTag = false;
@ -881,7 +883,7 @@ void QXmlStreamReaderPrivate::parseEntity(const QString &value)
if (!entityParser)
entityParser = new QXmlStreamReaderPrivate(q);
entityParser = qt_make_unique<QXmlStreamReaderPrivate>(q);
else
entityParser->init();
entityParser->inParseEntity = true;
@ -911,7 +913,6 @@ QXmlStreamReaderPrivate::~QXmlStreamReaderPrivate()
#endif
free(sym_stack);
free(state_stack);
delete entityParser;
}

View File

@ -981,7 +981,7 @@ public:
QString resolveUndeclaredEntity(const QString &name);
void parseEntity(const QString &value);
QXmlStreamReaderPrivate *entityParser;
std::unique_ptr<QXmlStreamReaderPrivate> entityParser;
bool scanAfterLangleBang();
bool scanPublicOrSystem();