summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2017-11-11 19:40:47 +0100
committerGravatar Lubomir I. Ivanov <neolit123@gmail.com>2017-11-11 21:01:42 +0100
commitefabf0a55cfe8be542fc9c694721d32ecd86583c (patch)
tree34aab5ba9a0475a0414ea17ee3969fea5fcb3725
parent35c5016777d902a2c2ae62bc135e5af0c05fbc14 (diff)
downloadsubsurface-efabf0a55cfe8be542fc9c694721d32ecd86583c.tar.gz
Fix memory leak in download-from-dive-computer widget
Instead of (re)allocating the vendor and product models, use the setStringList method on sub objects. Even though only a theoretical problem, the model objects are moved in front of the ui object, so that the widgets referencing the models are destroyed first. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r--desktop-widgets/downloadfromdivecomputer.cpp21
-rw-r--r--desktop-widgets/downloadfromdivecomputer.h4
2 files changed, 8 insertions, 17 deletions
diff --git a/desktop-widgets/downloadfromdivecomputer.cpp b/desktop-widgets/downloadfromdivecomputer.cpp
index 79fce917e..f4506fd4c 100644
--- a/desktop-widgets/downloadfromdivecomputer.cpp
+++ b/desktop-widgets/downloadfromdivecomputer.cpp
@@ -24,8 +24,6 @@ namespace DownloadFromDcGlobal {
DownloadFromDCWidget::DownloadFromDCWidget(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f),
downloading(false),
previousLast(0),
- vendorModel(0),
- productModel(0),
timer(new QTimer(this)),
dumpWarningShown(false),
ostcFirmwareCheck(0),
@@ -33,7 +31,7 @@ DownloadFromDCWidget::DownloadFromDCWidget(QWidget *parent, Qt::WindowFlags f) :
{
diveImportedModel = new DiveImportedModel(this);
diveImportedModel->setDiveTable(&downloadTable);
- vendorModel = new QStringListModel(vendorList);
+ vendorModel.setStringList(vendorList);
QShortcut *close = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this);
QShortcut *quit = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this);
@@ -54,7 +52,8 @@ DownloadFromDCWidget::DownloadFromDCWidget(QWidget *parent, Qt::WindowFlags f) :
ui.chooseLogFile->setEnabled(ui.logToFile->isChecked());
ui.selectAllButton->setEnabled(false);
ui.unselectAllButton->setEnabled(false);
- ui.vendor->setModel(vendorModel);
+ ui.vendor->setModel(&vendorModel);
+ ui.product->setModel(&productModel);
progress_bar_text = "";
@@ -81,8 +80,7 @@ DownloadFromDCWidget::DownloadFromDCWidget(QWidget *parent, Qt::WindowFlags f) :
auto dc = SettingsObjectWrapper::instance()->dive_computer_settings;
if (!dc->dc_vendor().isEmpty()) {
ui.vendor->setCurrentIndex(ui.vendor->findText(dc->dc_vendor()));
- productModel = new QStringListModel(productList[dc->dc_vendor()]);
- ui.product->setModel(productModel);
+ productModel.setStringList(productList[dc->dc_vendor()]);
if (!dc->dc_product().isEmpty())
ui.product->setCurrentIndex(ui.product->findText(dc->dc_product()));
}
@@ -241,19 +239,12 @@ void DownloadFromDCWidget::updateState(states state)
void DownloadFromDCWidget::on_vendor_currentIndexChanged(const QString &vendor)
{
int dcType = DC_TYPE_SERIAL;
- QAbstractItemModel *currentModel = ui.product->model();
- if (!currentModel)
- return;
-
- productModel = new QStringListModel(productList[vendor]);
- ui.product->setModel(productModel);
+ productModel.setStringList(productList[vendor]);
+ ui.product->setCurrentIndex(0);
if (vendor == QString("Uemis"))
dcType = DC_TYPE_UEMIS;
fill_device_list(dcType);
-
- // Memleak - but deleting gives me a crash.
- //currentModel->deleteLater();
}
void DownloadFromDCWidget::on_product_currentIndexChanged(const QString &product)
diff --git a/desktop-widgets/downloadfromdivecomputer.h b/desktop-widgets/downloadfromdivecomputer.h
index a004215a0..ec3ac266e 100644
--- a/desktop-widgets/downloadfromdivecomputer.h
+++ b/desktop-widgets/downloadfromdivecomputer.h
@@ -60,14 +60,14 @@ private:
void markChildrenAsEnabled();
void updateDeviceEnabled();
+ QStringListModel vendorModel;
+ QStringListModel productModel;
Ui::DownloadFromDiveComputer ui;
DownloadThread thread;
bool downloading;
int previousLast;
- QStringListModel *vendorModel;
- QStringListModel *productModel;
void fill_device_list(int dc_type);
QTimer *timer;
bool dumpWarningShown;