mirror of
https://github.com/monero-project/monero-gui.git
synced 2024-11-17 08:17:59 +00:00
DaemonManager: fix memory leak
This commit is contained in:
parent
585fb2810d
commit
9748974ce0
2 changed files with 20 additions and 7 deletions
|
@ -29,6 +29,7 @@
|
||||||
#include "DaemonManager.h"
|
#include "DaemonManager.h"
|
||||||
#include <QElapsedTimer>
|
#include <QElapsedTimer>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
#include <QMutexLocker>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
@ -123,18 +124,20 @@ bool DaemonManager::start(const QString &flags, NetworkType::Type nettype, const
|
||||||
qDebug() << "starting monerod " + m_monerod;
|
qDebug() << "starting monerod " + m_monerod;
|
||||||
qDebug() << "With command line arguments " << arguments;
|
qDebug() << "With command line arguments " << arguments;
|
||||||
|
|
||||||
m_daemon = new QProcess();
|
QMutexLocker locker(&m_daemonMutex);
|
||||||
|
|
||||||
|
m_daemon.reset(new QProcess());
|
||||||
initialized = true;
|
initialized = true;
|
||||||
|
|
||||||
// Connect output slots
|
// Connect output slots
|
||||||
connect (m_daemon, SIGNAL(readyReadStandardOutput()), this, SLOT(printOutput()));
|
connect(m_daemon.get(), SIGNAL(readyReadStandardOutput()), this, SLOT(printOutput()));
|
||||||
connect (m_daemon, SIGNAL(readyReadStandardError()), this, SLOT(printError()));
|
connect(m_daemon.get(), SIGNAL(readyReadStandardError()), this, SLOT(printError()));
|
||||||
|
|
||||||
// Start monerod
|
// Start monerod
|
||||||
bool started = m_daemon->startDetached(m_monerod, arguments);
|
bool started = m_daemon->startDetached(m_monerod, arguments);
|
||||||
|
|
||||||
// add state changed listener
|
// add state changed listener
|
||||||
connect(m_daemon,SIGNAL(stateChanged(QProcess::ProcessState)),this,SLOT(stateChanged(QProcess::ProcessState)));
|
connect(m_daemon.get(), SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(stateChanged(QProcess::ProcessState)));
|
||||||
|
|
||||||
if (!started) {
|
if (!started) {
|
||||||
qDebug() << "Daemon start error: " + m_daemon->errorString();
|
qDebug() << "Daemon start error: " + m_daemon->errorString();
|
||||||
|
@ -223,7 +226,10 @@ void DaemonManager::stateChanged(QProcess::ProcessState state)
|
||||||
|
|
||||||
void DaemonManager::printOutput()
|
void DaemonManager::printOutput()
|
||||||
{
|
{
|
||||||
QByteArray byteArray = m_daemon->readAllStandardOutput();
|
QByteArray byteArray = [this]() {
|
||||||
|
QMutexLocker locker(&m_daemonMutex);
|
||||||
|
return m_daemon->readAllStandardOutput();
|
||||||
|
}();
|
||||||
QStringList strLines = QString(byteArray).split("\n");
|
QStringList strLines = QString(byteArray).split("\n");
|
||||||
|
|
||||||
foreach (QString line, strLines) {
|
foreach (QString line, strLines) {
|
||||||
|
@ -234,7 +240,10 @@ void DaemonManager::printOutput()
|
||||||
|
|
||||||
void DaemonManager::printError()
|
void DaemonManager::printError()
|
||||||
{
|
{
|
||||||
QByteArray byteArray = m_daemon->readAllStandardError();
|
QByteArray byteArray = [this]() {
|
||||||
|
QMutexLocker locker(&m_daemonMutex);
|
||||||
|
return m_daemon->readAllStandardError();
|
||||||
|
}();
|
||||||
QStringList strLines = QString(byteArray).split("\n");
|
QStringList strLines = QString(byteArray).split("\n");
|
||||||
|
|
||||||
foreach (QString line, strLines) {
|
foreach (QString line, strLines) {
|
||||||
|
|
|
@ -29,6 +29,9 @@
|
||||||
#ifndef DAEMONMANAGER_H
|
#ifndef DAEMONMANAGER_H
|
||||||
#define DAEMONMANAGER_H
|
#define DAEMONMANAGER_H
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include <QMutex>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
|
@ -78,7 +81,8 @@ private:
|
||||||
|
|
||||||
static DaemonManager * m_instance;
|
static DaemonManager * m_instance;
|
||||||
static QStringList m_clArgs;
|
static QStringList m_clArgs;
|
||||||
QProcess *m_daemon;
|
std::unique_ptr<QProcess> m_daemon;
|
||||||
|
QMutex m_daemonMutex;
|
||||||
bool initialized = false;
|
bool initialized = false;
|
||||||
QString m_monerod;
|
QString m_monerod;
|
||||||
bool m_has_daemon = true;
|
bool m_has_daemon = true;
|
||||||
|
|
Loading…
Reference in a new issue