Skip to content

Commit

Permalink
Rework memory management to make ASAN happy
Browse files Browse the repository at this point in the history
  • Loading branch information
wolframroesler committed Dec 8, 2019
1 parent 4941413 commit 1096e19
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
23 changes: 12 additions & 11 deletions src/gui/reports/ReportsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,36 +30,37 @@
class ReportsDialog::ExtraPage
{
public:
ExtraPage(IReportsPage* page, QWidget* widget)
: settingsPage(page)
, widget(widget)
ExtraPage(QSharedPointer<IReportsPage> p, QWidget* w)
: page(p)
, widget(w)
{
}
void loadSettings(QSharedPointer<Database> db) const
{
settingsPage->loadSettings(widget, db);
page->loadSettings(widget, db);
}
void saveSettings() const
{
settingsPage->saveSettings(widget);
page->saveSettings(widget);
}

private:
QSharedPointer<IReportsPage> settingsPage;
QSharedPointer<IReportsPage> page;
QWidget* widget;
};

ReportsDialog::ReportsDialog(QWidget* parent)
: DialogyWidget(parent)
, m_ui(new Ui::ReportsDialog())
, m_healthPage(new ReportsPageHealthcheck())
, m_statPage(new ReportsPageStatistics())
, m_editEntryWidget(new EditEntryWidget(this))
{
m_ui->setupUi(this);

connect(m_ui->buttonBox, SIGNAL(rejected()), SLOT(reject()));
m_healthPage = new ReportsPageHealthcheck();
addPage(m_healthPage);
addPage(new ReportsPageStatistics());
addPage(m_statPage);

m_ui->stackedWidget->setCurrentIndex(0);

Expand Down Expand Up @@ -88,10 +89,10 @@ void ReportsDialog::load(const QSharedPointer<Database>& db)
m_db = db;
}

void ReportsDialog::addPage(IReportsPage* page)
void ReportsDialog::addPage(QSharedPointer<IReportsPage> page)
{
const int category = m_ui->categoryList->currentCategory();
QWidget* widget = page->createWidget();
const auto category = m_ui->categoryList->currentCategory();
const auto widget = page->createWidget();
widget->setParent(this);
m_extraPages.append(ExtraPage(page, widget));
m_ui->stackedWidget->addWidget(widget);
Expand Down
6 changes: 4 additions & 2 deletions src/gui/reports/ReportsDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Entry;
class Group;
class QTabWidget;
class ReportsPageHealthcheck;
class ReportsPageStatistics;

namespace Ui
{
Expand Down Expand Up @@ -60,7 +61,7 @@ class ReportsDialog : public DialogyWidget
Q_DISABLE_COPY(ReportsDialog);

void load(const QSharedPointer<Database>& db);
void addPage(IReportsPage* page);
void addPage(QSharedPointer<IReportsPage> page);

signals:
void editFinished(bool accepted);
Expand All @@ -73,7 +74,8 @@ private slots:
private:
QSharedPointer<Database> m_db;
const QScopedPointer<Ui::ReportsDialog> m_ui;
ReportsPageHealthcheck* m_healthPage = nullptr;
const QSharedPointer<ReportsPageHealthcheck> m_healthPage;
const QSharedPointer<ReportsPageStatistics> m_statPage;
QPointer<EditEntryWidget> m_editEntryWidget;

class ExtraPage;
Expand Down
3 changes: 1 addition & 2 deletions src/gui/reports/ReportsWidgetHealthcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "core/Group.h"
#include "core/PasswordHealth.h"

#include <QMap>
#include <QStandardItemModel>
#include <QVector>

Expand Down Expand Up @@ -201,7 +200,7 @@ void ReportsWidgetHealthcheck::showEvent(QShowEvent* event)

void ReportsWidgetHealthcheck::calculateHealth()
{
const auto health = AsyncTask::runAndWaitForFuture([this] { return new Health(m_db); });
const QScopedPointer<Health> health(AsyncTask::runAndWaitForFuture([this] { return new Health(m_db); }));

m_referencesModel->clear();
m_referencesModel->setHorizontalHeaderLabels(QStringList() << tr("") << tr("Title") << tr("Path") << tr("Reason"));
Expand Down
2 changes: 1 addition & 1 deletion src/gui/reports/ReportsWidgetStatistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ void ReportsWidgetStatistics::showEvent(QShowEvent* event)

void ReportsWidgetStatistics::calculateStats()
{
const auto stats = AsyncTask::runAndWaitForFuture([this] { return new Stats(m_db); });
const QScopedPointer<Stats> stats(AsyncTask::runAndWaitForFuture([this] { return new Stats(m_db); }));

m_referencesModel->clear();
addStatsRow(tr("Database name"), m_db->metadata()->name());
Expand Down

0 comments on commit 1096e19

Please sign in to comment.