protect cache lookups in pcbnew/zone by locking the mutex before calling find, fix #17237

This commit is contained in:
Armin Schoisswohl 2024-03-05 19:32:01 +01:00 committed by Jeff Young
parent 1b5e18d95f
commit d1867bd728
1 changed files with 3 additions and 5 deletions

View File

@ -344,14 +344,13 @@ const BOX2I ZONE::GetBoundingBox() const
if( const BOARD* board = GetBoard() )
{
std::unordered_map<const ZONE*, BOX2I>& cache = board->m_ZoneBBoxCache;
std::unique_lock<std::mutex> cacheLock( const_cast<BOARD*>( board )->m_CachesMutex );
auto cacheIter = cache.find( this );
if( cacheIter != cache.end() )
return cacheIter->second;
BOX2I bbox = m_Poly->BBox();
std::unique_lock<std::mutex> cacheLock( const_cast<BOARD*>( board )->m_CachesMutex );
cache[ this ] = bbox;
return bbox;
@ -365,12 +364,11 @@ void ZONE::CacheBoundingBox()
{
BOARD* board = GetBoard();
std::unordered_map<const ZONE*, BOX2I>& cache = board->m_ZoneBBoxCache;
std::unique_lock<std::mutex> cacheLock( board->m_CachesMutex );
auto cacheIter = cache.find( this );
if( cacheIter == cache.end() )
{
std::unique_lock<std::mutex> cacheLock( board->m_CachesMutex );
cache[ this ] = m_Poly->BBox();
}
}