From 00d85313827af88ae5f35b2391ffa6964e81da49 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Wed, 1 May 2013 16:23:20 -0700 Subject: Fix a couple of small problems in add weightsystem The constructor letf the currentWeightsytem variable uninitialized. Instead of creating the memory leak by malloc-ing the newWeightsystem in the on_addWeight_clicked() function use a local variable instead and pass its address around. Signed-off-by: Dirk Hohndel --- qt-ui/addweightsystemdialog.cpp | 1 + qt-ui/maintab.cpp | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/qt-ui/addweightsystemdialog.cpp b/qt-ui/addweightsystemdialog.cpp index 6ac1c02f9..48a399de9 100644 --- a/qt-ui/addweightsystemdialog.cpp +++ b/qt-ui/addweightsystemdialog.cpp @@ -14,6 +14,7 @@ AddWeightsystemDialog::AddWeightsystemDialog(QWidget *parent) : ui(new Ui::AddWeightsystemDialog()) { ui->setupUi(this); + currentWeightsystem = NULL; } void AddWeightsystemDialog::setWeightsystem(weightsystem_t *ws) diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index f26a72a8a..2467dd0d7 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -93,17 +93,17 @@ void MainTab::on_addWeight_clicked() return; AddWeightsystemDialog dialog(this); - weightsystem_t *newWeightsystem = (weightsystem_t *) malloc(sizeof(weightsystem_t)); - newWeightsystem->description = ""; - newWeightsystem->weight.grams = 0; + weightsystem_t newWeightsystem; + newWeightsystem.description = ""; + newWeightsystem.weight.grams = 0; - dialog.setWeightsystem(newWeightsystem); + dialog.setWeightsystem(&newWeightsystem); int result = dialog.exec(); if (result == QDialog::Rejected) return; dialog.updateWeightsystem(); - weightModel->add(newWeightsystem); + weightModel->add(&newWeightsystem); } void MainTab::on_editWeight_clicked() -- cgit v1.2.3-70-g09d2