From 99587f8e8004ca7c4d589081b629c5a5def75c03 Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Thu, 24 Oct 2019 19:28:31 -0700 Subject: [PATCH] Memory leak --- src/connection.cpp | 18 ++++++++---------- src/connection.h | 11 ++++++----- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/connection.cpp b/src/connection.cpp index 46f290e..3744a9f 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -22,9 +22,12 @@ ConnectionLoader::ConnectionLoader(MainWindow* main, Controller* rpc) { connD->setupUi(d); QPixmap logo(":/img/res/logobig.gif"); connD->topIcon->setBasePixmap(logo.scaled(256, 256, Qt::KeepAspectRatio, Qt::SmoothTransformation)); + + isSyncing = new QAtomicInteger(); } -ConnectionLoader::~ConnectionLoader() { +ConnectionLoader::~ConnectionLoader() { + delete isSyncing; delete connD; delete d; } @@ -61,7 +64,7 @@ void ConnectionLoader::doAutoConnect() { // If success, set the connection main->logger->write("Connection is online."); - QAtomicInteger* isSyncing = new QAtomicInteger(); + isSyncing = new QAtomicInteger(); isSyncing->store(true); // Do a sync at startup @@ -78,14 +81,11 @@ void ConnectionLoader::doAutoConnect() { // While it is syncing, we'll show the status updates while it is alive. QObject::connect(syncTimer, &QTimer::timeout, [=]() { - qDebug() << "Sync timer" << isSyncing->load(); // Check the sync status - if (isSyncing->load()) { + if (isSyncing != nullptr && isSyncing->load()) { // Get the sync status connection->doRPC("syncstatus", "", [=](json reply) { - qDebug() << QString::fromStdString("Sync statys = ") << QString::fromStdString(reply.dump()); - - if (isSyncing->load() && reply.find("synced_blocks") != reply.end()) { + if (isSyncing != nullptr && reply.find("synced_blocks") != reply.end()) { qint64 synced = reply["synced_blocks"].get(); qint64 total = reply["total_blocks"].get(); showInformation("Synced " + QString::number(synced) + " / " + QString::number(total)); @@ -94,13 +94,11 @@ void ConnectionLoader::doAutoConnect() { [=](QString err) { qDebug() << "Sync error" << err; }); - } else { - delete isSyncing; } }); syncTimer->setInterval(1* 1000); - syncTimer->start(1000); + syncTimer->start(); }, [=](QString err) { showError(err); diff --git a/src/connection.h b/src/connection.h index 970d6af..7ea28b1 100644 --- a/src/connection.h +++ b/src/connection.h @@ -40,13 +40,14 @@ private: void doRPCSetConnection(Connection* conn); - QTimer* syncTimer; + QTimer* syncTimer = nullptr; + QAtomicInteger* isSyncing = nullptr; - QDialog* d; - Ui_ConnectionDialog* connD; + QDialog* d = nullptr; + Ui_ConnectionDialog* connD = nullptr; - MainWindow* main; - Controller* rpc; + MainWindow* main = nullptr; + Controller* rpc = nullptr; }; /**