From 9fa8b9e49f47c2b3db40ddc99616ce15183d4afb Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 30 Nov 2022 12:18:24 +0000 Subject: [PATCH] Fix memory leak and re-code non-memory-leak so Coverity can understand it. --- pcbnew/tools/pcb_tool_base.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pcbnew/tools/pcb_tool_base.cpp b/pcbnew/tools/pcb_tool_base.cpp index 2f5734ecf5..658a4dd726 100644 --- a/pcbnew/tools/pcb_tool_base.cpp +++ b/pcbnew/tools/pcb_tool_base.cpp @@ -180,17 +180,18 @@ void PCB_TOOL_BASE::doInteractiveItemPlacement( const TOOL_EVENT& aTool, } else { - auto oldFlags = newItem->GetFlags(); - newItem->ClearFlags(); + BOARD_ITEM* newBoardItem = newItem.release(); + 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; } preview.Clear(); - newItem.release(); commit.Push( aCommitMessage ); controls()->CaptureCursor( false ); @@ -244,7 +245,7 @@ void PCB_TOOL_BASE::doInteractiveItemPlacement( const TOOL_EVENT& aTool, else if( evt->IsAction( &ACTIONS::refreshPreview ) ) { preview.Clear(); - newItem.release(); + newItem.reset(); makeNewItem( cursorPos ); aPlacer->SnapItem( newItem.get() );