summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-10-26 12:06:27 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-10-26 13:30:49 +0200
commit4054dff516367b332b7e3ce6fa91a452bf690571 (patch)
tree74ce35623e84933e4da9b134855ac1c74c4bce1d /sw
parentc0cc59adca23580864a2e5cdadf66212246cbfcc (diff)
use unique_ptr when Clone()'ing PoolItems
and fix a handful of small leaks in the process Change-Id: I876e12ff5305f9dda84532d4182fb91657d6fa0c Reviewed-on: https://gerrit.libreoffice.org/62389 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sw')
-rw-r--r--sw/source/core/doc/docfmt.cxx3
-rw-r--r--sw/source/core/doc/docnew.cxx9
-rw-r--r--sw/source/core/docnode/ndtbl.cxx3
-rw-r--r--sw/source/core/draw/drawdoc.cxx3
-rw-r--r--sw/source/core/tox/ToxTextGenerator.cxx2
-rw-r--r--sw/source/core/undo/SwUndoPageDesc.cxx62
-rw-r--r--sw/source/core/undo/unattr.cxx6
-rw-r--r--sw/source/core/unocore/SwXTextDefaults.cxx14
-rw-r--r--sw/source/core/unocore/unoframe.cxx8
-rw-r--r--sw/source/core/unocore/unosett.cxx9
-rw-r--r--sw/source/filter/html/htmldrawreader.cxx3
-rw-r--r--sw/source/filter/html/htmldrawwriter.cxx3
-rw-r--r--sw/source/filter/ww8/wrtw8esh.cxx6
-rw-r--r--sw/source/filter/ww8/ww8graf.cxx6
-rw-r--r--sw/source/filter/ww8/ww8par6.cxx18
-rw-r--r--sw/source/filter/xml/xmlimpit.cxx16
-rw-r--r--sw/source/filter/xml/xmlitemi.cxx2
-rw-r--r--sw/source/ui/chrdlg/numpara.cxx8
-rw-r--r--sw/source/uibase/sidebar/PageOrientationControl.cxx12
19 files changed, 71 insertions, 122 deletions
diff --git a/sw/source/core/doc/docfmt.cxx b/sw/source/core/doc/docfmt.cxx
index b2f0a2de4add..ccebf3bfac0b 100644
--- a/sw/source/core/doc/docfmt.cxx
+++ b/sw/source/core/doc/docfmt.cxx
@@ -601,10 +601,9 @@ void SwDoc::SetDefault( const SfxItemSet& rSet )
0 != (nEdtWhich = pSdrPool->GetWhich( nSlotId )) &&
nSlotId != nEdtWhich )
{
- SfxPoolItem* pCpy = pItem->Clone();
+ std::unique_ptr<SfxPoolItem> pCpy(pItem->Clone());
pCpy->SetWhich( nEdtWhich );
pSdrPool->SetPoolDefaultItem( *pCpy );
- delete pCpy;
}
}
diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx
index efd6218731a4..d3e9b548905e 100644
--- a/sw/source/core/doc/docnew.cxx
+++ b/sw/source/core/doc/docnew.cxx
@@ -1180,7 +1180,7 @@ SwNodeIndex SwDoc::AppendDoc(const SwDoc& rSource, sal_uInt16 const nStartPageNu
// we just need to set the new page description and reset numbering
// this keeps all other settings as in the pasted document
if ( nStartPageNumber || pTargetPageDesc ) {
- SfxPoolItem *pNewItem;
+ std::unique_ptr<SfxPoolItem> pNewItem;
SwTextNode *aTextNd = nullptr;
SwFormat *pFormat = nullptr;
@@ -1192,12 +1192,12 @@ SwNodeIndex SwDoc::AppendDoc(const SwDoc& rSource, sal_uInt16 const nStartPageNu
if ( node.IsTextNode() ) {
// every document contains at least one text node!
aTextNd = node.GetTextNode();
- pNewItem = aTextNd->GetAttr( RES_PAGEDESC ).Clone();
+ pNewItem.reset(aTextNd->GetAttr( RES_PAGEDESC ).Clone());
break;
}
else if ( node.IsTableNode() ) {
pFormat = node.GetTableNode()->GetTable().GetFrameFormat();
- pNewItem = pFormat->GetFormatAttr( RES_PAGEDESC ).Clone();
+ pNewItem.reset(pFormat->GetFormatAttr( RES_PAGEDESC ).Clone());
break;
}
}
@@ -1207,7 +1207,7 @@ SwNodeIndex SwDoc::AppendDoc(const SwDoc& rSource, sal_uInt16 const nStartPageNu
SAL_INFO( "sw.docappend", "Idx Fix " << CNTNT_IDX( aFixupIdx ) );
#endif
// just update the original instead of overwriting
- SwFormatPageDesc *aDesc = static_cast< SwFormatPageDesc* >( pNewItem );
+ SwFormatPageDesc *aDesc = static_cast< SwFormatPageDesc* >( pNewItem.get() );
#ifdef DBG_UTIL
if ( aDesc->GetPageDesc() )
SAL_INFO( "sw.docappend", "PD Update " << aDesc->GetPageDesc()->GetName() );
@@ -1222,7 +1222,6 @@ else
aTextNd->SetAttr( *aDesc );
else
pFormat->SetFormatAttr( *aDesc );
- delete pNewItem;
#ifdef DBG_UTIL
SAL_INFO( "sw.docappend", "Idx " << CNTNT_IDX( aDelIdx ) );
diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx
index d94e62c75200..daba8542ef05 100644
--- a/sw/source/core/docnode/ndtbl.cxx
+++ b/sw/source/core/docnode/ndtbl.cxx
@@ -4215,11 +4215,10 @@ void SwDoc::ClearLineNumAttrs( SwPosition const & rPos )
aRegH.RegisterInModify( pTextNode , *pTextNode );
if ( pUndo )
pUndo->AddNode( *pTextNode );
- SfxStringItem * pNewItem = static_cast<SfxStringItem*>(pFormatItem->Clone());
+ std::unique_ptr<SfxStringItem> pNewItem(static_cast<SfxStringItem*>(pFormatItem->Clone()));
pNewItem->SetValue(OUString());
rSet.Put( *pNewItem );
pTextNode->SetAttr( rSet );
- delete pNewItem;
}
}
}
diff --git a/sw/source/core/draw/drawdoc.cxx b/sw/source/core/draw/drawdoc.cxx
index 397faf27cb90..464fa5b157a0 100644
--- a/sw/source/core/draw/drawdoc.cxx
+++ b/sw/source/core/draw/drawdoc.cxx
@@ -77,10 +77,9 @@ SwDrawModel::SwDrawModel(SwDoc *const pDoc)
0 != (nEdtWhich = pSdrPool->GetWhich( nSlotId )) &&
nSlotId != nEdtWhich )
{
- SfxPoolItem* pCpy = pItem->Clone();
+ std::unique_ptr<SfxPoolItem> pCpy(pItem->Clone());
pCpy->SetWhich( nEdtWhich );
pSdrPool->SetPoolDefaultItem( *pCpy );
- delete pCpy;
}
}
diff --git a/sw/source/core/tox/ToxTextGenerator.cxx b/sw/source/core/tox/ToxTextGenerator.cxx
index 7ec515e7aae4..4734b1e97bde 100644
--- a/sw/source/core/tox/ToxTextGenerator.cxx
+++ b/sw/source/core/tox/ToxTextGenerator.cxx
@@ -283,7 +283,7 @@ ToxTextGenerator::CollectAttributesForTox(const SwTextAttr& hint, SwAttrPool& po
pItem->Which() == RES_CHRATR_POSTURE ||
pItem->Which() == RES_CHRATR_CJK_POSTURE ||
pItem->Which() == RES_CHRATR_CTL_POSTURE) {
- SfxPoolItem* clonedItem = pItem->Clone();
+ std::unique_ptr<SfxPoolItem> clonedItem(pItem->Clone());
retval->Put(*clonedItem);
}
if (aIter.IsAtEnd()) {
diff --git a/sw/source/core/undo/SwUndoPageDesc.cxx b/sw/source/core/undo/SwUndoPageDesc.cxx
index 0178cd0ff5bd..01bebbe2de95 100644
--- a/sw/source/core/undo/SwUndoPageDesc.cxx
+++ b/sw/source/core/undo/SwUndoPageDesc.cxx
@@ -135,48 +135,42 @@ void SwUndoPageDesc::ExchangeContentNodes( SwPageDesc& rSource, SwPageDesc &rDes
// from now on this descriptor is responsible for the content nodes!
const SfxPoolItem* pItem;
rDest.GetMaster().GetAttrSet().GetItemState( RES_HEADER, false, &pItem );
- SfxPoolItem *pNewItem = pItem->Clone();
- SwFrameFormat* pNewFormat = static_cast<SwFormatHeader*>(pNewItem)->GetHeaderFormat();
+ std::unique_ptr<SfxPoolItem> pNewItem(pItem->Clone());
+ SwFrameFormat* pNewFormat = static_cast<SwFormatHeader*>(pNewItem.get())->GetHeaderFormat();
pNewFormat->SetFormatAttr( rSourceHead.GetHeaderFormat()->GetContent() );
- delete pNewItem;
// Let the source page description point to zero node position,
// it loses the responsible and can be destroyed without removing the content nodes.
rSource.GetMaster().GetAttrSet().GetItemState( RES_HEADER, false, &pItem );
- pNewItem = pItem->Clone();
- pNewFormat = static_cast<SwFormatHeader*>(pNewItem)->GetHeaderFormat();
+ pNewItem.reset(pItem->Clone());
+ pNewFormat = static_cast<SwFormatHeader*>(pNewItem.get())->GetHeaderFormat();
pNewFormat->SetFormatAttr( SwFormatContent() );
- delete pNewItem;
if( !rDest.IsHeaderShared() )
{
// Same procedure for unshared header..
const SwFormatHeader& rSourceLeftHead = rSource.GetLeft().GetHeader();
rDest.GetLeft().GetAttrSet().GetItemState( RES_HEADER, false, &pItem );
- pNewItem = pItem->Clone();
- pNewFormat = static_cast<SwFormatHeader*>(pNewItem)->GetHeaderFormat();
+ pNewItem.reset(pItem->Clone());
+ pNewFormat = static_cast<SwFormatHeader*>(pNewItem.get())->GetHeaderFormat();
pNewFormat->SetFormatAttr( rSourceLeftHead.GetHeaderFormat()->GetContent() );
- delete pNewItem;
rSource.GetLeft().GetAttrSet().GetItemState( RES_HEADER, false, &pItem );
- pNewItem = pItem->Clone();
- pNewFormat = static_cast<SwFormatHeader*>(pNewItem)->GetHeaderFormat();
+ pNewItem.reset(pItem->Clone());
+ pNewFormat = static_cast<SwFormatHeader*>(pNewItem.get())->GetHeaderFormat();
pNewFormat->SetFormatAttr( SwFormatContent() );
- delete pNewItem;
}
if (!rDest.IsFirstShared())
{
// Same procedure for unshared header..
const SwFormatHeader& rSourceFirstMasterHead = rSource.GetFirstMaster().GetHeader();
rDest.GetFirstMaster().GetAttrSet().GetItemState( RES_HEADER, false, &pItem );
- pNewItem = pItem->Clone();
- pNewFormat = static_cast<SwFormatHeader*>(pNewItem)->GetHeaderFormat();
+ pNewItem.reset(pItem->Clone());
+ pNewFormat = static_cast<SwFormatHeader*>(pNewItem.get())->GetHeaderFormat();
pNewFormat->SetFormatAttr( rSourceFirstMasterHead.GetHeaderFormat()->GetContent() );
- delete pNewItem;
rSource.GetFirstMaster().GetAttrSet().GetItemState( RES_HEADER, false, &pItem );
- pNewItem = pItem->Clone();
- pNewFormat = static_cast<SwFormatHeader*>(pNewItem)->GetHeaderFormat();
+ pNewItem.reset(pItem->Clone());
+ pNewFormat = static_cast<SwFormatHeader*>(pNewItem.get())->GetHeaderFormat();
pNewFormat->SetFormatAttr( SwFormatContent() );
- delete pNewItem;
}
}
// Same procedure for footers...
@@ -187,47 +181,39 @@ void SwUndoPageDesc::ExchangeContentNodes( SwPageDesc& rSource, SwPageDesc &rDes
const SfxPoolItem* pItem;
rDest.GetMaster().GetAttrSet().GetItemState( RES_FOOTER, false, &pItem );
- SfxPoolItem *pNewItem = pItem->Clone();
- SwFrameFormat *pNewFormat = static_cast<SwFormatFooter*>(pNewItem)->GetFooterFormat();
+ std::unique_ptr<SfxPoolItem> pNewItem(pItem->Clone());
+ SwFrameFormat *pNewFormat = static_cast<SwFormatFooter*>(pNewItem.get())->GetFooterFormat();
pNewFormat->SetFormatAttr( rSourceFoot.GetFooterFormat()->GetContent() );
- delete pNewItem;
rSource.GetMaster().GetAttrSet().GetItemState( RES_FOOTER, false, &pItem );
- pNewItem = pItem->Clone();
- pNewFormat = static_cast<SwFormatFooter*>(pNewItem)->GetFooterFormat();
+ pNewItem.reset(pItem->Clone());
+ pNewFormat = static_cast<SwFormatFooter*>(pNewItem.get())->GetFooterFormat();
pNewFormat->SetFormatAttr( SwFormatContent() );
- delete pNewItem;
if( !rDest.IsFooterShared() )
{
const SwFormatFooter& rSourceLeftFoot = rSource.GetLeft().GetFooter();
rDest.GetLeft().GetAttrSet().GetItemState( RES_FOOTER, false, &pItem );
- pNewItem = pItem->Clone();
- pNewFormat = static_cast<SwFormatFooter*>(pNewItem)->GetFooterFormat();
+ pNewItem.reset(pItem->Clone());
+ pNewFormat = static_cast<SwFormatFooter*>(pNewItem.get())->GetFooterFormat();
pNewFormat->SetFormatAttr( rSourceLeftFoot.GetFooterFormat()->GetContent() );
- delete pNewItem;
rSource.GetLeft().GetAttrSet().GetItemState( RES_FOOTER, false, &pItem );
- pNewItem = pItem->Clone();
- pNewFormat = static_cast<SwFormatFooter*>(pNewItem)->GetFooterFormat();
+ pNewItem.reset(pItem->Clone());
+ pNewFormat = static_cast<SwFormatFooter*>(pNewItem.get())->GetFooterFormat();
pNewFormat->SetFormatAttr( SwFormatContent() );
- delete pNewItem;
}
if (rDest.IsFirstShared())
return;
const SwFormatFooter& rSourceFirstMasterFoot = rSource.GetFirstMaster().GetFooter();
rDest.GetFirstMaster().GetAttrSet().GetItemState( RES_FOOTER, false, &pItem );
- pNewItem = pItem->Clone();
- pNewFormat = static_cast<SwFormatFooter*>(pNewItem)->GetFooterFormat();
+ pNewItem.reset(pItem->Clone());
+ pNewFormat = static_cast<SwFormatFooter*>(pNewItem.get())->GetFooterFormat();
pNewFormat->SetFormatAttr( rSourceFirstMasterFoot.GetFooterFormat()->GetContent() );
- delete pNewItem;
rSource.GetFirstMaster().GetAttrSet().GetItemState( RES_FOOTER, false, &pItem );
- pNewItem = pItem->Clone();
- pNewFormat = static_cast<SwFormatFooter*>(pNewItem)->GetFooterFormat();
+ pNewItem.reset(pItem->Clone());
+ pNewFormat = static_cast<SwFormatFooter*>(pNewItem.get())->GetFooterFormat();
pNewFormat->SetFormatAttr( SwFormatContent() );
- delete pNewItem;
-
-
}
void SwUndoPageDesc::UndoImpl(::sw::UndoRedoContext &)
diff --git a/sw/source/core/undo/unattr.cxx b/sw/source/core/undo/unattr.cxx
index d3b88108a725..474a8b72429a 100644
--- a/sw/source/core/undo/unattr.cxx
+++ b/sw/source/core/undo/unattr.cxx
@@ -865,10 +865,10 @@ void SwUndoDefaultAttr::UndoImpl(::sw::UndoRedoContext & rContext)
}
if (m_pTabStop)
{
- SvxTabStopItem* pOld = static_cast<SvxTabStopItem*>(
- rDoc.GetDefault( RES_PARATR_TABSTOP ).Clone() );
+ std::unique_ptr<SvxTabStopItem> pOld(static_cast<SvxTabStopItem*>(
+ rDoc.GetDefault( RES_PARATR_TABSTOP ).Clone() ));
rDoc.SetDefault( *m_pTabStop );
- m_pTabStop.reset( pOld );
+ m_pTabStop = std::move( pOld );
}
}
diff --git a/sw/source/core/unocore/SwXTextDefaults.cxx b/sw/source/core/unocore/SwXTextDefaults.cxx
index f9af14cb786c..82ef158a418d 100644
--- a/sw/source/core/unocore/SwXTextDefaults.cxx
+++ b/sw/source/core/unocore/SwXTextDefaults.cxx
@@ -88,8 +88,8 @@ void SAL_CALL SwXTextDefaults::setPropertyValue( const OUString& rPropertyName,
SwStyleNameMapper::FillUIName(uStyle, sStyle, SwGetPoolIdFromName::ChrFmt );
SwDocStyleSheet* pStyle =
static_cast<SwDocStyleSheet*>(m_pDoc->GetDocShell()->GetStyleSheetPool()->Find(sStyle, SfxStyleFamily::Char));
- SwFormatDrop* pDrop = nullptr;
- SwFormatCharFormat *pCharFormat = nullptr;
+ std::unique_ptr<SwFormatDrop> pDrop;
+ std::unique_ptr<SwFormatCharFormat> pCharFormat;
if(!pStyle)
throw lang::IllegalArgumentException();
@@ -99,26 +99,22 @@ void SAL_CALL SwXTextDefaults::setPropertyValue( const OUString& rPropertyName,
if (RES_PARATR_DROP == pMap->nWID)
{
- pDrop = static_cast<SwFormatDrop*>(rItem.Clone()); // because rItem is const...
+ pDrop.reset(static_cast<SwFormatDrop*>(rItem.Clone())); // because rItem is const...
pDrop->SetCharFormat(xStyle->GetCharFormat());
m_pDoc->SetDefault(*pDrop);
}
else // RES_TXTATR_CHARFMT == pMap->nWID
{
- pCharFormat = static_cast<SwFormatCharFormat*>(rItem.Clone()); // because rItem is const...
+ pCharFormat.reset(static_cast<SwFormatCharFormat*>(rItem.Clone())); // because rItem is const...
pCharFormat->SetCharFormat(xStyle->GetCharFormat());
m_pDoc->SetDefault(*pCharFormat);
}
-
- delete pDrop;
- delete pCharFormat;
}
else
{
- SfxPoolItem * pNewItem = rItem.Clone();
+ std::unique_ptr<SfxPoolItem> pNewItem(rItem.Clone());
pNewItem->PutValue( aValue, pMap->nMemberId);
m_pDoc->SetDefault(*pNewItem);
- delete pNewItem;
}
}
diff --git a/sw/source/core/unocore/unoframe.cxx b/sw/source/core/unocore/unoframe.cxx
index 0c04513751a4..dca356d6ad8d 100644
--- a/sw/source/core/unocore/unoframe.cxx
+++ b/sw/source/core/unocore/unoframe.cxx
@@ -1104,10 +1104,9 @@ bool SwGraphicProperties_Impl::AnyToItemSet(
sal_uInt8 nMId = RES_GRFATR_CROPGRF == nIDs[nIndex] ? CONVERT_TWIPS : 0;
if(GetProperty(nIDs[nIndex], nMId, pAny ))
{
- SfxPoolItem* pItem = ::GetDfltAttr( nIDs[nIndex] )->Clone();
+ std::unique_ptr<SfxPoolItem> pItem(::GetDfltAttr( nIDs[nIndex] )->Clone());
bRet &= pItem->PutValue(*pAny, nMId );
rGrSet.Put(*pItem);
- delete pItem;
}
}
@@ -2705,12 +2704,12 @@ void SwXFrame::attachToRange(const uno::Reference< text::XTextRange > & xTextRan
UnoActionContext aCont(pDoc);
if(m_pCopySource)
{
- SwFormatAnchor* pAnchorItem = nullptr;
+ std::unique_ptr<SwFormatAnchor> pAnchorItem;
// the frame is inserted bound to page
// to prevent conflicts if the to-be-anchored position is part of the to-be-copied text
if (eAnchorId != RndStdIds::FLY_AT_PAGE)
{
- pAnchorItem = static_cast<SwFormatAnchor*>(aFrameSet.Get(RES_ANCHOR).Clone());
+ pAnchorItem.reset(static_cast<SwFormatAnchor*>(aFrameSet.Get(RES_ANCHOR).Clone()));
aFrameSet.Put( SwFormatAnchor( RndStdIds::FLY_AT_PAGE, 1 ));
}
@@ -2726,7 +2725,6 @@ void SwXFrame::attachToRange(const uno::Reference< text::XTextRange > & xTextRan
SfxItemSet aAnchorSet( pDoc->GetAttrPool(), svl::Items<RES_ANCHOR, RES_ANCHOR>{} );
aAnchorSet.Put( *pAnchorItem );
pDoc->SetFlyFrameAttr( *pFormat, aAnchorSet );
- delete pAnchorItem;
}
m_pCopySource.reset();
}
diff --git a/sw/source/core/unocore/unosett.cxx b/sw/source/core/unocore/unosett.cxx
index 585881f14b5d..3a72361cdc49 100644
--- a/sw/source/core/unocore/unosett.cxx
+++ b/sw/source/core/unocore/unosett.cxx
@@ -1613,7 +1613,7 @@ void SwXNumberingRules::SetPropertiesToNumFormat(
{
SvxBrushItem* pSetBrush = nullptr;
Size* pSetSize = nullptr;
- SwFormatVertOrient* pSetVOrient = nullptr;
+ std::unique_ptr<SwFormatVertOrient> pSetVOrient;
bool bCharStyleNameSet = false;
for(size_t i = 0; i < SAL_N_ELEMENTS( aNumPropertyNames ) && !bExcept && !bWrongArg; ++i)
@@ -1983,9 +1983,9 @@ void SwXNumberingRules::SetPropertiesToNumFormat(
if(!pSetVOrient)
{
if(aFormat.GetGraphicOrientation())
- pSetVOrient = static_cast<SwFormatVertOrient*>(aFormat.GetGraphicOrientation()->Clone());
+ pSetVOrient.reset( static_cast<SwFormatVertOrient*>(aFormat.GetGraphicOrientation()->Clone()) );
else
- pSetVOrient = new SwFormatVertOrient;
+ pSetVOrient.reset(new SwFormatVertOrient);
}
pSetVOrient->PutValue(pProp->Value, MID_VERTORIENT_ORIENT);
}
@@ -2041,7 +2041,7 @@ void SwXNumberingRules::SetPropertiesToNumFormat(
if(pSetBrush)
{
if(!pSetVOrient && aFormat.GetGraphicOrientation())
- pSetVOrient = new SwFormatVertOrient(*aFormat.GetGraphicOrientation());
+ pSetVOrient.reset( new SwFormatVertOrient(*aFormat.GetGraphicOrientation()) );
if(!pSetSize)
{
@@ -2069,7 +2069,6 @@ void SwXNumberingRules::SetPropertiesToNumFormat(
}
delete pSetBrush;
delete pSetSize;
- delete pSetVOrient;
}
if(bWrongArg)
diff --git a/sw/source/filter/html/htmldrawreader.cxx b/sw/source/filter/html/htmldrawreader.cxx
index d47e01a24acc..9843075560ea 100644
--- a/sw/source/filter/html/htmldrawreader.cxx
+++ b/sw/source/filter/html/htmldrawreader.cxx
@@ -239,10 +239,9 @@ static void PutEEPoolItem( SfxItemSet &rEEItemSet,
if( nEEWhich )
{
- SfxPoolItem *pEEItem = rSwItem.Clone();
+ std::unique_ptr<SfxPoolItem> pEEItem(rSwItem.Clone());
pEEItem->SetWhich( nEEWhich );
rEEItemSet.Put( *pEEItem );
- delete pEEItem;
}
}
diff --git a/sw/source/filter/html/htmldrawwriter.cxx b/sw/source/filter/html/htmldrawwriter.cxx
index 8dc50e8358cf..b6f071c869c4 100644
--- a/sw/source/filter/html/htmldrawwriter.cxx
+++ b/sw/source/filter/html/htmldrawwriter.cxx
@@ -114,10 +114,9 @@ void SwHTMLWriter::GetEEAttrsFromDrwObj( SfxItemSet& rItemSet,
pEEItem = &rObjItemSet.GetPool()->GetDefaultItem(nEEWhich);
// now we clone the item with the which id of the writer
- SfxPoolItem *pSwItem = pEEItem->Clone();
+ std::unique_ptr<SfxPoolItem> pSwItem(pEEItem->Clone());
pSwItem->SetWhich( nSwWhich );
rItemSet.Put( *pSwItem );
- delete pSwItem;
}
nEEWhich = aIter.NextWhich();
diff --git a/sw/source/filter/ww8/wrtw8esh.cxx b/sw/source/filter/ww8/wrtw8esh.cxx
index d64917bb54f9..99f8c902aab5 100644
--- a/sw/source/filter/ww8/wrtw8esh.cxx
+++ b/sw/source/filter/ww8/wrtw8esh.cxx
@@ -1155,7 +1155,7 @@ void MSWord_SdrAttrIter::OutAttr( sal_Int32 nSwPos )
m_rExport.CollapseScriptsforWordOk(nScript,nWhich))
{
// use always the SW-Which Id !
- SfxPoolItem* pI = i->pAttr->Clone();
+ std::unique_ptr<SfxPoolItem> pI(i->pAttr->Clone());
pI->SetWhich( nWhich );
// Will this item produce a <w:sz> element?
bool bFontSizeItem = nWhich == RES_CHRATR_FONTSIZE || nWhich == RES_CHRATR_CJK_FONTSIZE;
@@ -1163,7 +1163,6 @@ void MSWord_SdrAttrIter::OutAttr( sal_Int32 nSwPos )
m_rExport.AttrOutput().OutputItem( *pI );
if (bFontSizeItem)
m_rExport.m_bFontSizeWritten = true;
- delete pI;
}
}
}
@@ -1290,11 +1289,10 @@ void MSWord_SdrAttrIter::OutParaAttr(bool bCharAttr, const std::set<sal_uInt16>*
: ( nWhich >= RES_PARATR_BEGIN && nWhich < RES_FRMATR_END ) ) )
{
// use always the SW-Which Id !
- SfxPoolItem* pI = pItem->Clone();
+ std::unique_ptr<SfxPoolItem> pI(pItem->Clone());
pI->SetWhich( nWhich );
if (m_rExport.CollapseScriptsforWordOk(nScript,nWhich))
m_rExport.AttrOutput().OutputItem(*pI);
- delete pI;
}
} while( !aIter.IsAtEnd() && nullptr != ( pItem = aIter.NextItem() ) );
m_rExport.SetCurItemSet( pOldSet );
diff --git a/sw/source/filter/ww8/ww8graf.cxx b/sw/source/filter/ww8/ww8graf.cxx
index 885e33b26d3b..90cd932fa6d4 100644
--- a/sw/source/filter/ww8/ww8graf.cxx
+++ b/sw/source/filter/ww8/ww8graf.cxx
@@ -512,10 +512,9 @@ void SwWW8ImplReader::InsertTxbxStyAttrs( SfxItemSet& rS, sal_uInt16 nColl )
( SfxItemState::SET != rS.GetItemState(nWhich, false) )
)
{
- SfxPoolItem* pCopy = pItem->Clone();
+ std::unique_ptr<SfxPoolItem> pCopy(pItem->Clone());
pCopy->SetWhich( nWhich );
rS.Put( *pCopy );
- delete pCopy;
}
}
}
@@ -728,10 +727,9 @@ void SwWW8ImplReader::InsertAttrsAsDrawingAttrs(WW8_CP nStartCp, WW8_CP nEndCp,
nWhich != nSlotId
)
{
- SfxPoolItem* pCopy = pItem->Clone();
+ std::unique_ptr<SfxPoolItem> pCopy(pItem->Clone());
pCopy->SetWhich( nWhich );
pS->Put( *pCopy );
- delete pCopy;
}
}
}
diff --git a/sw/source/filter/ww8/ww8par6.cxx b/sw/source/filter/ww8/ww8par6.cxx
index 3b6468c0dac4..f240b8ffe969 100644
--- a/sw/source/filter/ww8/ww8par6.cxx
+++ b/sw/source/filter/ww8/ww8par6.cxx
@@ -3540,14 +3540,13 @@ void SwWW8ImplReader::Read_UnderlineColor(sal_uInt16, const sal_uInt8* pData, sh
{
if( SfxItemState::SET == m_pCurrentColl->GetItemState( RES_CHRATR_UNDERLINE, false ) )
{
- const SwAttrSet& aSet = m_pCurrentColl->GetAttrSet();
- SvxUnderlineItem *pUnderline
- = static_cast<SvxUnderlineItem *>(aSet.Get( RES_CHRATR_UNDERLINE, false ).Clone());
- if (pUnderline && nLen >= 4)
+ if (nLen >= 4)
{
+ const SwAttrSet& aSet = m_pCurrentColl->GetAttrSet();
+ std::unique_ptr<SvxUnderlineItem> pUnderline(
+ static_cast<SvxUnderlineItem *>(aSet.Get( RES_CHRATR_UNDERLINE, false ).Clone()));
pUnderline->SetColor( msfilter::util::BGRToRGB(SVBT32ToUInt32(pData)) );
m_pCurrentColl->SetFormatAttr( *pUnderline );
- delete pUnderline;
}
}
}
@@ -3555,13 +3554,11 @@ void SwWW8ImplReader::Read_UnderlineColor(sal_uInt16, const sal_uInt8* pData, sh
{
if ( SfxItemState::SET == m_xCurrentItemSet->GetItemState( RES_CHRATR_UNDERLINE, false ) )
{
- SvxUnderlineItem *pUnderline
- = static_cast<SvxUnderlineItem*>(m_xCurrentItemSet->Get(RES_CHRATR_UNDERLINE, false).Clone());
- if (pUnderline && nLen >= 4)
+ if (nLen >= 4)
{
+ std::unique_ptr<SvxUnderlineItem> pUnderline(static_cast<SvxUnderlineItem*>(m_xCurrentItemSet->Get(RES_CHRATR_UNDERLINE, false).Clone()));
pUnderline->SetColor( msfilter::util::BGRToRGB(SVBT32ToUInt32(pData)) );
m_xCurrentItemSet->Put( *pUnderline );
- delete pUnderline;
}
}
}
@@ -4541,10 +4538,9 @@ void SwWW8ImplReader::Read_BoolItem( sal_uInt16 nId, const sal_uInt8* pData, sho
m_xCtrlStck->SetAttr( *m_pPaM->GetPoint(), nId );
else
{
- SfxBoolItem* pI = static_cast<SfxBoolItem*>(GetDfltAttr( nId )->Clone());
+ std::unique_ptr<SfxBoolItem> pI(static_cast<SfxBoolItem*>(GetDfltAttr( nId )->Clone()));
pI->SetValue( 0 != *pData );
NewAttr( *pI );
- delete pI;
}
}
diff --git a/sw/source/filter/xml/xmlimpit.cxx b/sw/source/filter/xml/xmlimpit.cxx
index d6b1ea06ad44..afc3cd64d3d3 100644
--- a/sw/source/filter/xml/xmlimpit.cxx
+++ b/sw/source/filter/xml/xmlimpit.cxx
@@ -83,7 +83,7 @@ void SvXMLImportItemMapper::importXML( SfxItemSet& rSet,
{
sal_Int16 nAttr = xAttrList->getLength();
- SvXMLAttrContainerItem *pUnknownItem = nullptr;
+ std::unique_ptr<SvXMLAttrContainerItem> pUnknownItem;
for( sal_Int16 i=0; i < nAttr; i++ )
{
const OUString& rAttrName = xAttrList->getNameByIndex( i );
@@ -117,7 +117,7 @@ void SvXMLImportItemMapper::importXML( SfxItemSet& rSet,
// do we have an item?
if(eState >= SfxItemState::DEFAULT && pItem)
{
- SfxPoolItem *pNewItem = pItem->Clone();
+ std::unique_ptr<SfxPoolItem> pNewItem(pItem->Clone());
bool bPut = false;
if( 0 == (pEntry->nMemberId&MID_SW_FLAG_SPECIAL_ITEM_IMPORT) )
@@ -136,8 +136,6 @@ void SvXMLImportItemMapper::importXML( SfxItemSet& rSet,
if( bPut )
rSet.Put( *pNewItem );
-
- delete pNewItem;
}
else
{
@@ -158,16 +156,11 @@ void SvXMLImportItemMapper::importXML( SfxItemSet& rSet,
if( SfxItemState::SET == rSet.GetItemState( nUnknownWhich, true,
&pItem ) )
{
- SfxPoolItem *pNew = pItem->Clone();
- pUnknownItem = dynamic_cast<SvXMLAttrContainerItem*>( pNew );
- OSL_ENSURE( pUnknownItem,
- "SvXMLAttrContainerItem expected" );
- if( !pUnknownItem )
- delete pNew;
+ pUnknownItem.reset( static_cast<SvXMLAttrContainerItem*>( pItem->Clone() ) );
}
else
{
- pUnknownItem = new SvXMLAttrContainerItem( nUnknownWhich );
+ pUnknownItem.reset( new SvXMLAttrContainerItem( nUnknownWhich ) );
}
}
if( pUnknownItem )
@@ -184,7 +177,6 @@ void SvXMLImportItemMapper::importXML( SfxItemSet& rSet,
if( pUnknownItem )
{
rSet.Put( *pUnknownItem );
- delete pUnknownItem;
}
finished(rSet, rUnitConverter);
diff --git a/sw/source/filter/xml/xmlitemi.cxx b/sw/source/filter/xml/xmlitemi.cxx
index aac6e87740e3..1e1c5f3a9672 100644
--- a/sw/source/filter/xml/xmlitemi.cxx
+++ b/sw/source/filter/xml/xmlitemi.cxx
@@ -214,7 +214,7 @@ void SwXMLImportTableItemMapper_Impl::finished(
// do we have an item?
if (eState >= SfxItemState::DEFAULT && pItem)
{
- SfxPoolItem *const pNewItem = pItem->Clone();
+ std::unique_ptr<SfxPoolItem> pNewItem(pItem->Clone());
bool const bPut = PutXMLValue(
*pNewItem, m_FoMarginValue, Ids[i][1], rUnitConverter);
if (bPut)
diff --git a/sw/source/ui/chrdlg/numpara.cxx b/sw/source/ui/chrdlg/numpara.cxx
index 2c13bf47dc32..0a102586c1e4 100644
--- a/sw/source/ui/chrdlg/numpara.cxx
+++ b/sw/source/ui/chrdlg/numpara.cxx
@@ -111,10 +111,9 @@ bool SwParagraphNumTabPage::FillItemSet( SfxItemSet* rSet )
const SfxUInt16Item* pOldOutlineLv = static_cast<const SfxUInt16Item*>(GetOldItem( *rSet, SID_ATTR_PARA_OUTLINE_LEVEL));
if (pOldOutlineLv)
{
- SfxUInt16Item* pOutlineLv = static_cast<SfxUInt16Item*>(pOldOutlineLv->Clone());
+ std::unique_ptr<SfxUInt16Item> pOutlineLv(static_cast<SfxUInt16Item*>(pOldOutlineLv->Clone()));
pOutlineLv->SetValue( aOutlineLv );
rSet->Put(*pOutlineLv);
- delete pOutlineLv;
bModified = true;
}
}
@@ -125,12 +124,11 @@ bool SwParagraphNumTabPage::FillItemSet( SfxItemSet* rSet )
if (m_xNumberStyleLB->get_active())
aStyle = m_xNumberStyleLB->get_active_text();
const SfxStringItem* pOldRule = static_cast<const SfxStringItem*>(GetOldItem( *rSet, SID_ATTR_PARA_NUMRULE));
- SfxStringItem* pRule = pOldRule ? static_cast<SfxStringItem*>(pOldRule->Clone()) : nullptr;
- if (pRule)
+ if (pOldRule)
{
+ std::unique_ptr<SfxStringItem> pRule(static_cast<SfxStringItem*>(pOldRule->Clone()));
pRule->SetValue(aStyle);
rSet->Put(*pRule);
- delete pRule;
bModified = true;
}
}
diff --git a/sw/source/uibase/sidebar/PageOrientationControl.cxx b/sw/source/uibase/sidebar/PageOrientationControl.cxx
index a5ff79bab38e..aa810867aae9 100644
--- a/sw/source/uibase/sidebar/PageOrientationControl.cxx
+++ b/sw/source/uibase/sidebar/PageOrientationControl.cxx
@@ -111,19 +111,13 @@ void PageOrientationControl::ExecuteOrientationChange( const bool bLandscape )
const SfxPoolItem* pItem;
SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState(SID_ATTR_PAGE_SIZE, pItem);
- SvxSizeItem* pSizeItem = static_cast<SvxSizeItem*>(pItem->Clone());
- if ( pSizeItem )
- mpPageSizeItem.reset( pSizeItem );
+ mpPageSizeItem.reset( static_cast<SvxSizeItem*>(pItem->Clone()) );
SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState(SID_ATTR_PAGE_LRSPACE, pItem);
- SvxLongLRSpaceItem* pLRItem = static_cast<SvxLongLRSpaceItem*>(pItem->Clone());
- if ( pLRItem )
- mpPageLRMarginItem.reset( pLRItem );
+ mpPageLRMarginItem.reset( static_cast<SvxLongLRSpaceItem*>(pItem->Clone()) );
SfxViewFrame::Current()->GetBindings().GetDispatcher()->QueryState(SID_ATTR_PAGE_ULSPACE, pItem);
- SvxLongULSpaceItem* pULItem = static_cast<SvxLongULSpaceItem*>(pItem->Clone());
- if ( pULItem )
- mpPageULMarginItem.reset( pULItem );
+ mpPageULMarginItem.reset( static_cast<SvxLongULSpaceItem*>(pItem->Clone()) );
{
// set new page orientation