mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
76a38b6326
commit
57d01701aa
2 changed files with 12 additions and 3 deletions
|
@ -421,6 +421,8 @@ void DownloadFromDCWidget::on_ok_clicked()
|
||||||
for (int i = 0; i < downloadTable.nr; i++) {
|
for (int i = 0; i < downloadTable.nr; i++) {
|
||||||
if (diveImportedModel->data(diveImportedModel->index(i, 0),Qt::CheckStateRole) == Qt::Checked)
|
if (diveImportedModel->data(diveImportedModel->index(i, 0),Qt::CheckStateRole) == Qt::Checked)
|
||||||
record_dive(downloadTable.dives[i]);
|
record_dive(downloadTable.dives[i]);
|
||||||
|
else
|
||||||
|
clear_dive(downloadTable.dives[i]);
|
||||||
downloadTable.dives[i] = NULL;
|
downloadTable.dives[i] = NULL;
|
||||||
}
|
}
|
||||||
downloadTable.nr = 0;
|
downloadTable.nr = 0;
|
||||||
|
|
|
@ -148,11 +148,18 @@ void DiveImportedModel::repopulate()
|
||||||
|
|
||||||
void DiveImportedModel::recordDives()
|
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++) {
|
for (int i = 0; i < rowCount(); i++) {
|
||||||
if (diveTable->dives[i] && checkStates[i]) {
|
struct dive *d = diveTable->dives[i];
|
||||||
record_dive(diveTable->dives[i]);
|
if (d && checkStates[i]) {
|
||||||
diveTable->dives[i] = NULL;
|
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;
|
diveTable->nr = 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue