From 53d523f2e11839bcbbdc9288b4f71c764d0efd5c Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Thu, 15 Apr 2021 13:33:43 -0400 Subject: autogen: fix race in depfile parsing cmReadGccDepfile() calls cmSystemTools::CollapseFullPath(), which is not thread safe due to internal caching. Serialize calls to cmReadGccDepfile() in autogen to avoid thread safety issues. Fixes: #22014 --- Source/cmQtAutoMocUic.cxx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Source/cmQtAutoMocUic.cxx b/Source/cmQtAutoMocUic.cxx index 535f786..f583162 100644 --- a/Source/cmQtAutoMocUic.cxx +++ b/Source/cmQtAutoMocUic.cxx @@ -564,8 +564,7 @@ private: // -- Generation bool CreateDirectories(); // -- Support for depfiles - static std::vector dependenciesFromDepFile( - const char* filePath); + std::vector dependenciesFromDepFile(const char* filePath); // -- Settings BaseSettingsT BaseConst_; @@ -2066,7 +2065,8 @@ void cmQtAutoMocUicT::JobCompileMocT::Process() " does not exist."); return; } - this->CacheEntry->Moc.Depends = dependenciesFromDepFile(depfile.c_str()); + this->CacheEntry->Moc.Depends = + this->Gen()->dependenciesFromDepFile(depfile.c_str()); } } @@ -2223,12 +2223,12 @@ void cmQtAutoMocUicT::JobDepFilesMergeT::Process() this->MessagePath(this->BaseConst().DepFile.c_str()))); } auto processDepFile = - [](const std::string& mocOutputFile) -> std::vector { + [this](const std::string& mocOutputFile) -> std::vector { std::string f = mocOutputFile + ".d"; if (!cmSystemTools::FileExists(f)) { return {}; } - return dependenciesFromDepFile(f.c_str()); + return this->Gen()->dependenciesFromDepFile(f.c_str()); }; std::vector dependencies = this->initialDependencies(); @@ -2961,6 +2961,7 @@ bool cmQtAutoMocUicT::CreateDirectories() std::vector cmQtAutoMocUicT::dependenciesFromDepFile( const char* filePath) { + std::lock_guard guard(this->CMakeLibMutex_); auto const content = cmReadGccDepfile(filePath); if (!content || content->empty()) { return {}; -- cgit v0.12