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>
This commit is contained in:
Dirk Hohndel 2014-06-03 18:12:24 -07:00
parent c5437c7499
commit 37910751a0

View file

@ -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);