diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2014-06-03 18:12:24 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-06-03 18:12:24 -0700 |
commit | 37910751a005b9b28edcdf3170514c560af04f6c (patch) | |
tree | f8577b97a2e7e82ad38f4ec39b26de9c2be6a2cc /qt-ui | |
parent | c5437c7499514d1cc3fa7486921aecdd8d25944e (diff) | |
download | subsurface-37910751a005b9b28edcdf3170514c560af04f6c.tar.gz |
Dive edit: avoid memory leaks
If we edit any of these fields, we create new strings via strdup (or a
fresh tag_list). So if the edits are rejected, free all that memory.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui')
-rw-r--r-- | qt-ui/maintab.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 9200f28f5..442136d7f 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -778,6 +778,10 @@ void MainTab::resetPallete() free(what); \ what = strdup(textByteArray.data()); +#define FREE_IF_DIFFERENT(what) \ + if (editedDive.what != cd->what) \ + free(editedDive.what) + void MainTab::rejectChanges() { EditMode lastMode = editMode; @@ -814,6 +818,14 @@ void MainTab::rejectChanges() setEnabled(false); } } + // now let's avoid memory leaks + struct dive *cd = current_dive; + FREE_IF_DIFFERENT(tag_list); + FREE_IF_DIFFERENT(location); + FREE_IF_DIFFERENT(buddy); + FREE_IF_DIFFERENT(divemaster); + FREE_IF_DIFFERENT(notes); + FREE_IF_DIFFERENT(suit); hideMessage(); MainWindow::instance()->dive_list()->setEnabled(true); |