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 7520a8b316
commit 4590455ab2
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;
auto cacheIter = cache.find( this );
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();
}
}