Memory leak

This commit is contained in:
Aditya Kulkarni
2019-10-24 19:28:31 -07:00
parent 2fabc1ec8d
commit 99587f8e80
2 changed files with 14 additions and 15 deletions

View File

@@ -22,9 +22,12 @@ ConnectionLoader::ConnectionLoader(MainWindow* main, Controller* rpc) {
connD->setupUi(d); connD->setupUi(d);
QPixmap logo(":/img/res/logobig.gif"); QPixmap logo(":/img/res/logobig.gif");
connD->topIcon->setBasePixmap(logo.scaled(256, 256, Qt::KeepAspectRatio, Qt::SmoothTransformation)); connD->topIcon->setBasePixmap(logo.scaled(256, 256, Qt::KeepAspectRatio, Qt::SmoothTransformation));
isSyncing = new QAtomicInteger<bool>();
} }
ConnectionLoader::~ConnectionLoader() { ConnectionLoader::~ConnectionLoader() {
delete isSyncing;
delete connD; delete connD;
delete d; delete d;
} }
@@ -61,7 +64,7 @@ void ConnectionLoader::doAutoConnect() {
// If success, set the connection // If success, set the connection
main->logger->write("Connection is online."); main->logger->write("Connection is online.");
QAtomicInteger<bool>* isSyncing = new QAtomicInteger<bool>(); isSyncing = new QAtomicInteger<bool>();
isSyncing->store(true); isSyncing->store(true);
// Do a sync at startup // 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. // While it is syncing, we'll show the status updates while it is alive.
QObject::connect(syncTimer, &QTimer::timeout, [=]() { QObject::connect(syncTimer, &QTimer::timeout, [=]() {
qDebug() << "Sync timer" << isSyncing->load();
// Check the sync status // Check the sync status
if (isSyncing->load()) { if (isSyncing != nullptr && isSyncing->load()) {
// Get the sync status // Get the sync status
connection->doRPC("syncstatus", "", [=](json reply) { connection->doRPC("syncstatus", "", [=](json reply) {
qDebug() << QString::fromStdString("Sync statys = ") << QString::fromStdString(reply.dump()); if (isSyncing != nullptr && reply.find("synced_blocks") != reply.end()) {
if (isSyncing->load() && reply.find("synced_blocks") != reply.end()) {
qint64 synced = reply["synced_blocks"].get<json::number_unsigned_t>(); qint64 synced = reply["synced_blocks"].get<json::number_unsigned_t>();
qint64 total = reply["total_blocks"].get<json::number_unsigned_t>(); qint64 total = reply["total_blocks"].get<json::number_unsigned_t>();
showInformation("Synced " + QString::number(synced) + " / " + QString::number(total)); showInformation("Synced " + QString::number(synced) + " / " + QString::number(total));
@@ -94,13 +94,11 @@ void ConnectionLoader::doAutoConnect() {
[=](QString err) { [=](QString err) {
qDebug() << "Sync error" << err; qDebug() << "Sync error" << err;
}); });
} else {
delete isSyncing;
} }
}); });
syncTimer->setInterval(1* 1000); syncTimer->setInterval(1* 1000);
syncTimer->start(1000); syncTimer->start();
}, [=](QString err) { }, [=](QString err) {
showError(err); showError(err);

View File

@@ -40,13 +40,14 @@ private:
void doRPCSetConnection(Connection* conn); void doRPCSetConnection(Connection* conn);
QTimer* syncTimer; QTimer* syncTimer = nullptr;
QAtomicInteger<bool>* isSyncing = nullptr;
QDialog* d; QDialog* d = nullptr;
Ui_ConnectionDialog* connD; Ui_ConnectionDialog* connD = nullptr;
MainWindow* main; MainWindow* main = nullptr;
Controller* rpc; Controller* rpc = nullptr;
}; };
/** /**