summaryrefslogtreecommitdiffstats
path: root/qt-models/diveplotdatamodel.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2016-01-19 10:27:38 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2016-01-19 10:33:53 -0800
commitf466ee61da75705abd615a2a0d3cbaca12e3c902 (patch)
tree924271e9f6384b392c552d0e06124a34caf72573 /qt-models/diveplotdatamodel.cpp
parente9e843dc3cbd7bcb0519d07bf93c918449ca029b (diff)
downloadsubsurface-f466ee61da75705abd615a2a0d3cbaca12e3c902.tar.gz
Don't blindly copy a pointer to the heap
Copying the entry pointer and assuming that it stays valid is of course totally bogus. This is most likely the reason for the random crashes people have observed. See #992 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-models/diveplotdatamodel.cpp')
-rw-r--r--qt-models/diveplotdatamodel.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/qt-models/diveplotdatamodel.cpp b/qt-models/diveplotdatamodel.cpp
index de156bfac..4b60b3ea3 100644
--- a/qt-models/diveplotdatamodel.cpp
+++ b/qt-models/diveplotdatamodel.cpp
@@ -19,7 +19,7 @@ int DivePlotDataModel::columnCount(const QModelIndex &parent) const
QVariant DivePlotDataModel::data(const QModelIndex &index, int role) const
{
- if ((!index.isValid()) || (index.row() >= pInfo.nr))
+ if ((!index.isValid()) || (index.row() >= pInfo.nr) || pInfo.entry == 0)
return QVariant();
plot_data item = pInfo.entry[index.row()];
@@ -167,6 +167,8 @@ void DivePlotDataModel::clear()
if (rowCount() != 0) {
beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
pInfo.nr = 0;
+ free(pInfo.entry);
+ pInfo.entry = 0;
diveId = -1;
dcNr = -1;
endRemoveRows();
@@ -179,7 +181,10 @@ void DivePlotDataModel::setDive(dive *d, const plot_info &info)
Q_ASSERT(d != NULL);
diveId = d->id;
dcNr = dc_number;
+ free(pInfo.entry);
pInfo = info;
+ pInfo.entry = (struct plot_data *)malloc(sizeof(struct plot_data) * pInfo.nr);
+ memcpy(pInfo.entry, info.entry, sizeof(plot_data) * pInfo.nr);
beginInsertRows(QModelIndex(), 0, pInfo.nr - 1);
endInsertRows();
}