Skip to content

Commit

Permalink
feat: get rid of memory leaks from SettingsDialog
Browse files Browse the repository at this point in the history
SettingsDialog causes a lot of memory leaks. This patch changes the
logic to only create the dialog on demand. This was asans output stays
readable when no SettingsDialog is opened.
  • Loading branch information
lievenhey committed Dec 10, 2024
1 parent 489df63 commit 091da7e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
37 changes: 20 additions & 17 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ MainWindow::MainWindow(QWidget* parent)
, m_startPage(new StartPage(this))
, m_recordPage(new RecordPage(this))
, m_resultsPage(new ResultsPage(m_parser, this))
, m_settingsDialog(new SettingsDialog(this))
{
ui->setupUi(this);

Expand All @@ -111,17 +110,6 @@ MainWindow::MainWindow(QWidget* parent)

auto settings = Settings::instance();

connect(m_settingsDialog, &QDialog::accepted, this, [this, settings]() {
settings->setSysroot(m_settingsDialog->sysroot());
settings->setAppPath(m_settingsDialog->appPath());
settings->setExtraLibPaths(m_settingsDialog->extraLibPaths());
settings->setDebugPaths(m_settingsDialog->debugPaths());
settings->setKallsyms(m_settingsDialog->kallsyms());
settings->setArch(m_settingsDialog->arch());
settings->setObjdump(m_settingsDialog->objdump());
settings->setPerfMapPath(m_settingsDialog->perfMapPath());
});

connect(settings, &Settings::sysrootChanged, m_resultsPage, &ResultsPage::setSysroot);
connect(settings, &Settings::appPathChanged, m_resultsPage, &ResultsPage::setAppPath);
connect(m_startPage, &StartPage::pathSettingsButtonClicked, this, &MainWindow::openSettingsDialog);
Expand Down Expand Up @@ -419,11 +407,26 @@ void MainWindow::aboutKDAB()

void MainWindow::openSettingsDialog()
{
m_settingsDialog->setWindowTitle(tr("Hotspot configuration"));
m_settingsDialog->setWindowIcon(windowIcon());
m_settingsDialog->adjustSize();
m_settingsDialog->initSettings();
m_settingsDialog->open();
auto settings = Settings::instance();

auto settingsDialog = new SettingsDialog(this);

connect(settingsDialog, &QDialog::accepted, this, [settingsDialog, settings]() {
settings->setSysroot(settingsDialog->sysroot());
settings->setAppPath(settingsDialog->appPath());
settings->setExtraLibPaths(settingsDialog->extraLibPaths());
settings->setDebugPaths(settingsDialog->debugPaths());
settings->setKallsyms(settingsDialog->kallsyms());
settings->setArch(settingsDialog->arch());
settings->setObjdump(settingsDialog->objdump());
settings->setPerfMapPath(settingsDialog->perfMapPath());
});

settingsDialog->setWindowTitle(tr("Hotspot configuration"));
settingsDialog->setWindowIcon(windowIcon());
settingsDialog->adjustSize();
settingsDialog->initSettings();
settingsDialog->open();
}

void MainWindow::aboutHotspot()
Expand Down
2 changes: 0 additions & 2 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class KRecentFilesAction;
class StartPage;
class ResultsPage;
class RecordPage;
class SettingsDialog;

class MainWindow : public KParts::MainWindow
{
Expand Down Expand Up @@ -78,7 +77,6 @@ public slots:
StartPage* m_startPage;
RecordPage* m_recordPage;
ResultsPage* m_resultsPage;
SettingsDialog* m_settingsDialog;

KRecentFilesAction* m_recentFilesAction = nullptr;
QAction* m_reloadAction = nullptr;
Expand Down
2 changes: 2 additions & 0 deletions src/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ SettingsDialog::SettingsDialog(QWidget* parent)
addCallgraphPage();
#endif
addSourcePathPage();

setAttribute(Qt::WA_DeleteOnClose);
}

SettingsDialog::~SettingsDialog() = default;
Expand Down

0 comments on commit 091da7e

Please sign in to comment.