From c31b351b173fa8010da0984a0ebe656850b10c41 Mon Sep 17 00:00:00 2001 From: tobtoht Date: Tue, 1 Oct 2024 05:47:57 +0200 Subject: [PATCH] fix a few memory leaks --- src/MainWindow.cpp | 4 ++-- src/MainWindow.h | 9 ++++++--- src/ReceiveWidget.cpp | 2 +- src/libwalletqt/TransactionHistory.cpp | 8 ++++---- src/libwalletqt/rows/TransactionRow.cpp | 13 ++++++++++--- src/libwalletqt/rows/TransactionRow.h | 8 +++++--- src/plugins/xmrig/XMRigWidget.cpp | 2 +- src/widgets/NetworkProxyWidget.cpp | 2 +- src/wizard/PageSetSubaddressLookahead.cpp | 2 +- 9 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index fa2b4c2..848f1e3 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -323,7 +323,7 @@ void MainWindow::initMenu() { // Show/Hide Coins connect(ui->actionShow_Coins, &QAction::triggered, m_tabShowHideSignalMapper, QOverload<>::of(&QSignalMapper::map)); - m_tabShowHideMapper["Coins"] = new ToggleTab(ui->tabCoins, "Coins", "Coins", ui->actionShow_Coins); + m_tabShowHideMapper["Coins"] = new ToggleTab(ui->tabCoins, "Coins", "Coins", ui->actionShow_Coins, this); m_tabShowHideSignalMapper->setMapping(ui->actionShow_Coins, "Coins"); // Show/Hide Plugins.. @@ -335,7 +335,7 @@ void MainWindow::initMenu() { auto* pluginAction = new QAction(QString("Show %1").arg(plugin->displayName()), this); ui->menuView->insertAction(plugin->insertFirst() ? ui->actionPlaceholderBegin : ui->actionPlaceholderEnd, pluginAction); connect(pluginAction, &QAction::triggered, m_tabShowHideSignalMapper, QOverload<>::of(&QSignalMapper::map)); - m_tabShowHideMapper[plugin->displayName()] = new ToggleTab(plugin->tab(), plugin->displayName(), plugin->displayName(), pluginAction); + m_tabShowHideMapper[plugin->displayName()] = new ToggleTab(plugin->tab(), plugin->displayName(), plugin->displayName(), pluginAction, this); m_tabShowHideSignalMapper->setMapping(pluginAction, plugin->displayName()); } ui->actionPlaceholderBegin->setVisible(false); diff --git a/src/MainWindow.h b/src/MainWindow.h index ac9251e..bab68a3 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -51,9 +51,12 @@ namespace Ui { class MainWindow; } -struct ToggleTab { - ToggleTab(QWidget *tab, QString name, QString description, QAction *menuAction) : - tab(tab), key(std::move(name)), name(std::move(description)), menuAction(menuAction) {} +class ToggleTab : QObject { +Q_OBJECT + +public: + ToggleTab(QWidget *tab, QString name, QString description, QAction *menuAction, QObject *parent = nullptr) : + QObject(parent), tab(tab), key(std::move(name)), name(std::move(description)), menuAction(menuAction) {} QWidget *tab; QString key; QString name; diff --git a/src/ReceiveWidget.cpp b/src/ReceiveWidget.cpp index c57e5c9..a463401 100644 --- a/src/ReceiveWidget.cpp +++ b/src/ReceiveWidget.cpp @@ -71,7 +71,7 @@ ReceiveWidget::ReceiveWidget(Wallet *wallet, QWidget *parent) // context menu ui->addresses->setContextMenuPolicy(Qt::CustomContextMenu); - m_showTransactionsAction = new QAction("Show transactions"); + m_showTransactionsAction = new QAction("Show transactions", this); connect(m_showTransactionsAction, &QAction::triggered, this, &ReceiveWidget::onShowTransactions); connect(ui->addresses, &QTreeView::customContextMenuRequested, this, &ReceiveWidget::showContextMenu); connect(ui->addresses, &SubaddressView::copyAddress, this, &ReceiveWidget::copyAddress); diff --git a/src/libwalletqt/TransactionHistory.cpp b/src/libwalletqt/TransactionHistory.cpp index 37ee863..905af2d 100644 --- a/src/libwalletqt/TransactionHistory.cpp +++ b/src/libwalletqt/TransactionHistory.cpp @@ -105,7 +105,7 @@ void TransactionHistory::refresh() if (payment_id.substr(16).find_first_not_of('0') == std::string::npos) payment_id = payment_id.substr(0,16); - auto* t = new TransactionRow(); + auto* t = new TransactionRow(this); t->m_paymentId = QString::fromStdString(payment_id); t->m_coinbase = pd.m_coinbase; t->m_amount = pd.m_amount; @@ -152,7 +152,7 @@ void TransactionHistory::refresh() if (payment_id.substr(16).find_first_not_of('0') == std::string::npos) payment_id = payment_id.substr(0,16); - auto* t = new TransactionRow(); + auto* t = new TransactionRow(this); t->m_paymentId = QString::fromStdString(payment_id); t->m_amount = pd.m_amount_out - change; @@ -206,7 +206,7 @@ void TransactionHistory::refresh() payment_id = payment_id.substr(0,16); bool is_failed = pd.m_state == tools::wallet2::unconfirmed_transfer_details::failed; - auto *t = new TransactionRow(); + auto *t = new TransactionRow(this); t->m_paymentId = QString::fromStdString(payment_id); t->m_amount = pd.m_amount_out - change; @@ -254,7 +254,7 @@ void TransactionHistory::refresh() std::string payment_id = epee::string_tools::pod_to_hex(i->first); if (payment_id.substr(16).find_first_not_of('0') == std::string::npos) payment_id = payment_id.substr(0,16); - auto *t = new TransactionRow(); + auto *t = new TransactionRow(this); t->m_paymentId = QString::fromStdString(payment_id); t->m_amount = pd.m_amount; t->m_balanceDelta = pd.m_amount; diff --git a/src/libwalletqt/rows/TransactionRow.cpp b/src/libwalletqt/rows/TransactionRow.cpp index a4c1b7f..0edb315 100644 --- a/src/libwalletqt/rows/TransactionRow.cpp +++ b/src/libwalletqt/rows/TransactionRow.cpp @@ -6,8 +6,9 @@ #include "Transfer.h" #include "Ring.h" -TransactionRow::TransactionRow() - : m_direction(TransactionRow::Direction_Out) +TransactionRow::TransactionRow(QObject *parent) + : QObject(parent) + , m_direction(TransactionRow::Direction_Out) , m_pending(false) , m_failed(false) , m_coinbase(false) @@ -164,4 +165,10 @@ QString TransactionRow::rings_formatted() const rings += "\n\n"; } return rings; -} \ No newline at end of file +} + +TransactionRow::~TransactionRow() +{ + qDeleteAll(m_transfers); + qDeleteAll(m_rings); +} diff --git a/src/libwalletqt/rows/TransactionRow.h b/src/libwalletqt/rows/TransactionRow.h index 3fb8be4..68b21e2 100644 --- a/src/libwalletqt/rows/TransactionRow.h +++ b/src/libwalletqt/rows/TransactionRow.h @@ -16,6 +16,8 @@ class TransactionRow : public QObject Q_OBJECT public: + ~TransactionRow() override; + enum Direction { Direction_In = 0, Direction_Out = 1, @@ -52,12 +54,12 @@ public: QString rings_formatted() const; private: - explicit TransactionRow(); + explicit TransactionRow(QObject *parent); private: friend class TransactionHistory; - mutable QList m_transfers; - mutable QList m_rings; + QList m_transfers; + QList m_rings; qint64 m_amount; // Amount that was sent (to destinations) or received, excludes tx fee qint64 m_balanceDelta; // How much the total balance was mutated as a result of this tx (includes tx fee) quint64 m_blockHeight; diff --git a/src/plugins/xmrig/XMRigWidget.cpp b/src/plugins/xmrig/XMRigWidget.cpp index 256c1f1..0759514 100644 --- a/src/plugins/xmrig/XMRigWidget.cpp +++ b/src/plugins/xmrig/XMRigWidget.cpp @@ -20,7 +20,7 @@ XMRigWidget::XMRigWidget(Wallet *wallet, QWidget *parent) : QWidget(parent) , ui(new Ui::XMRigWidget) , m_wallet(wallet) - , m_XMRig(new XmRig(Config::defaultConfigDir().path())) + , m_XMRig(new XmRig(Config::defaultConfigDir().path(), this)) , m_model(new QStandardItemModel(this)) , m_contextMenu(new QMenu(this)) { diff --git a/src/widgets/NetworkProxyWidget.cpp b/src/widgets/NetworkProxyWidget.cpp index 35cc1e9..c79b90c 100644 --- a/src/widgets/NetworkProxyWidget.cpp +++ b/src/widgets/NetworkProxyWidget.cpp @@ -37,7 +37,7 @@ NetworkProxyWidget::NetworkProxyWidget(QWidget *parent) connect(ui->line_host, &QLineEdit::textChanged, this, &NetworkProxyWidget::onProxySettingsChanged); // [Port] - auto *portValidator = new QRegularExpressionValidator{QRegularExpression("[0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]")}; + auto *portValidator = new QRegularExpressionValidator{QRegularExpression("[0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]"), this}; ui->line_port->setValidator(portValidator); ui->line_port->setText(conf()->get(Config::socks5Port).toString()); connect(ui->line_port, &QLineEdit::textChanged, this, &NetworkProxyWidget::onProxySettingsChanged); diff --git a/src/wizard/PageSetSubaddressLookahead.cpp b/src/wizard/PageSetSubaddressLookahead.cpp index 6d9e05b..f83839a 100644 --- a/src/wizard/PageSetSubaddressLookahead.cpp +++ b/src/wizard/PageSetSubaddressLookahead.cpp @@ -16,7 +16,7 @@ PageSetSubaddressLookahead::PageSetSubaddressLookahead(WizardFields *fields, QWi { ui->setupUi(this); - auto *indexValidator = new QRegularExpressionValidator{QRegularExpression("[0-9]{0,5}")}; + auto *indexValidator = new QRegularExpressionValidator{QRegularExpression("[0-9]{0,5}"), this}; ui->line_major->setValidator(indexValidator); connect(ui->line_major, &QLineEdit::textChanged, [this]{