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 <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2013-05-01 16:23:20 -07:00
parent f45618f0c7
commit 00d8531382
2 changed files with 6 additions and 5 deletions

View file

@ -14,6 +14,7 @@
AddWeightsystemDialog::AddWeightsystemDialog(QWidget *parent) : ui(new Ui::AddWeightsystemDialog())
{
ui->setupUi(this);
currentWeightsystem = NULL;
}
void AddWeightsystemDialog::setWeightsystem(weightsystem_t *ws)

View file

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