Browse Source

Reduce designBlock memory leaks.

pull/18/head
Jeff Young 8 months ago
parent
commit
d2305957d8
  1. 4
      eeschema/sch_design_block_utils.cpp
  2. 11
      eeschema/tools/sch_editor_control.cpp
  3. 3
      pcbnew/pcb_design_block_utils.cpp
  4. 26
      pcbnew/tools/pcb_control.cpp

4
eeschema/sch_design_block_utils.cpp

@ -417,6 +417,7 @@ bool SCH_EDIT_FRAME::SaveSelectionToDesignBlock( const LIB_ID& aLibId )
if( !blk->GetSchematicFile().IsEmpty() && !checkOverwriteDbSchematic( this, aLibId ) )
{
delete blk;
return false;
}
@ -456,10 +457,12 @@ bool SCH_EDIT_FRAME::SaveSelectionToDesignBlock( const LIB_ID& aLibId )
// Save a temporary copy of the schematic file, as the plugin is just going to move it
wxString tempFile = wxFileName::CreateTempFileName( "design_block" );
if( !saveSchematicFile( tempSheet, tempFile ) )
{
DisplayErrorMessage( this, _( "Error saving temporary schematic file to create design block." ) );
wxRemoveFile( tempFile );
delete blk;
return false;
}
@ -503,5 +506,6 @@ bool SCH_EDIT_FRAME::SaveSelectionToDesignBlock( const LIB_ID& aLibId )
m_designBlocksPane->RefreshLibs();
m_designBlocksPane->SelectLibId( blk->GetLibId() );
delete blk;
return success;
}

11
eeschema/tools/sch_editor_control.cpp

@ -2994,8 +2994,8 @@ int SCH_EDITOR_CONTROL::PlaceLinkedDesignBlock( const TOOL_EVENT& aEvent )
return 1;
// Get the associated design block
DESIGN_BLOCK* designBlock =
editFrame->GetDesignBlockPane()->GetDesignBlock( group->GetDesignBlockLibId(), true, true );
DESIGN_BLOCK* designBlock = editFrame->GetDesignBlockPane()->GetDesignBlock( group->GetDesignBlockLibId(),
true, true );
if( !designBlock )
{
@ -3011,6 +3011,7 @@ int SCH_EDITOR_CONTROL::PlaceLinkedDesignBlock( const TOOL_EVENT& aEvent )
msg.Printf( _( "Design block %s does not have a schematic file." ),
group->GetDesignBlockLibId().GetUniStringLibId() );
m_frame->GetInfoBar()->ShowMessageFor( msg, 5000, wxICON_WARNING );
delete designBlock;
return 1;
}
@ -3040,8 +3041,8 @@ int SCH_EDITOR_CONTROL::SaveToLinkedDesignBlock( const TOOL_EVENT& aEvent )
return 1;
// Get the associated design block
DESIGN_BLOCK* designBlock =
editFrame->GetDesignBlockPane()->GetDesignBlock( group->GetDesignBlockLibId(), true, true );
DESIGN_BLOCK* designBlock = editFrame->GetDesignBlockPane()->GetDesignBlock( group->GetDesignBlockLibId(),
true, true );
if( !designBlock )
{
@ -3051,6 +3052,8 @@ int SCH_EDITOR_CONTROL::SaveToLinkedDesignBlock( const TOOL_EVENT& aEvent )
return 1;
}
delete designBlock;
editFrame->GetDesignBlockPane()->SelectLibId( group->GetDesignBlockLibId() );
return m_toolMgr->RunAction( SCH_ACTIONS::saveSelectionToDesignBlock ) ? 1 : 0;

3
pcbnew/pcb_design_block_utils.cpp

@ -202,6 +202,7 @@ bool PCB_EDIT_FRAME::SaveBoardToDesignBlock( const LIB_ID& aLibId )
if( !blk->GetBoardFile().IsEmpty() && !checkOverwriteDbLayout( this, aLibId ) )
{
delete blk;
return false;
}
@ -212,6 +213,7 @@ bool PCB_EDIT_FRAME::SaveBoardToDesignBlock( const LIB_ID& aLibId )
{
DisplayErrorMessage( this, _( "Error saving temporary board file to create design block." ) );
wxRemoveFile( tempFile );
delete blk;
return false;
}
@ -235,6 +237,7 @@ bool PCB_EDIT_FRAME::SaveBoardToDesignBlock( const LIB_ID& aLibId )
m_designBlocksPane->RefreshLibs();
m_designBlocksPane->SelectLibId( blk->GetLibId() );
delete blk;
return success;
}

26
pcbnew/tools/pcb_control.cpp

@ -1327,9 +1327,14 @@ int PCB_CONTROL::AppendDesignBlock( const TOOL_EVENT& aEvent )
designBlock = editFrame->GetDesignBlockPane()->GetDesignBlock( editFrame->GetDesignBlockPane()->GetSelectedLibId(),
true, true );
if( !designBlock || designBlock->GetBoardFile().IsEmpty() )
if( !designBlock )
return 1;
wxString designBlockBoardFile = designBlock->GetBoardFile();
delete designBlock;
if( designBlock->GetBoardFile().IsEmpty() )
return 1;
PCB_IO_MGR::PCB_FILE_T pluginType = PCB_IO_MGR::KICAD_SEXP;
IO_RELEASER<PCB_IO> pi( PCB_IO_MGR::PluginFind( pluginType ) );
@ -1346,7 +1351,7 @@ int PCB_CONTROL::AppendDesignBlock( const TOOL_EVENT& aEvent )
do
{
ret = AppendBoard( *pi, designBlock->GetBoardFile() );
ret = AppendBoard( *pi, designBlockBoardFile );
} while( repeatPlacement && ret == 0 );
return ret;
@ -1373,8 +1378,8 @@ int PCB_CONTROL::PlaceLinkedDesignBlock( const TOOL_EVENT& aEvent )
return 1;
// Get the associated design block
DESIGN_BLOCK* designBlock =
editFrame->GetDesignBlockPane()->GetDesignBlock( group->GetDesignBlockLibId(), true, true );
DESIGN_BLOCK* designBlock = editFrame->GetDesignBlockPane()->GetDesignBlock( group->GetDesignBlockLibId(),
true, true );
if( !designBlock )
{
@ -1384,7 +1389,10 @@ int PCB_CONTROL::PlaceLinkedDesignBlock( const TOOL_EVENT& aEvent )
return 1;
}
if( designBlock->GetBoardFile().IsEmpty() )
wxString designBlockBoardFile = designBlock->GetBoardFile();
delete designBlock;
if( designBlockBoardFile.IsEmpty() )
{
wxString msg;
msg.Printf( _( "Design block %s does not have a board file." ),
@ -1400,7 +1408,7 @@ int PCB_CONTROL::PlaceLinkedDesignBlock( const TOOL_EVENT& aEvent )
if( !pi )
return 1;
int ret = AppendBoard( *pi, designBlock->GetBoardFile() );
int ret = AppendBoard( *pi, designBlockBoardFile );
return ret;
}
@ -1426,8 +1434,8 @@ int PCB_CONTROL::SaveToLinkedDesignBlock( const TOOL_EVENT& aEvent )
return 1;
// Get the associated design block
DESIGN_BLOCK* designBlock =
editFrame->GetDesignBlockPane()->GetDesignBlock( group->GetDesignBlockLibId(), true, true );
DESIGN_BLOCK* designBlock = editFrame->GetDesignBlockPane()->GetDesignBlock( group->GetDesignBlockLibId(),
true, true );
if( !designBlock )
{
@ -1437,6 +1445,8 @@ int PCB_CONTROL::SaveToLinkedDesignBlock( const TOOL_EVENT& aEvent )
return 1;
}
delete designBlock;
editFrame->GetDesignBlockPane()->SelectLibId( group->GetDesignBlockLibId() );
return m_toolMgr->RunAction( PCB_ACTIONS::saveSelectionToDesignBlock ) ? 1 : 0;

Loading…
Cancel
Save