From 2a089d96922e855963e4e0c3846f719e9d138335 Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Thu, 1 Nov 2018 23:34:45 -0700 Subject: [PATCH] fix memory leaks --- src/connection.cpp | 47 ++++++++++++-------------------------------- src/connection.h | 4 +++- src/rpc.cpp | 2 ++ src/txtablemodel.cpp | 5 ++++- 4 files changed, 22 insertions(+), 36 deletions(-) diff --git a/src/connection.cpp b/src/connection.cpp index f9c9bef..f410824 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -7,22 +7,7 @@ #include "precompiled.h" using json = nlohmann::json; -/* -class LoadingDialog : public QDialog { - //Q_OBJECT -public: - LoadingDialog(QWidget* parent); - ~LoadingDialog(); -public slots: - void reject(); -}; -LoadingDialog::LoadingDialog(QWidget* parent) : QDialog(parent) {} -LoadingDialog::~LoadingDialog() {} -void LoadingDialog::reject() { - //event->ignore(); -} -*/ ConnectionLoader::ConnectionLoader(MainWindow* main, RPC* rpc) { this->main = main; this->rpc = rpc; @@ -61,7 +46,7 @@ void ConnectionLoader::loadConnection() { % "please set the host/port and user/password in the File->Settings menu."; showError(explanation); - rpc->setConnection(nullptr); + doRPCSetConnection(nullptr); return; } @@ -71,6 +56,11 @@ void ConnectionLoader::loadConnection() { refreshZcashdState(connection); } +void ConnectionLoader::doRPCSetConnection(Connection* conn) { + rpc->setConnection(conn); + delete this; +} + Connection* ConnectionLoader::makeConnection(std::shared_ptr config) { QNetworkAccessManager* client = new QNetworkAccessManager(main); @@ -100,7 +90,7 @@ void ConnectionLoader::refreshZcashdState(Connection* connection) { [=] (auto) { // Success, hide the dialog if it was shown. d->hide(); - rpc->setConnection(connection); + doRPCSetConnection(connection); }, [=] (auto reply, auto res) { d->show(); @@ -148,16 +138,6 @@ void ConnectionLoader::showError(QString explanation) { connD->buttonBox->setEnabled(true); } -/* -int ConnectionLoader::getProgressFromStatus(QString status) { - if (status.startsWith("Loading block")) return 20; - if (status.startsWith("Verifying")) return 40; - if (status.startsWith("Loading Wallet")) return 60; - if (status.startsWith("Activating")) return 80; - if (status.startsWith("Rescanning")) return 90; - return 0; -} -*/ /** * Try to automatically detect a zcash.conf file in the correct location and load parameters @@ -248,10 +228,11 @@ std::shared_ptr ConnectionLoader::loadFromSettings() { - - - -Connection::Connection(MainWindow* m, QNetworkAccessManager* c, QNetworkRequest* r, std::shared_ptr conf) { +/*********************************************************************************** + * Connection Class + ************************************************************************************/ +Connection::Connection(MainWindow* m, QNetworkAccessManager* c, QNetworkRequest* r, + std::shared_ptr conf) { this->restclient = c; this->request = r; this->config = conf; @@ -263,8 +244,6 @@ Connection::~Connection() { delete request; } - - void Connection::doRPC(const json& payload, const std::function& cb, const std::function& ne) { QNetworkReply *reply = restclient->post(*request, QByteArray::fromStdString(payload.dump())); @@ -315,4 +294,4 @@ void Connection::showTxError(const QString& error) { + error); msg.exec(); -} \ No newline at end of file +} diff --git a/src/connection.h b/src/connection.h index 48ab48f..d6c26a9 100644 --- a/src/connection.h +++ b/src/connection.h @@ -46,6 +46,8 @@ private: void showError(QString explanation); + void doRPCSetConnection(Connection* conn); + QDialog* d; Ui_ConnectionDialog* connD; @@ -122,4 +124,4 @@ public: } }; -#endif \ No newline at end of file +#endif diff --git a/src/rpc.cpp b/src/rpc.cpp index cd7b447..a93c8e2 100644 --- a/src/rpc.cpp +++ b/src/rpc.cpp @@ -261,6 +261,7 @@ void RPC::getAllPrivKeys(const std::function> } fnCombineTwoLists(allTKeys); + delete privkeys; } ); }); @@ -677,6 +678,7 @@ void RPC::refreshSentZTrans() { } transactionsTableModel->addZSentData(newSentZTxs); + delete txidList; } ); } diff --git a/src/txtablemodel.cpp b/src/txtablemodel.cpp index 12664ec..bc49bf6 100644 --- a/src/txtablemodel.cpp +++ b/src/txtablemodel.cpp @@ -10,6 +10,9 @@ TxTableModel::TxTableModel(QObject *parent) TxTableModel::~TxTableModel() { delete modeldata; + delete tTrans; + delete zsTrans; + delete zrTrans; } void TxTableModel::addZSentData(const QList& data) { @@ -159,4 +162,4 @@ QString TxTableModel::getTxId(int row) { QString TxTableModel::getMemo(int row) { return modeldata->at(row).memo; -} \ No newline at end of file +}