Fix memory leak and re-code non-memory-leak so Coverity can understand it.

This commit is contained in:
Jeff Young 2022-11-30 12:18:24 +00:00
parent e39c0b20ea
commit 9fa8b9e49f
1 changed files with 7 additions and 6 deletions

View File

@ -180,17 +180,18 @@ void PCB_TOOL_BASE::doInteractiveItemPlacement( const TOOL_EVENT& aTool,
} }
else else
{ {
auto oldFlags = newItem->GetFlags(); BOARD_ITEM* newBoardItem = newItem.release();
newItem->ClearFlags(); EDA_ITEM_FLAGS oldFlags = newBoardItem->GetFlags();
if( !aPlacer->PlaceItem( newItem.get(), commit ) ) newBoardItem->ClearFlags();
if( !aPlacer->PlaceItem( newBoardItem, commit ) )
{ {
newItem->SetFlags( oldFlags ); newBoardItem->SetFlags( oldFlags );
continue; continue;
} }
preview.Clear(); preview.Clear();
newItem.release();
commit.Push( aCommitMessage ); commit.Push( aCommitMessage );
controls()->CaptureCursor( false ); controls()->CaptureCursor( false );
@ -244,7 +245,7 @@ void PCB_TOOL_BASE::doInteractiveItemPlacement( const TOOL_EVENT& aTool,
else if( evt->IsAction( &ACTIONS::refreshPreview ) ) else if( evt->IsAction( &ACTIONS::refreshPreview ) )
{ {
preview.Clear(); preview.Clear();
newItem.release(); newItem.reset();
makeNewItem( cursorPos ); makeNewItem( cursorPos );
aPlacer->SnapItem( newItem.get() ); aPlacer->SnapItem( newItem.get() );