Browse Source

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.
pull/12/head
Cirilo Bernardo 10 years ago
committed by Chris Pavlina
parent
commit
28d49b6589
  1. 4
      3d-viewer/3d_cache/3d_cache.cpp
  2. 3
      3d-viewer/3d_cache/3d_cache_wrapper.cpp
  3. 6
      3d-viewer/3d_cache/3d_filename_resolver.cpp

4
3d-viewer/3d_cache/3d_cache.cpp

@ -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 );

3
3d-viewer/3d_cache/3d_cache_wrapper.cpp

@ -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 );

6
3d-viewer/3d_cache/3d_filename_resolver.cpp

@ -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;

Loading…
Cancel
Save