diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2017-05-29 10:32:32 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-05-29 10:35:21 -0700 |
commit | 57d01701aa81f7b1033ff0b19a2d128554aeed7d (patch) | |
tree | 8e1328433f906fde25b857b80ed4dc4995fa4e98 | |
parent | 76a38b63269f554f3299e8ddfb1ea335bbc932d5 (diff) | |
download | subsurface-57d01701aa81f7b1033ff0b19a2d128554aeed7d.tar.gz |
Don't leak memory on downloaded dives not picked
I noticed this in the mobile download code when fixing an unrelated
issue - and then realized that the same was true in the desktop app
as well.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | desktop-widgets/downloadfromdivecomputer.cpp | 2 | ||||
-rw-r--r-- | qt-models/diveimportedmodel.cpp | 13 |
2 files changed, 12 insertions, 3 deletions
diff --git a/desktop-widgets/downloadfromdivecomputer.cpp b/desktop-widgets/downloadfromdivecomputer.cpp index 2d834359e..5400f62ed 100644 --- a/desktop-widgets/downloadfromdivecomputer.cpp +++ b/desktop-widgets/downloadfromdivecomputer.cpp @@ -421,6 +421,8 @@ void DownloadFromDCWidget::on_ok_clicked() for (int i = 0; i < downloadTable.nr; i++) { if (diveImportedModel->data(diveImportedModel->index(i, 0),Qt::CheckStateRole) == Qt::Checked) record_dive(downloadTable.dives[i]); + else + clear_dive(downloadTable.dives[i]); downloadTable.dives[i] = NULL; } downloadTable.nr = 0; diff --git a/qt-models/diveimportedmodel.cpp b/qt-models/diveimportedmodel.cpp index 1b8b5a897..f121aef31 100644 --- a/qt-models/diveimportedmodel.cpp +++ b/qt-models/diveimportedmodel.cpp @@ -148,11 +148,18 @@ void DiveImportedModel::repopulate() void DiveImportedModel::recordDives() { + // walk the table of imported dives and record the ones that the user picked + // clearing out the table as we go for (int i = 0; i < rowCount(); i++) { - if (diveTable->dives[i] && checkStates[i]) { - record_dive(diveTable->dives[i]); - diveTable->dives[i] = NULL; + struct dive *d = diveTable->dives[i]; + if (d && checkStates[i]) { + record_dive(d); + } else { + // we should free the dives that weren't recorded + clear_dive(d); + free(d) } + diveTable->dives[i] = NULL; } diveTable->nr = 0; } |