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 /qt-models/diveimportedmodel.cpp | |
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>
Diffstat (limited to 'qt-models/diveimportedmodel.cpp')
-rw-r--r-- | qt-models/diveimportedmodel.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
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; } |