summaryrefslogtreecommitdiffstats
path: root/src/gui/itemmodels
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@woboq.com>2017-04-18 17:01:22 +0200
committerOlivier Goffart (Woboq GmbH) <ogoffart@woboq.com>2017-04-23 10:11:01 +0000
commit88b6abcebf29b455438d8da7db9fd5aa1aed2bf5 (patch)
tree64e7428da4636db6f3d5fe577b887966df816beb /src/gui/itemmodels
parent41eefd7493bf0119a4fd1a069e31ab4f2c4d10f9 (diff)
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>
Diffstat (limited to 'src/gui/itemmodels')
-rw-r--r--src/gui/itemmodels/qstandarditemmodel.cpp34
-rw-r--r--src/gui/itemmodels/qstandarditemmodel_p.h1
2 files changed, 14 insertions, 21 deletions
diff --git a/src/gui/itemmodels/qstandarditemmodel.cpp b/src/gui/itemmodels/qstandarditemmodel.cpp
index e965045524..1d6e2924b1 100644
--- a/src/gui/itemmodels/qstandarditemmodel.cpp
+++ b/src/gui/itemmodels/qstandarditemmodel.cpp
@@ -91,23 +91,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
-*/
QPair<int, int> QStandardItemPrivate::position() const
{
if (QStandardItem *par = parent) {
@@ -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();
}
/*!
diff --git a/src/gui/itemmodels/qstandarditemmodel_p.h b/src/gui/itemmodels/qstandarditemmodel_p.h
index fbba93b93a..516cce8613 100644
--- a/src/gui/itemmodels/qstandarditemmodel_p.h
+++ b/src/gui/itemmodels/qstandarditemmodel_p.h
@@ -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)