fix race condition related to 3D cache and resolver

The attached patch fixes a segfault due to a race condition.
If a user starts eeschema with an empty sheet and clicks
the 'cvpcb' button, memory is corrupted and the program
segfaults. The issue appears to arise from multiple threads
accessing the 3D cache and resolver. This patch makes
relevant code thread-safe by using a wxCriticalSection.
This commit is contained in:
Cirilo Bernardo 2016-04-10 23:03:39 -04:00 committed by Chris Pavlina
parent 4d77388216
commit 28d49b6589
3 changed files with 13 additions and 0 deletions

View File

@ -32,6 +32,7 @@
#include <wx/datetime.h>
#include <wx/filename.h>
#include <wx/log.h>
#include <wx/thread.h>
#include <wx/utils.h>
#include <wx/stdpaths.h>
@ -51,6 +52,8 @@
#define CACHE_CONFIG_NAME wxT( "cache.cfg" )
#define MASK_3D_CACHE "3D_CACHE"
static wxCriticalSection lock3D_cache;
static bool isSHA1Same( const unsigned char* shaA, const unsigned char* shaB )
{
for( int i = 0; i < 20; ++i )
@ -215,6 +218,7 @@ SCENEGRAPH* S3D_CACHE::load( const wxString& aModelFile, S3D_CACHE_ENTRY** aCach
}
// check cache if file is already loaded
wxCriticalSectionLocker lock( lock3D_cache );
std::map< wxString, S3D_CACHE_ENTRY*, S3D::rsort_wxString >::iterator mi;
mi = m_CacheMap.find( full3Dpath );

View File

@ -23,8 +23,10 @@
#include <common.h>
#include <wx/thread.h>
#include "3d_cache_wrapper.h"
static wxCriticalSection lock3D_wrapper;
CACHE_WRAPPER::CACHE_WRAPPER()
{
@ -40,6 +42,7 @@ CACHE_WRAPPER::~CACHE_WRAPPER()
S3D_CACHE* PROJECT::Get3DCacheManager( bool updateProjDir )
{
wxCriticalSectionLocker lock( lock3D_wrapper );
CACHE_WRAPPER* cw = (CACHE_WRAPPER*) GetElem( ELEM_3DCACHE );
S3D_CACHE* cache = dynamic_cast<S3D_CACHE*>( cw );

View File

@ -29,6 +29,7 @@
#include <sstream>
#include <wx/filename.h>
#include <wx/log.h>
#include <wx/thread.h>
#include <wx/utils.h>
#include <wx/msgdlg.h>
@ -45,6 +46,7 @@
#define MASK_3D_RESOLVER "3D_RESOLVER"
static wxCriticalSection lock3D_resolver;
static bool getHollerith( const std::string& aString, size_t& aIndex, wxString& aResult );
@ -203,6 +205,7 @@ bool S3D_FILENAME_RESOLVER::UpdatePathList( std::vector< S3D_ALIAS >& aPathList
wxString S3D_FILENAME_RESOLVER::ResolvePath( const wxString& aFileName )
{
wxCriticalSectionLocker lock( lock3D_resolver );
if( aFileName.empty() )
return wxEmptyString;
@ -372,6 +375,8 @@ bool S3D_FILENAME_RESOLVER::addPath( const S3D_ALIAS& aPath )
if( aPath.m_alias.empty() || aPath.m_pathvar.empty() )
return false;
wxCriticalSectionLocker lock( lock3D_resolver );
S3D_ALIAS tpath = aPath;
tpath.m_duplicate = false;
@ -735,6 +740,7 @@ wxString S3D_FILENAME_RESOLVER::ShortenPath( const wxString& aFullPathName )
if( m_Paths.empty() )
createPathList();
wxCriticalSectionLocker lock( lock3D_resolver );
std::list< S3D_ALIAS >::const_iterator sL = m_Paths.begin();
std::list< S3D_ALIAS >::const_iterator eL = m_Paths.end();
size_t idx;