From 4590455ab2a4655f09d51c835af28ec80dfaea18 Mon Sep 17 00:00:00 2001 From: Armin Schoisswohl Date: Tue, 5 Mar 2024 19:32:01 +0100 Subject: [PATCH] protect cache lookups in pcbnew/zone by locking the mutex before calling find, fix #17237 --- pcbnew/zone.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pcbnew/zone.cpp b/pcbnew/zone.cpp index e850f9f456..fe642aaa48 100644 --- a/pcbnew/zone.cpp +++ b/pcbnew/zone.cpp @@ -344,14 +344,13 @@ const BOX2I ZONE::GetBoundingBox() const if( const BOARD* board = GetBoard() ) { std::unordered_map& cache = board->m_ZoneBBoxCache; + std::unique_lock cacheLock( const_cast( board )->m_CachesMutex ); auto cacheIter = cache.find( this ); if( cacheIter != cache.end() ) return cacheIter->second; BOX2I bbox = m_Poly->BBox(); - - std::unique_lock cacheLock( const_cast( board )->m_CachesMutex ); cache[ this ] = bbox; return bbox; @@ -365,12 +364,11 @@ void ZONE::CacheBoundingBox() { BOARD* board = GetBoard(); std::unordered_map& cache = board->m_ZoneBBoxCache; - - auto cacheIter = cache.find( this ); + std::unique_lock cacheLock( board->m_CachesMutex ); + auto cacheIter = cache.find( this ); if( cacheIter == cache.end() ) { - std::unique_lock cacheLock( board->m_CachesMutex ); cache[ this ] = m_Poly->BBox(); } }