fix a few memory leaks

This commit is contained in:
tobtoht 2024-10-01 05:47:57 +02:00
parent 37aa04e3e5
commit c31b351b17
No known key found for this signature in database
GPG key ID: E45B10DD027D2472
9 changed files with 31 additions and 19 deletions

View file

@ -323,7 +323,7 @@ void MainWindow::initMenu() {
// Show/Hide Coins // Show/Hide Coins
connect(ui->actionShow_Coins, &QAction::triggered, m_tabShowHideSignalMapper, QOverload<>::of(&QSignalMapper::map)); 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"); m_tabShowHideSignalMapper->setMapping(ui->actionShow_Coins, "Coins");
// Show/Hide Plugins.. // Show/Hide Plugins..
@ -335,7 +335,7 @@ void MainWindow::initMenu() {
auto* pluginAction = new QAction(QString("Show %1").arg(plugin->displayName()), this); auto* pluginAction = new QAction(QString("Show %1").arg(plugin->displayName()), this);
ui->menuView->insertAction(plugin->insertFirst() ? ui->actionPlaceholderBegin : ui->actionPlaceholderEnd, pluginAction); ui->menuView->insertAction(plugin->insertFirst() ? ui->actionPlaceholderBegin : ui->actionPlaceholderEnd, pluginAction);
connect(pluginAction, &QAction::triggered, m_tabShowHideSignalMapper, QOverload<>::of(&QSignalMapper::map)); 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()); m_tabShowHideSignalMapper->setMapping(pluginAction, plugin->displayName());
} }
ui->actionPlaceholderBegin->setVisible(false); ui->actionPlaceholderBegin->setVisible(false);

View file

@ -51,9 +51,12 @@ namespace Ui {
class MainWindow; class MainWindow;
} }
struct ToggleTab { class ToggleTab : QObject {
ToggleTab(QWidget *tab, QString name, QString description, QAction *menuAction) : Q_OBJECT
tab(tab), key(std::move(name)), name(std::move(description)), menuAction(menuAction) {}
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; QWidget *tab;
QString key; QString key;
QString name; QString name;

View file

@ -71,7 +71,7 @@ ReceiveWidget::ReceiveWidget(Wallet *wallet, QWidget *parent)
// context menu // context menu
ui->addresses->setContextMenuPolicy(Qt::CustomContextMenu); 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(m_showTransactionsAction, &QAction::triggered, this, &ReceiveWidget::onShowTransactions);
connect(ui->addresses, &QTreeView::customContextMenuRequested, this, &ReceiveWidget::showContextMenu); connect(ui->addresses, &QTreeView::customContextMenuRequested, this, &ReceiveWidget::showContextMenu);
connect(ui->addresses, &SubaddressView::copyAddress, this, &ReceiveWidget::copyAddress); connect(ui->addresses, &SubaddressView::copyAddress, this, &ReceiveWidget::copyAddress);

View file

@ -105,7 +105,7 @@ void TransactionHistory::refresh()
if (payment_id.substr(16).find_first_not_of('0') == std::string::npos) if (payment_id.substr(16).find_first_not_of('0') == std::string::npos)
payment_id = payment_id.substr(0,16); 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_paymentId = QString::fromStdString(payment_id);
t->m_coinbase = pd.m_coinbase; t->m_coinbase = pd.m_coinbase;
t->m_amount = pd.m_amount; 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) if (payment_id.substr(16).find_first_not_of('0') == std::string::npos)
payment_id = payment_id.substr(0,16); 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_paymentId = QString::fromStdString(payment_id);
t->m_amount = pd.m_amount_out - change; t->m_amount = pd.m_amount_out - change;
@ -206,7 +206,7 @@ void TransactionHistory::refresh()
payment_id = payment_id.substr(0,16); payment_id = payment_id.substr(0,16);
bool is_failed = pd.m_state == tools::wallet2::unconfirmed_transfer_details::failed; 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_paymentId = QString::fromStdString(payment_id);
t->m_amount = pd.m_amount_out - change; 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); 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) if (payment_id.substr(16).find_first_not_of('0') == std::string::npos)
payment_id = payment_id.substr(0,16); 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_paymentId = QString::fromStdString(payment_id);
t->m_amount = pd.m_amount; t->m_amount = pd.m_amount;
t->m_balanceDelta = pd.m_amount; t->m_balanceDelta = pd.m_amount;

View file

@ -6,8 +6,9 @@
#include "Transfer.h" #include "Transfer.h"
#include "Ring.h" #include "Ring.h"
TransactionRow::TransactionRow() TransactionRow::TransactionRow(QObject *parent)
: m_direction(TransactionRow::Direction_Out) : QObject(parent)
, m_direction(TransactionRow::Direction_Out)
, m_pending(false) , m_pending(false)
, m_failed(false) , m_failed(false)
, m_coinbase(false) , m_coinbase(false)
@ -164,4 +165,10 @@ QString TransactionRow::rings_formatted() const
rings += "\n\n"; rings += "\n\n";
} }
return rings; return rings;
} }
TransactionRow::~TransactionRow()
{
qDeleteAll(m_transfers);
qDeleteAll(m_rings);
}

View file

@ -16,6 +16,8 @@ class TransactionRow : public QObject
Q_OBJECT Q_OBJECT
public: public:
~TransactionRow() override;
enum Direction { enum Direction {
Direction_In = 0, Direction_In = 0,
Direction_Out = 1, Direction_Out = 1,
@ -52,12 +54,12 @@ public:
QString rings_formatted() const; QString rings_formatted() const;
private: private:
explicit TransactionRow(); explicit TransactionRow(QObject *parent);
private: private:
friend class TransactionHistory; friend class TransactionHistory;
mutable QList<Transfer*> m_transfers; QList<Transfer*> m_transfers;
mutable QList<Ring*> m_rings; QList<Ring*> m_rings;
qint64 m_amount; // Amount that was sent (to destinations) or received, excludes tx fee 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) qint64 m_balanceDelta; // How much the total balance was mutated as a result of this tx (includes tx fee)
quint64 m_blockHeight; quint64 m_blockHeight;

View file

@ -20,7 +20,7 @@ XMRigWidget::XMRigWidget(Wallet *wallet, QWidget *parent)
: QWidget(parent) : QWidget(parent)
, ui(new Ui::XMRigWidget) , ui(new Ui::XMRigWidget)
, m_wallet(wallet) , m_wallet(wallet)
, m_XMRig(new XmRig(Config::defaultConfigDir().path())) , m_XMRig(new XmRig(Config::defaultConfigDir().path(), this))
, m_model(new QStandardItemModel(this)) , m_model(new QStandardItemModel(this))
, m_contextMenu(new QMenu(this)) , m_contextMenu(new QMenu(this))
{ {

View file

@ -37,7 +37,7 @@ NetworkProxyWidget::NetworkProxyWidget(QWidget *parent)
connect(ui->line_host, &QLineEdit::textChanged, this, &NetworkProxyWidget::onProxySettingsChanged); connect(ui->line_host, &QLineEdit::textChanged, this, &NetworkProxyWidget::onProxySettingsChanged);
// [Port] // [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->setValidator(portValidator);
ui->line_port->setText(conf()->get(Config::socks5Port).toString()); ui->line_port->setText(conf()->get(Config::socks5Port).toString());
connect(ui->line_port, &QLineEdit::textChanged, this, &NetworkProxyWidget::onProxySettingsChanged); connect(ui->line_port, &QLineEdit::textChanged, this, &NetworkProxyWidget::onProxySettingsChanged);

View file

@ -16,7 +16,7 @@ PageSetSubaddressLookahead::PageSetSubaddressLookahead(WizardFields *fields, QWi
{ {
ui->setupUi(this); 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); ui->line_major->setValidator(indexValidator);
connect(ui->line_major, &QLineEdit::textChanged, [this]{ connect(ui->line_major, &QLineEdit::textChanged, [this]{