summaryrefslogtreecommitdiffstats
path: root/qt-ui/models.cpp
diff options
context:
space:
mode:
authorGravatar Thiago Macieira <thiago@macieira.org>2013-11-30 09:18:04 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-11-30 09:28:42 -0800
commitb22f1da59e37ff4ba871fb2d6c72ee3ec87b4c5b (patch)
tree6548f4639be3261e2db66657b50a6fd095d3a577 /qt-ui/models.cpp
parentbd7ded88940995ebbb46fc6983ba9cfd179e55e0 (diff)
downloadsubsurface-b22f1da59e37ff4ba871fb2d6c72ee3ec87b4c5b.tar.gz
Fix all leak-at-exit from singletons in Subsurface
Subsurface creates a lot of singleton instances on demand, but nothing ever deleted them. Since they are singletons, these memory allocations are technically not leaks. However, they clutter the output in valgrind and other memory analysers, hiding the real issues. The solution is to delete these items at exit. For the models and for gettextFromC, the solution is to use a QScopedPointer, which will delete its payload when it gets destroyed. For the dialogs and other widgets, we can't do that: they need to be deleted before QApplication exits, so we just set the parent in all of them to the main window. Signed-off-by: Thiago Macieira <thiago@macieira.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/models.cpp')
-rw-r--r--qt-ui/models.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp
index 920d362e0..bb0de69f3 100644
--- a/qt-ui/models.cpp
+++ b/qt-ui/models.cpp
@@ -67,8 +67,8 @@ CylindersModel::CylindersModel(QObject* parent): current(0), rows(0)
CylindersModel *CylindersModel::instance()
{
- static CylindersModel *self = new CylindersModel();
- return self;
+ static QScopedPointer<CylindersModel> self(new CylindersModel());
+ return self.data();
}
static QVariant percent_string(fraction_t fraction)
@@ -559,8 +559,8 @@ void WeightModel::setDive(dive* d)
WSInfoModel* WSInfoModel::instance()
{
- static WSInfoModel *self = new WSInfoModel();
- return self;
+ static QScopedPointer<WSInfoModel> self(new WSInfoModel());
+ return self.data();
}
bool WSInfoModel::insertRows(int row, int count, const QModelIndex& parent)
@@ -680,8 +680,8 @@ void WSInfoModel::update()
TankInfoModel* TankInfoModel::instance()
{
- static TankInfoModel *self = new TankInfoModel();
- return self;
+ static QScopedPointer<TankInfoModel> self(new TankInfoModel());
+ return self.data();
}
const QString& TankInfoModel::biggerString() const
@@ -1711,8 +1711,8 @@ Qt::ItemFlags GasSelectionModel::flags(const QModelIndex& index) const
GasSelectionModel* GasSelectionModel::instance()
{
- static GasSelectionModel* self = new GasSelectionModel();
- return self;
+ static QScopedPointer<GasSelectionModel> self(new GasSelectionModel());
+ return self.data();
}
void GasSelectionModel::repopulate()