Commit 9b5161cb authored by David Edmundson's avatar David Edmundson
Browse files

Handle smap read result in the correct thread

We set the context to "this" so we should auto disconnect when the
Processes object is destroyed.
But Qt::DirectConnection means that is run in the runner thread.

It is possible to have a scenario where "this" is active when the
connection is made, but destroyed before we get to this line.

BUG: 428160

But scoping the connect to Processes existing we would have leaked the
worker if Processes got destroyed whilst the worker was running.

CCBUG: 428048
parent e5f0f067
......@@ -550,13 +550,16 @@ bool ProcessesLocal::Private::getIOStatistics(const QString &dir, Process *proce
bool ProcessesLocal::updateProcessInfo( long pid, Process *process)
{
bool success = true;
QString dir = QLatin1String("/proc/") + QString::number(pid) + QLatin1Char('/');
const QString dir = QLatin1String("/proc/") + QString::number(pid) + QLatin1Char('/');
auto runnable = new ReadProcSmapsRunnable{dir};
connect(runnable, &ReadProcSmapsRunnable::finished, this, [this, pid, runnable]() {
Q_EMIT processUpdated(pid, { { Process::VmPSS, runnable->pss() } });
runnable->deleteLater();
}, Qt::DirectConnection);
connect(runnable, &ReadProcSmapsRunnable::finished, this, [this, pid, runnable](qulonglong pss) {
Q_EMIT processUpdated(pid, { { Process::VmPSS, pss } });
});
connect(runnable, &ReadProcSmapsRunnable::finished, runnable, &QObject::deleteLater);
QThreadPool::globalInstance()->start(runnable);
if(!d->readProcStat(dir, process)) success = false;
......
......@@ -24,20 +24,15 @@ void ReadProcSmapsRunnable::run()
return;
}
m_pss = 0LL;
qulonglong pss = 0LL;
auto buffer = QByteArray{1024, '\0'};
while (file.readLine(buffer.data(), buffer.size()) > 0) {
if (buffer.startsWith("Pss:")) {
m_pss += std::stoll(buffer.mid(sizeof("Pss:")).toStdString());
pss += std::stoll(buffer.mid(sizeof("Pss:")).toStdString());
}
}
file.close();
Q_EMIT finished();
}
qlonglong ReadProcSmapsRunnable::pss() const
{
return m_pss;
Q_EMIT finished(pss);
}
......@@ -19,13 +19,10 @@ public:
void run() override;
qlonglong pss() const;
Q_SIGNAL void finished();
Q_SIGNAL void finished(qulonglong pss);
private:
QString m_dir;
qlonglong m_pss = 0;
};
} // namespace KSysGuard
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment