From 57d01701aa81f7b1033ff0b19a2d128554aeed7d Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Mon, 29 May 2017 10:32:32 -0700 Subject: 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 --- qt-models/diveimportedmodel.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'qt-models') 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; } -- cgit v1.2.3-70-g09d2