diff options
author | Ivan Komissarov <abbapoh@gmail.com> | 2019-12-22 17:28:33 +0200 |
---|---|---|
committer | Ivan Komissarov <ABBAPOH@gmail.com> | 2020-01-10 13:06:22 +0000 |
commit | 4bdd40c12364b11e425ffb9904fd75d591dc7dfb (patch) | |
tree | f3ac1822dde8b14be84505126b3fe24c6c7975ed /src/lib/corelib | |
parent | e1287e747174b9b2dc7824ad7fddfb8996a18820 (diff) | |
download | qbs-4bdd40c12364b11e425ffb9904fd75d591dc7dfb.tar.gz |
Use RAII for memory management of jobs
QMap::keys() method allocates memory for a new list which is not desired
during the object destruction. Also simplifies dtor and make code more
exception-safe
Change-Id: Ib76c2426e74ca79e2ab56b993007985ba8999c85
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src/lib/corelib')
-rw-r--r-- | src/lib/corelib/buildgraph/executor.cpp | 12 | ||||
-rw-r--r-- | src/lib/corelib/buildgraph/executor.h | 1 | ||||
-rw-r--r-- | src/lib/corelib/buildgraph/executorjob.h | 2 |
3 files changed, 7 insertions, 8 deletions
diff --git a/src/lib/corelib/buildgraph/executor.cpp b/src/lib/corelib/buildgraph/executor.cpp index 6e2e7a556..377222d21 100644 --- a/src/lib/corelib/buildgraph/executor.cpp +++ b/src/lib/corelib/buildgraph/executor.cpp @@ -102,12 +102,8 @@ Executor::Executor(Logger logger, QObject *parent) Executor::~Executor() { - // jobs must be destroyed before deleting the shared scan result cache - for (ExecutorJob *job : qAsConst(m_availableJobs)) - delete job; - const auto processingJobs = m_processingJobs.keys(); - for (ExecutorJob *job : processingJobs) - delete job; + // jobs must be destroyed before deleting the m_inputArtifactScanContext + m_allJobs.clear(); delete m_inputArtifactScanContext; delete m_productInstaller; } @@ -769,9 +765,11 @@ void Executor::addExecutorJobs() { const int count = m_buildOptions.maxJobCount(); qCDebug(lcExec) << "preparing executor for" << count << "jobs in parallel"; + m_allJobs.reserve(count); m_availableJobs.reserve(count); for (int i = 1; i <= count; i++) { - const auto job = new ExecutorJob(m_logger, this); + m_allJobs.push_back(std::make_unique<ExecutorJob>(m_logger)); + const auto job = m_allJobs.back().get(); job->setMainThreadScriptEngine(m_evalContext->engine()); job->setObjectName(QStringLiteral("J%1").arg(i)); job->setDryRun(m_buildOptions.dryRun()); diff --git a/src/lib/corelib/buildgraph/executor.h b/src/lib/corelib/buildgraph/executor.h index 460f46959..cc879e125 100644 --- a/src/lib/corelib/buildgraph/executor.h +++ b/src/lib/corelib/buildgraph/executor.h @@ -166,6 +166,7 @@ private: BuildOptions m_buildOptions; Logger m_logger; ProgressObserver *m_progressObserver; + std::vector<std::unique_ptr<ExecutorJob>> m_allJobs; QList<ExecutorJob*> m_availableJobs; ExecutorState m_state; TopLevelProjectPtr m_project; diff --git a/src/lib/corelib/buildgraph/executorjob.h b/src/lib/corelib/buildgraph/executorjob.h index bc8954072..1f8f0cd73 100644 --- a/src/lib/corelib/buildgraph/executorjob.h +++ b/src/lib/corelib/buildgraph/executorjob.h @@ -65,7 +65,7 @@ class ExecutorJob : public QObject { Q_OBJECT public: - ExecutorJob(const Logger &logger, QObject *parent); + explicit ExecutorJob(const Logger &logger, QObject *parent = nullptr); ~ExecutorJob() override; void setMainThreadScriptEngine(ScriptEngine *engine); |