summaryrefslogtreecommitdiffstats
path: root/qt-ui/maintab.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-07-02 21:31:55 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-07-03 09:37:55 -0700
commit20d9fafd7cc5d5b0fde5a4ace8c59d6bfed20c75 (patch)
treee56f70bc960c10874af1620b048b9c1bb04d15c8 /qt-ui/maintab.cpp
parent2cfe97e4dd5093b13301ed98a97b6edd41da56c7 (diff)
downloadsubsurface-20d9fafd7cc5d5b0fde5a4ace8c59d6bfed20c75.tar.gz
UI restructure: improve memory handling in maintab
Free strings before overwriting them. Use copy_dive() instead of just copying the dive structure. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/maintab.cpp')
-rw-r--r--qt-ui/maintab.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index 09f3e5a06..049ad7fb7 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -265,8 +265,8 @@ void MainTab::enableEdition(EditMode newEditMode)
if (MainWindow::instance() && MainWindow::instance()->dive_list()->selectedTrips().count() == 1) {
// we are editing trip location and notes
displayMessage(tr("This trip is being edited."));
- displayed_dive.location = current_dive->divetrip->location;
- displayed_dive.notes = current_dive->divetrip->notes;
+ displayed_dive.location = copy_string(current_dive->divetrip->location);
+ displayed_dive.notes = copy_string(current_dive->divetrip->notes);
ui.dateEdit->setEnabled(false);
editMode = TRIP;
} else {
@@ -842,7 +842,7 @@ void MainTab::rejectChanges()
DivePlannerPointsModel::instance()->restoreBackupDive();
}
if (selected_dive >= 0) {
- displayed_dive = *get_dive(selected_dive);
+ copy_dive(current_dive, &displayed_dive);
cylindersModel->setDive(&displayed_dive);
weightModel->setDive(&displayed_dive);
} else {
@@ -851,6 +851,7 @@ void MainTab::rejectChanges()
setEnabled(false);
}
}
+#if 0 // this makes no sense anymore - but let's make sure I think this through
// now let's avoid memory leaks
if (MainWindow::instance() && MainWindow::instance()->dive_list()->selectedTrips().count() == 1) {
if (displayed_dive.location != current_dive->divetrip->location)
@@ -866,6 +867,7 @@ void MainTab::rejectChanges()
FREE_IF_DIFFERENT(notes);
FREE_IF_DIFFERENT(suit);
}
+#endif
hideMessage();
MainWindow::instance()->dive_list()->setEnabled(true);
ui.dateEdit->setEnabled(true);
@@ -904,6 +906,7 @@ void MainTab::on_buddy_textChanged()
for (int i = 0; i < text_list.size(); i++)
text_list[i] = text_list[i].trimmed();
QString text = text_list.join(", ");
+ free(displayed_dive.buddy);
displayed_dive.buddy = strdup(text.toUtf8().data());
markChangedWidget(ui.buddy);
}
@@ -916,6 +919,7 @@ void MainTab::on_divemaster_textChanged()
for (int i = 0; i < text_list.size(); i++)
text_list[i] = text_list[i].trimmed();
QString text = text_list.join(", ");
+ free(displayed_dive.divemaster);
displayed_dive.divemaster = strdup(text.toUtf8().data());
markChangedWidget(ui.divemaster);
}
@@ -1036,6 +1040,7 @@ void MainTab::on_location_textChanged(const QString &text)
{
if (editMode == NONE)
return;
+ free(displayed_dive.location);
displayed_dive.location = strdup(ui.location->text().toUtf8().data());
markChangedWidget(ui.location);
}
@@ -1044,6 +1049,7 @@ void MainTab::on_suit_textChanged(const QString &text)
{
if (editMode == NONE)
return;
+ free(displayed_dive.suit);
displayed_dive.suit = strdup(text.toUtf8().data());
markChangedWidget(ui.suit);
}
@@ -1052,6 +1058,7 @@ void MainTab::on_notes_textChanged()
{
if (editMode == NONE)
return;
+ free(displayed_dive.notes);
displayed_dive.notes = strdup(ui.notes->toPlainText().toUtf8().data());
markChangedWidget(ui.notes);
}