]> Nutra Git (v2) - gamesguru/feather.git/commitdiff
fix a few memory leaks
authortobtoht <tob@featherwallet.org>
Tue, 1 Oct 2024 03:47:57 +0000 (05:47 +0200)
committertobtoht <tob@featherwallet.org>
Tue, 1 Oct 2024 03:47:57 +0000 (05:47 +0200)
src/MainWindow.cpp
src/MainWindow.h
src/ReceiveWidget.cpp
src/libwalletqt/TransactionHistory.cpp
src/libwalletqt/rows/TransactionRow.cpp
src/libwalletqt/rows/TransactionRow.h
src/plugins/xmrig/XMRigWidget.cpp
src/widgets/NetworkProxyWidget.cpp
src/wizard/PageSetSubaddressLookahead.cpp

index fa2b4c21f75e9f0e4dedfce6e4e3716d7317e179..848f1e3ab0e099e1c970ea9ea4561e2ef8d07d61 100644 (file)
@@ -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);
index ac9251eccdcfdc083d5d81e79bb7955633633892..bab68a3b6a337fe45fc558e48ef01bc5ba4e8667 100644 (file)
@@ -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;
index c57e5c9f50dee3f809b628290ab90d05be69e31a..a4634018d8785aaedaf97a42089167bc9aa2c40e 100644 (file)
@@ -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);
index 37ee863e37d1cc318504ba59f03cdf248b581c62..905af2df0cbf677f417dc425721464998d352ef7 100644 (file)
@@ -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;
index a4c1b7fed7a478b4a3d69de2e3db2a56339de86c..0edb315b1a3a27272dd15fe4ceffe1e395cdf2d5 100644 (file)
@@ -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);
+}
index 3fb8be4cfb94c6c8af4c3385da24bec8cfb5e5a3..68b21e22521a06df79b36df440f153ef9a2d3d62 100644 (file)
@@ -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<Transfer*> m_transfers;
-    mutable QList<Ring*> m_rings;
+    QList<Transfer*> m_transfers;
+    QList<Ring*> 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;
index 256c1f15411a3783b711ff0b01c5cd5215b01953..0759514dbc6100994dfb5655eb699696a92f9fee 100644 (file)
@@ -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))
 {
index 35cc1e972e22bd5f5c0feac76104faec2a4c7661..c79b90cb2b8b40d9c6166aa816493e32db121a36 100644 (file)
@@ -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);
index 6d9e05b4bf911ad3b4e9fb65ff4ae7cabafab91c..f83839a5e02ad397487e12ef804d59ebf389e0f7 100644 (file)
@@ -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]{