Coverity: fix issues reported in QJsonModel

- Also reported upstream, in the MIT-licensed version of same.

This is a re-hash of b348a45834,
adding memory-leak prevention when load() is called.
main
Adriaan de Groot 7 years ago
parent b15d970845
commit a138eb501c

@ -26,11 +26,9 @@
#include "qjsonitem.h"
QJsonTreeItem::QJsonTreeItem(QJsonTreeItem *parent)
: mParent( parent )
, mType( QJsonValue::Type::Null )
{
mParent = parent;
}
QJsonTreeItem::~QJsonTreeItem()

@ -33,14 +33,19 @@
QJsonModel::QJsonModel(QObject *parent) :
QAbstractItemModel(parent)
, mRootItem( new QJsonTreeItem )
{
mRootItem = new QJsonTreeItem;
mHeaders.append("key");
mHeaders.append("value");
}
QJsonModel::~QJsonModel()
{
delete mRootItem;
}
bool QJsonModel::load(const QString &fileName)
{
QFile file(fileName);
@ -66,6 +71,7 @@ bool QJsonModel::loadJson(const QByteArray &json)
if (!mDocument.isNull())
{
beginResetModel();
delete mRootItem;
if (mDocument.isArray()) {
mRootItem = QJsonTreeItem::load(QJsonValue(mDocument.array()));
} else {

Loading…
Cancel
Save