Fix UB in QStandardItemModel

The destructor of QStandardItem needs to access the model. So we need to
destroy them before the QStrandardItemModel gets destroyed.
In the destructor of the private, it is already too late because we are
already in the ~QObject

Since the destructor of QStandardItemPrivate is now empty, remove it
completely. There is no need for QStandardItemPrivate to have a virtual
table as there are no class that inherit from it.

Change-Id: Id6639e21f277f1c4e85c3f9bc720b4f29eb16c2c
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
Olivier Goffart 2017-04-18 17:01:22 +02:00 committed by Olivier Goffart (Woboq GmbH)
parent 41eefd7493
commit 88b6abcebf
2 changed files with 14 additions and 21 deletions

View File

@ -88,23 +88,6 @@ public:
}
};
/*!
\internal
*/
QStandardItemPrivate::~QStandardItemPrivate()
{
QVector<QStandardItem*>::const_iterator it;
for (it = children.constBegin(); it != children.constEnd(); ++it) {
QStandardItem *child = *it;
if (child)
child->d_func()->setModel(0);
delete child;
}
children.clear();
if (parent && model)
parent->d_func()->childDeleted(q_func());
}
/*!
\internal
*/
@ -340,9 +323,6 @@ QStandardItemModelPrivate::QStandardItemModelPrivate()
*/
QStandardItemModelPrivate::~QStandardItemModelPrivate()
{
delete itemPrototype;
qDeleteAll(columnHeaderItems);
qDeleteAll(rowHeaderItems);
}
/*!
@ -780,6 +760,15 @@ QStandardItem &QStandardItem::operator=(const QStandardItem &other)
*/
QStandardItem::~QStandardItem()
{
Q_D(QStandardItem);
for (QStandardItem *child : qAsConst(d->children)) {
if (child)
child->d_func()->setModel(0);
delete child;
}
d->children.clear();
if (d->parent && d->model)
d->parent->d_func()->childDeleted(this);
}
/*!
@ -2116,6 +2105,11 @@ QStandardItemModel::QStandardItemModel(QStandardItemModelPrivate &dd, QObject *p
*/
QStandardItemModel::~QStandardItemModel()
{
Q_D(QStandardItemModel);
delete d->itemPrototype;
qDeleteAll(d->columnHeaderItems);
qDeleteAll(d->rowHeaderItems);
d->root.reset();
}
/*!

View File

@ -105,7 +105,6 @@ public:
q_ptr(0),
lastIndexOf(2)
{ }
virtual ~QStandardItemPrivate();
inline int childIndex(int row, int column) const {
if ((row < 0) || (column < 0)