Use a unique_ptr for ensuring clean up when reading excellon files

This commit is contained in:
Marek Roszko 2021-05-01 14:23:01 -04:00
parent 6b03b26364
commit e955f83c51
1 changed files with 5 additions and 3 deletions

View File

@ -252,19 +252,21 @@ bool GERBVIEW_FRAME::Read_EXCELLON_File( const wxString& aFullFileName )
if( gerber_layer )
Erase_Current_DrawLayer( false );
EXCELLON_IMAGE* drill_layer = new EXCELLON_IMAGE( layerId );
std::unique_ptr<EXCELLON_IMAGE> drill_layer_uptr = std::make_unique<EXCELLON_IMAGE>( layerId );
// Read the Excellon drill file:
bool success = drill_layer->LoadFile( aFullFileName );
bool success = drill_layer_uptr->LoadFile( aFullFileName );
if( !success )
{
delete drill_layer;
drill_layer_uptr.reset();
msg.Printf( _( "File %s not found." ), aFullFileName );
ShowInfoBarError( msg );
return false;
}
EXCELLON_IMAGE* drill_layer = drill_layer_uptr.release();
layerId = images->AddGbrImage( drill_layer, layerId );
if( layerId < 0 )