From e8cf4f0724d00cc8b010edb6a26ced08c2add076 Mon Sep 17 00:00:00 2001 From: Wayne Stambaugh Date: Sat, 11 Feb 2017 20:14:45 -0500 Subject: [PATCH] Fix bug in legacy schematic I/O plugin. Move adding LIB_PART to library until the part is fully parse. The problem was unique_ptr was cleaning up the part when an exception was thrown during parsing causing a double free when the cache was deleted. Add missing try/catch block when loading the cache library during an append schematic operation. Fixes lp:1663869 https://bugs.launchpad.net/kicad/+bug/1663869 --- eeschema/class_library.cpp | 3 ++- eeschema/files-io.cpp | 11 +++++++++-- eeschema/sch_legacy_plugin.cpp | 10 ++++++---- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/eeschema/class_library.cpp b/eeschema/class_library.cpp index 2bde3860f9..9c8fa7e5c4 100644 --- a/eeschema/class_library.cpp +++ b/eeschema/class_library.cpp @@ -548,7 +548,8 @@ const wxString PART_LIBS::CacheName( const wxString& aFullProjectFilename ) } -void PART_LIBS::LoadAllLibraries( PROJECT* aProject, bool aShowProgress ) throw( IO_ERROR, boost::bad_pointer ) +void PART_LIBS::LoadAllLibraries( PROJECT* aProject, bool aShowProgress ) + throw( IO_ERROR, boost::bad_pointer ) { wxString filename; wxString libs_not_found; diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index 9dad886b02..0afbd5504a 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -397,8 +397,15 @@ bool SCH_EDIT_FRAME::AppendOneEEProject() { PART_LIBS* libs = Prj().SchLibs(); - if( PART_LIB* lib = libs->AddLibrary( cache_name ) ) - lib->SetCache(); + try + { + if( PART_LIB* lib = libs->AddLibrary( cache_name ) ) + lib->SetCache(); + } + catch( const IO_ERROR& ioe ) + { + DisplayError( this, ioe.What() ); + } } wxLogDebug( wxT( "Importing schematic " ) + fullFileName ); diff --git a/eeschema/sch_legacy_plugin.cpp b/eeschema/sch_legacy_plugin.cpp index f6ffa137f3..d05d5a0d81 100644 --- a/eeschema/sch_legacy_plugin.cpp +++ b/eeschema/sch_legacy_plugin.cpp @@ -2382,10 +2382,6 @@ LIB_PART* SCH_LEGACY_PLUGIN_CACHE::loadPart( FILE_LINE_READER& aReader ) value.SetVisible( false ); } - // Add the root alias to the alias list. - part->m_aliases.push_back( new LIB_ALIAS( name, part.get() ) ); - m_aliases[ part->GetName() ] = part->GetAlias( name ); - LIB_FIELD& reference = part->GetReferenceField(); if( prefix == "~" ) @@ -2450,7 +2446,13 @@ LIB_PART* SCH_LEGACY_PLUGIN_CACHE::loadPart( FILE_LINE_READER& aReader ) else if( strCompare( "$FPLIST", line, &line ) ) // Footprint filter list loadFootprintFilters( part, aReader ); else if( strCompare( "ENDDEF", line, &line ) ) // End of part description + { + // Add the root alias to the alias list. + part->m_aliases.push_back( new LIB_ALIAS( name, part.get() ) ); + m_aliases[ part->GetName() ] = part->GetAlias( name ); + return part.release(); + } line = aReader.ReadLine(); }