From 2c0157fbe9b9338f98e66d300664fe3c710eb415 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Mon, 3 Jun 2024 20:09:16 +0100 Subject: cid#1602449 Resource leak MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ide5575adb3346a0ad36a484078dc02ef46a4c043 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168389 Tested-by: Jenkins Reviewed-by: Caolán McNamara --- sw/source/core/doc/docsort.cxx | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'sw') diff --git a/sw/source/core/doc/docsort.cxx b/sw/source/core/doc/docsort.cxx index df5aaf6e5c89..8f5e70d5110d 100644 --- a/sw/source/core/doc/docsort.cxx +++ b/sw/source/core/doc/docsort.cxx @@ -313,7 +313,7 @@ bool SwDoc::SortText(const SwPaM& rPaM, const SwSortOptions& rOpt) } std::optional pRedlPam; - SwUndoRedlineSort* pRedlUndo = nullptr; + std::unique_ptr xRedlUndo; SwUndoSort* pUndoSort = nullptr; // To-Do - add 'SwExtraRedlineTable' also ? @@ -328,7 +328,7 @@ bool SwDoc::SortText(const SwPaM& rPaM, const SwSortOptions& rOpt) { if( bUndo ) { - pRedlUndo = new SwUndoRedlineSort( *pRedlPam,rOpt ); + xRedlUndo.reset(new SwUndoRedlineSort(*pRedlPam, rOpt)); GetIDocumentUndoRedo().DoUndo(false); } // First copy the range @@ -356,8 +356,8 @@ bool SwDoc::SortText(const SwPaM& rPaM, const SwSortOptions& rOpt) if (pCNd) pRedlPam->GetPoint()->SetContent( nCLen ); - if( pRedlUndo ) - pRedlUndo->SetValues( rPaM ); + if (xRedlUndo) + xRedlUndo->SetValues(rPaM); } else { @@ -380,7 +380,7 @@ bool SwDoc::SortText(const SwPaM& rPaM, const SwSortOptions& rOpt) SwNodeOffset nBeg = pStart->GetNodeIndex(); SwNodeRange aRg( aStart, aStart ); - if( bUndo && !pRedlUndo ) + if (bUndo && !xRedlUndo) { pUndoSort = new SwUndoSort(rPaM, rOpt); GetIDocumentUndoRedo().AppendUndo(std::unique_ptr(pUndoSort)); @@ -412,12 +412,13 @@ bool SwDoc::SortText(const SwPaM& rPaM, const SwSortOptions& rOpt) if( pRedlPam ) { - if( pRedlUndo ) + SwUndoRedlineSort* pRedlUndo = xRedlUndo.get(); + if (pRedlUndo) { - pRedlUndo->SetSaveRange( *pRedlPam ); + xRedlUndo->SetSaveRange(*pRedlPam); // UGLY: temp. enable Undo GetIDocumentUndoRedo().DoUndo(true); - GetIDocumentUndoRedo().AppendUndo( std::unique_ptr(pRedlUndo) ); + GetIDocumentUndoRedo().AppendUndo(std::move(xRedlUndo)); GetIDocumentUndoRedo().DoUndo(false); } @@ -437,13 +438,13 @@ bool SwDoc::SortText(const SwPaM& rPaM, const SwSortOptions& rOpt) // the sorted range is inserted getIDocumentRedlineAccess().AppendRedline( new SwRangeRedline( RedlineType::Insert, *pRedlPam ), true); - if( pRedlUndo ) + if (pRedlUndo) { SwNodeIndex aInsEndIdx( pRedlPam->GetMark()->GetNode(), -1 ); SwContentNode *const pContentNode = aInsEndIdx.GetNode().GetContentNode(); pRedlPam->GetMark()->Assign( *pContentNode, pContentNode->Len() ); - pRedlUndo->SetValues( *pRedlPam ); + pRedlUndo->SetValues(*pRedlPam); } pRedlPam.reset(); -- cgit