mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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:
parent
c5437c7499
commit
37910751a0
1 changed files with 12 additions and 0 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue