Changeset 57d0170 in subsurface


Ignore:
Timestamp:
May 29, 2017, 10:35:21 AM (4 weeks ago)
Author:
Dirk Hohndel <dirk@…>
Branches:
master
Children:
dd3edb0
Parents:
76a38b6
git-author:
Dirk Hohndel <dirk@…> (05/29/17 10:32:32)
git-committer:
Dirk Hohndel <dirk@…> (05/29/17 10:35:21)
Message:

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@…>

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • desktop-widgets/downloadfromdivecomputer.cpp

    r84b1b63 r57d0170  
    422422                if (diveImportedModel->data(diveImportedModel->index(i, 0),Qt::CheckStateRole) == Qt::Checked)
    423423                        record_dive(downloadTable.dives[i]);
     424                else
     425                        clear_dive(downloadTable.dives[i]);
    424426                downloadTable.dives[i] = NULL;
    425427        }
  • qt-models/diveimportedmodel.cpp

    r8d42d33 r57d0170  
    149149void DiveImportedModel::recordDives()
    150150{
     151        // walk the table of imported dives and record the ones that the user picked
     152        // clearing out the table as we go
    151153        for (int i = 0; i < rowCount(); i++) {
    152                 if (diveTable->dives[i] && checkStates[i]) {
    153                         record_dive(diveTable->dives[i]);
    154                         diveTable->dives[i] = NULL;
     154                struct dive *d = diveTable->dives[i];
     155                if (d && checkStates[i]) {
     156                        record_dive(d);
     157                } else {
     158                        // we should free the dives that weren't recorded
     159                        clear_dive(d);
     160                        free(d)
    155161                }
     162                diveTable->dives[i] = NULL;
    156163        }
    157164        diveTable->nr = 0;
Note: See TracChangeset for help on using the changeset viewer.