[Libreoffice-commits] core.git: chart2/source cui/source editeng/source forms/source sc/source sd/source sfx2/source svl/source svx/source sw/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Oct 26 11:31:16 UTC 2018


 chart2/source/controller/itemsetwrapper/ItemConverter.cxx |   10 --
 cui/source/options/treeopt.cxx                            |    3 
 editeng/source/editeng/editdoc.cxx                        |    3 
 editeng/source/editeng/impedit4.cxx                       |    3 
 editeng/source/uno/unoipset.cxx                           |    3 
 forms/source/richtext/richtextimplcontrol.cxx             |    3 
 forms/source/richtext/rtattributehandler.cxx              |    8 -
 sc/source/core/data/attarray.cxx                          |    9 --
 sc/source/ui/unoobj/afmtuno.cxx                           |    3 
 sc/source/ui/unoobj/defltuno.cxx                          |    3 
 sd/source/ui/func/fuconstr.cxx                            |    4 
 sfx2/source/appl/appopen.cxx                              |    7 -
 sfx2/source/control/bindings.cxx                          |    8 -
 svl/source/items/poolitem.cxx                             |    4 
 svx/source/svdraw/svdibrow.cxx                            |   41 ++++-----
 sw/source/core/doc/docfmt.cxx                             |    3 
 sw/source/core/doc/docnew.cxx                             |    9 --
 sw/source/core/docnode/ndtbl.cxx                          |    3 
 sw/source/core/draw/drawdoc.cxx                           |    3 
 sw/source/core/tox/ToxTextGenerator.cxx                   |    2 
 sw/source/core/undo/SwUndoPageDesc.cxx                    |   62 +++++---------
 sw/source/core/undo/unattr.cxx                            |    6 -
 sw/source/core/unocore/SwXTextDefaults.cxx                |   14 +--
 sw/source/core/unocore/unoframe.cxx                       |    8 -
 sw/source/core/unocore/unosett.cxx                        |    9 --
 sw/source/filter/html/htmldrawreader.cxx                  |    3 
 sw/source/filter/html/htmldrawwriter.cxx                  |    3 
 sw/source/filter/ww8/wrtw8esh.cxx                         |    6 -
 sw/source/filter/ww8/ww8graf.cxx                          |    6 -
 sw/source/filter/ww8/ww8par6.cxx                          |   18 +---
 sw/source/filter/xml/xmlimpit.cxx                         |   16 ---
 sw/source/filter/xml/xmlitemi.cxx                         |    2 
 sw/source/ui/chrdlg/numpara.cxx                           |    8 -
 sw/source/uibase/sidebar/PageOrientationControl.cxx       |   12 --
 34 files changed, 116 insertions(+), 189 deletions(-)

New commits:
commit 4054dff516367b332b7e3ce6fa91a452bf690571
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Fri Oct 26 12:06:27 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Fri Oct 26 13:30:49 2018 +0200

    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 at collabora.co.uk>

diff --git a/chart2/source/controller/itemsetwrapper/ItemConverter.cxx b/chart2/source/controller/itemsetwrapper/ItemConverter.cxx
index 9d4fd5669841..a463fc176b82 100644
--- a/chart2/source/controller/itemsetwrapper/ItemConverter.cxx
+++ b/chart2/source/controller/itemsetwrapper/ItemConverter.cxx
@@ -97,28 +97,22 @@ void ItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
             if( GetItemProperty( nWhich, aProperty ))
             {
                 // put the Property into the itemset
-                SfxPoolItem * pItem = rPool.GetDefaultItem( nWhich ).Clone();
+                std::unique_ptr<SfxPoolItem> pItem(rPool.GetDefaultItem( nWhich ).Clone());
 
                 if( pItem )
                 {
                     try
                     {
-                        if( ! pItem->PutValue( m_xPropertySet->getPropertyValue( aProperty.first ),
+                        if( pItem->PutValue( m_xPropertySet->getPropertyValue( aProperty.first ),
                                                aProperty.second // nMemberId
                                 ))
                         {
-                            delete pItem;
-                        }
-                        else
-                        {
                             pItem->SetWhich(nWhich);
                             rOutItemSet.Put( *pItem );
-                            delete pItem;
                         }
                     }
                     catch( const beans::UnknownPropertyException &ex )
                     {
-                        delete pItem;
                         SAL_WARN( "chart2", ex << " - unknown Property: " << aProperty.first);
                     }
                     catch( const uno::Exception & )
diff --git a/cui/source/options/treeopt.cxx b/cui/source/options/treeopt.cxx
index 47d3a7ffcaa7..ee1070ab4ec3 100644
--- a/cui/source/options/treeopt.cxx
+++ b/cui/source/options/treeopt.cxx
@@ -1238,9 +1238,8 @@ std::unique_ptr<SfxItemSet> OfaTreeOptionsDialog::CreateItemSet( sal_uInt16 nId
                 pRet->Put(aHyphen);
                 if(SfxItemState::DEFAULT <= pDispatch->QueryState(SID_AUTOSPELL_CHECK, pItem))
                 {
-                    SfxPoolItem* pClone = pItem->Clone();
+                    std::unique_ptr<SfxPoolItem> pClone(pItem->Clone());
                     pRet->Put(*pClone);
-                    delete pClone;
                 }
                 else
                 {
diff --git a/editeng/source/editeng/editdoc.cxx b/editeng/source/editeng/editdoc.cxx
index f4c761183276..18d14cf82d81 100644
--- a/editeng/source/editeng/editdoc.cxx
+++ b/editeng/source/editeng/editdoc.cxx
@@ -896,11 +896,10 @@ void ConvertAndPutItems( SfxItemSet& rDest, const SfxItemSet& rSource, const Map
             MapUnit eDestUnit = pDestUnit ? *pDestUnit : pDestPool->GetMetric( nWhich );
             if ( eSourceUnit != eDestUnit )
             {
-                SfxPoolItem* pItem = rSource.Get( nSourceWhich ).Clone();
+                std::unique_ptr<SfxPoolItem> pItem(rSource.Get( nSourceWhich ).Clone());
                 ConvertItem( *pItem, eSourceUnit, eDestUnit );
                 pItem->SetWhich(nWhich);
                 rDest.Put( *pItem );
-                delete pItem;
             }
             else
             {
diff --git a/editeng/source/editeng/impedit4.cxx b/editeng/source/editeng/impedit4.cxx
index 4be47ec63d4a..68de66939b06 100644
--- a/editeng/source/editeng/impedit4.cxx
+++ b/editeng/source/editeng/impedit4.cxx
@@ -1237,10 +1237,9 @@ EditSelection ImpEditEngine::InsertTextObject( const EditTextObject& rTextObject
                             pAttr = MakeCharAttrib( aEditDoc.GetItemPool(), *(rX.GetItem()), rX.GetStart()+nStartPos, rX.GetEnd()+nStartPos );
                         else
                         {
-                            SfxPoolItem* pNew = rX.GetItem()->Clone();
+                            std::unique_ptr<SfxPoolItem> pNew(rX.GetItem()->Clone());
                             ConvertItem( *pNew, eSourceUnit, eDestUnit );
                             pAttr = MakeCharAttrib( aEditDoc.GetItemPool(), *pNew, rX.GetStart()+nStartPos, rX.GetEnd()+nStartPos );
-                            delete pNew;
                         }
                         DBG_ASSERT( pAttr->GetEnd() <= aPaM.GetNode()->Len(), "InsertBinTextObject: Attribute does not fit! (1)" );
                         aPaM.GetNode()->GetCharAttribs().InsertAttrib( pAttr );
diff --git a/editeng/source/uno/unoipset.cxx b/editeng/source/uno/unoipset.cxx
index 1f84b114a810..71afb18871e3 100644
--- a/editeng/source/uno/unoipset.cxx
+++ b/editeng/source/uno/unoipset.cxx
@@ -171,7 +171,7 @@ void SvxItemPropertySet::setPropertyValue( const SfxItemPropertySimpleEntry* pMa
                 SvxUnoConvertFromMM( eMapUnit, aValue );
         }
 
-        SfxPoolItem *pNewItem = pItem->Clone();
+        std::unique_ptr<SfxPoolItem> pNewItem( pItem->Clone() );
 
         sal_uInt8 nMemberId = pMap->nMemberId;
         if( eMapUnit == MapUnit::Map100thMM )
@@ -183,7 +183,6 @@ void SvxItemPropertySet::setPropertyValue( const SfxItemPropertySimpleEntry* pMa
             pNewItem->SetWhich( pMap->nWID );
             rSet.Put( *pNewItem );
         }
-        delete pNewItem;
     }
 }
 
diff --git a/forms/source/richtext/richtextimplcontrol.cxx b/forms/source/richtext/richtextimplcontrol.cxx
index 4ab753f040c7..5eec237ff775 100644
--- a/forms/source/richtext/richtextimplcontrol.cxx
+++ b/forms/source/richtext/richtextimplcontrol.cxx
@@ -225,10 +225,9 @@ namespace frm
         WhichId nNormalizedWhichId = _rScriptSetItem.GetItemSet().GetPool()->GetWhich( _rScriptSetItem.Which() );
         if ( pNormalizedItem )
         {
-            SfxPoolItem* pProperWhich = pNormalizedItem->Clone();
+            std::unique_ptr<SfxPoolItem> pProperWhich(pNormalizedItem->Clone());
             pProperWhich->SetWhich( nNormalizedWhichId );
             _rScriptSetItem.GetItemSet().Put( *pProperWhich );
-            DELETEZ( pProperWhich );
         }
         else
             _rScriptSetItem.GetItemSet().InvalidateItem( nNormalizedWhichId );
diff --git a/forms/source/richtext/rtattributehandler.cxx b/forms/source/richtext/rtattributehandler.cxx
index c78e3524bb04..7c2845e9b34f 100644
--- a/forms/source/richtext/rtattributehandler.cxx
+++ b/forms/source/richtext/rtattributehandler.cxx
@@ -281,7 +281,7 @@ namespace frm
 
         const SfxPoolItem* pItem = _rAttribs.GetItem( getWhich() );
         if ( pItem )
-            aState.setItem( pItem->Clone() );
+            aState.setItem( pItem );
 
         return aState;
     }
@@ -291,14 +291,13 @@ namespace frm
     {
         if ( _pAdditionalArg )
         {
-            SfxPoolItem* pCorrectWich = _pAdditionalArg->Clone();
+            std::unique_ptr<SfxPoolItem> pCorrectWich(_pAdditionalArg->Clone());
             pCorrectWich->SetWhich( getWhich() );
 
             if ( m_bScriptDependent )
                 putItemForScript( _rNewAttribs, *pCorrectWich, _nForScriptType );
             else
                 _rNewAttribs.Put( *pCorrectWich );
-            DELETEZ( pCorrectWich );
         }
         else
             OSL_FAIL( "SlotHandler::executeAttribute: need attributes to do something!" );
@@ -434,10 +433,9 @@ namespace frm
         OSL_ENSURE( dynamic_cast<const SfxBoolItem*>( _pAdditionalArg) !=  nullptr, "BooleanHandler::executeAttribute: invalid argument!" );
         if ( _pAdditionalArg )
         {
-            SfxPoolItem* pCorrectWich = _pAdditionalArg->Clone();
+            std::unique_ptr<SfxPoolItem> pCorrectWich(_pAdditionalArg->Clone());
             pCorrectWich->SetWhich( getWhich() );
             _rNewAttribs.Put( *pCorrectWich );
-            DELETEZ( pCorrectWich );
         }
     }
 
diff --git a/sc/source/core/data/attarray.cxx b/sc/source/core/data/attarray.cxx
index e5c3f3534e55..16201a96b22b 100644
--- a/sc/source/core/data/attarray.cxx
+++ b/sc/source/core/data/attarray.cxx
@@ -746,9 +746,9 @@ void ScAttrArray::ApplyLineStyleArea( SCROW nStartRow, SCROW nEndRow,
                 SCROW           nY1 = nStart;
                 SCROW           nY2 = mvData[nPos].nEndRow;
 
-                SvxBoxItem*     pNewBoxItem = pBoxItem ? static_cast<SvxBoxItem*>(pBoxItem->Clone()) : nullptr;
-                SvxLineItem*    pNewTLBRItem = pTLBRItem ? static_cast<SvxLineItem*>(pTLBRItem->Clone()) : nullptr;
-                SvxLineItem*    pNewBLTRItem = pBLTRItem ? static_cast<SvxLineItem*>(pBLTRItem->Clone()) : nullptr;
+                std::unique_ptr<SvxBoxItem>  pNewBoxItem( pBoxItem ? static_cast<SvxBoxItem*>(pBoxItem->Clone()) : nullptr);
+                std::unique_ptr<SvxLineItem> pNewTLBRItem( pTLBRItem ? static_cast<SvxLineItem*>(pTLBRItem->Clone()) : nullptr);
+                std::unique_ptr<SvxLineItem> pNewBLTRItem(pBLTRItem ? static_cast<SvxLineItem*>(pBLTRItem->Clone()) : nullptr);
 
                 // fetch line and update attributes with parameters
 
@@ -823,9 +823,6 @@ void ScAttrArray::ApplyLineStyleArea( SCROW nStartRow, SCROW nEndRow,
                     else
                         nPos++;
                 }
-                delete pNewBoxItem;
-                delete pNewTLBRItem;
-                delete pNewBLTRItem;
             }
             else
             {
diff --git a/sc/source/ui/unoobj/afmtuno.cxx b/sc/source/ui/unoobj/afmtuno.cxx
index d2f03486c794..1aff21e72fdb 100644
--- a/sc/source/ui/unoobj/afmtuno.cxx
+++ b/sc/source/ui/unoobj/afmtuno.cxx
@@ -659,11 +659,10 @@ void SAL_CALL ScAutoFormatFieldObj::setPropertyValue(
                     }
                     break;
                     default:
-                        SfxPoolItem* pNewItem = pItem->Clone();
+                        std::unique_ptr<SfxPoolItem> pNewItem(pItem->Clone());
                         bDone = pNewItem->PutValue( aValue, pEntry->nMemberId );
                         if (bDone)
                             pData->PutItem( nFieldIndex, *pNewItem );
-                        delete pNewItem;
                 }
 
                 if (bDone)
diff --git a/sc/source/ui/unoobj/defltuno.cxx b/sc/source/ui/unoobj/defltuno.cxx
index 87867b79f929..bec8a82e0429 100644
--- a/sc/source/ui/unoobj/defltuno.cxx
+++ b/sc/source/ui/unoobj/defltuno.cxx
@@ -186,13 +186,12 @@ void SAL_CALL ScDocDefaultsObj::setPropertyValue(
     else
     {
         ScDocumentPool* pPool = pDocShell->GetDocument().GetPool();
-        SfxPoolItem* pNewItem = pPool->GetDefaultItem(pEntry->nWID).Clone();
+        std::unique_ptr<SfxPoolItem> pNewItem(pPool->GetDefaultItem(pEntry->nWID).Clone());
 
         if( !pNewItem->PutValue( aValue, pEntry->nMemberId ) )
             throw lang::IllegalArgumentException();
 
         pPool->SetPoolDefaultItem( *pNewItem );
-        delete pNewItem;    // copied in SetPoolDefaultItem
 
         ItemsChanged();
     }
diff --git a/sd/source/ui/func/fuconstr.cxx b/sd/source/ui/func/fuconstr.cxx
index ecd4456d193f..d3c7b93c89f7 100644
--- a/sd/source/ui/func/fuconstr.cxx
+++ b/sd/source/ui/func/fuconstr.cxx
@@ -356,13 +356,13 @@ void FuConstruct::SetStyleSheet( SfxItemSet& rAttr, SdrObject* pObj,
             if (pSheet)
             {
                 pObj->SetStyleSheet(pSheet, false);
-                SfxItemSet aAttr(*mpView->GetDefaultAttr().Clone());
+                SfxItemSet aAttr(mpView->GetDefaultAttr());
                 aAttr.Put(pSheet->GetItemSet().Get(XATTR_FILLSTYLE));
                 pObj->SetMergedItemSet(aAttr);
             }
             else
             {
-                SfxItemSet aAttr(*mpView->GetDefaultAttr().Clone());
+                SfxItemSet aAttr(mpView->GetDefaultAttr());
                 rAttr.Put(XFillStyleItem(drawing::FillStyle_NONE));
                 pObj->SetMergedItemSet(aAttr);
             }
diff --git a/sfx2/source/appl/appopen.cxx b/sfx2/source/appl/appopen.cxx
index 1c16308dbd4e..c54b3e58580b 100644
--- a/sfx2/source/appl/appopen.cxx
+++ b/sfx2/source/appl/appopen.cxx
@@ -942,11 +942,11 @@ void SfxApplication::OpenDocExec_Impl( SfxRequest& rReq )
         pTargetFrame = &SfxViewFrame::Current()->GetFrame();
 
     // check if caller has set a callback
-    const SfxLinkItem* pLinkItem = rReq.GetArg<SfxLinkItem>(SID_DONELINK);
+    std::unique_ptr<SfxLinkItem> pLinkItem;
 
     // remove from Itemset, because it confuses the parameter transformation
-    if ( pLinkItem )
-        pLinkItem = static_cast<SfxLinkItem*>( pLinkItem->Clone() );
+    if (auto pParamLinkItem = rReq.GetArg<SfxLinkItem>(SID_DONELINK))
+        pLinkItem.reset( static_cast<SfxLinkItem*>( pParamLinkItem->Clone() ) );
 
     rReq.RemoveItem( SID_DONELINK );
 
@@ -1111,7 +1111,6 @@ void SfxApplication::OpenDocExec_Impl( SfxRequest& rReq )
         {
             pLinkItem->GetValue().Call(pRetValue);
         }
-        delete pLinkItem;
     }
 }
 
diff --git a/sfx2/source/control/bindings.cxx b/sfx2/source/control/bindings.cxx
index 2b2409be3369..29d49129f076 100644
--- a/sfx2/source/control/bindings.cxx
+++ b/sfx2/source/control/bindings.cxx
@@ -1018,20 +1018,18 @@ void SfxBindings::Execute_Impl( SfxRequest& aReq, const SfxSlot* pSlot, SfxShell
                 {
                     // we can toggle Bools
                     bool bOldValue = pOldBoolItem->GetValue();
-                    SfxBoolItem *pNewItem = static_cast<SfxBoolItem*>(pOldItem->Clone());
+                    std::unique_ptr<SfxBoolItem> pNewItem(static_cast<SfxBoolItem*>(pOldItem->Clone()));
                     pNewItem->SetValue( !bOldValue );
                     aReq.AppendItem( *pNewItem );
-                    delete pNewItem;
                 }
                 else if ( dynamic_cast< const SfxEnumItemInterface *>( pOldItem ) !=  nullptr &&
                         static_cast<const SfxEnumItemInterface *>(pOldItem)->HasBoolValue())
                 {
                     // and Enums with Bool-Interface
-                    SfxEnumItemInterface *pNewItem =
-                        static_cast<SfxEnumItemInterface*>(pOldItem->Clone());
+                    std::unique_ptr<SfxEnumItemInterface> pNewItem(
+                        static_cast<SfxEnumItemInterface*>(pOldItem->Clone()));
                     pNewItem->SetBoolValue(!static_cast<const SfxEnumItemInterface *>(pOldItem)->GetBoolValue());
                     aReq.AppendItem( *pNewItem );
-                    delete pNewItem;
                 }
                 else {
                     OSL_FAIL( "Toggle only for Enums and Bools allowed" );
diff --git a/svl/source/items/poolitem.cxx b/svl/source/items/poolitem.cxx
index 40e9ef895d42..346e38324bce 100644
--- a/svl/source/items/poolitem.cxx
+++ b/svl/source/items/poolitem.cxx
@@ -129,9 +129,9 @@ void SfxPoolItem::dumpAsXml(xmlTextWriterPtr pWriter) const
 
 std::unique_ptr<SfxPoolItem> SfxPoolItem::CloneSetWhich( sal_uInt16 nNewWhich ) const
 {
-    SfxPoolItem* pItem = Clone();
+    std::unique_ptr<SfxPoolItem> pItem(Clone());
     pItem->SetWhich(nNewWhich);
-    return std::unique_ptr<SfxPoolItem>(pItem);
+    return pItem;
 }
 
 bool SfxPoolItem::IsVoidItem() const
diff --git a/svx/source/svdraw/svdibrow.cxx b/svx/source/svdraw/svdibrow.cxx
index db64774aa686..eef8f83fc9bb 100644
--- a/svx/source/svdraw/svdibrow.cxx
+++ b/svx/source/svdraw/svdibrow.cxx
@@ -1126,7 +1126,7 @@ IMPL_LINK(SdrItemBrowser, ChangedHdl, SdrItemBrowserControl&, rBrowse, void)
             || aNewText == "DEFAULT" );
 
         if (!bDel) {
-            SfxPoolItem* pNewItem=aSet.Get(pEntry->nWhichId).Clone();
+            std::unique_ptr<SfxPoolItem> pNewItem(aSet.Get(pEntry->nWhichId).Clone());
             sal_Int32 nLongVal = aNewText.toInt32();
             if (pEntry->bCanNum) {
                 if (nLongVal>pEntry->nMax) nLongVal=pEntry->nMax;
@@ -1149,20 +1149,20 @@ IMPL_LINK(SdrItemBrowser, ChangedHdl, SdrItemBrowserControl&, rBrowse, void)
                 nLongY = s.toInt32();
             }
             switch (pEntry->eItemType) {
-                case ItemType::BYTE  : static_cast<SfxByteItem  *>(pNewItem)->SetValue(static_cast<sal_uInt8>(nLongVal)); break;
-                case ItemType::INT16 : static_cast<SfxInt16Item *>(pNewItem)->SetValue(static_cast<sal_Int16>(nLongVal)); break;
-                case ItemType::UINT16: static_cast<SfxUInt16Item*>(pNewItem)->SetValue(static_cast<sal_uInt16>(nLongVal)); break;
+                case ItemType::BYTE  : static_cast<SfxByteItem  *>(pNewItem.get())->SetValue(static_cast<sal_uInt8>(nLongVal)); break;
+                case ItemType::INT16 : static_cast<SfxInt16Item *>(pNewItem.get())->SetValue(static_cast<sal_Int16>(nLongVal)); break;
+                case ItemType::UINT16: static_cast<SfxUInt16Item*>(pNewItem.get())->SetValue(static_cast<sal_uInt16>(nLongVal)); break;
                 case ItemType::INT32: {
-                    if(dynamic_cast<const SdrAngleItem *>(pNewItem) != nullptr)
+                    if(dynamic_cast<const SdrAngleItem *>(pNewItem.get()))
                     {
                         aNewText = aNewText.replace(',', '.');
                         double nVal = aNewText.toFloat();
                         nLongVal = static_cast<sal_Int32>(nVal * 100.0 + 0.5);
                     }
-                    static_cast<SfxInt32Item *>(pNewItem)->SetValue(nLongVal);
+                    static_cast<SfxInt32Item *>(pNewItem.get())->SetValue(nLongVal);
                 } break;
-                case ItemType::UINT32: static_cast<SfxUInt32Item*>(pNewItem)->SetValue(aNewText.toInt32()); break;
-                case ItemType::ENUM  : static_cast<SfxEnumItemInterface*>(pNewItem)->SetEnumValue(static_cast<sal_uInt16>(nLongVal)); break;
+                case ItemType::UINT32: static_cast<SfxUInt32Item*>(pNewItem.get())->SetValue(aNewText.toInt32()); break;
+                case ItemType::ENUM  : static_cast<SfxEnumItemInterface*>(pNewItem.get())->SetEnumValue(static_cast<sal_uInt16>(nLongVal)); break;
                 case ItemType::BOOL: {
                     aNewText = aNewText.toAsciiUpperCase();
                     if (aNewText == "TRUE") nLongVal=1;
@@ -1171,27 +1171,27 @@ IMPL_LINK(SdrItemBrowser, ChangedHdl, SdrItemBrowserControl&, rBrowse, void)
                     if (aNewText == "EIN") nLongVal=1;
                     if (aNewText == "ON") nLongVal=1;
                     if (aNewText == "YES") nLongVal=1;
-                    static_cast<SfxBoolItem*>(pNewItem)->SetValue(nLongVal == 1);
+                    static_cast<SfxBoolItem*>(pNewItem.get())->SetValue(nLongVal == 1);
                 } break;
-                case ItemType::FLAG  : static_cast<SfxFlagItem  *>(pNewItem)->SetValue(static_cast<sal_uInt16>(nLongVal)); break;
-                case ItemType::STRING: static_cast<SfxStringItem*>(pNewItem)->SetValue(aNewText); break;
-                case ItemType::POINT : static_cast<SfxPointItem*>(pNewItem)->SetValue(Point(nLongX,nLongY)); break;
+                case ItemType::FLAG  : static_cast<SfxFlagItem  *>(pNewItem.get())->SetValue(static_cast<sal_uInt16>(nLongVal)); break;
+                case ItemType::STRING: static_cast<SfxStringItem*>(pNewItem.get())->SetValue(aNewText); break;
+                case ItemType::POINT : static_cast<SfxPointItem*>(pNewItem.get())->SetValue(Point(nLongX,nLongY)); break;
                 case ItemType::RECT  : break;
                 case ItemType::RANGE : {
-                    static_cast<SfxRangeItem*>(pNewItem)->From()=static_cast<sal_uInt16>(nLongX);
-                    static_cast<SfxRangeItem*>(pNewItem)->From()=static_cast<sal_uInt16>(nLongY);
+                    static_cast<SfxRangeItem*>(pNewItem.get())->From()=static_cast<sal_uInt16>(nLongX);
+                    static_cast<SfxRangeItem*>(pNewItem.get())->From()=static_cast<sal_uInt16>(nLongY);
                 } break;
                 case ItemType::FRACTION: {
                     if (!bPairX) nLongX=1;
                     if (!bPairY) nLongY=1;
-                    static_cast<SdrFractionItem*>(pNewItem)->SetValue(Fraction(nLongX,nLongY));
+                    static_cast<SdrFractionItem*>(pNewItem.get())->SetValue(Fraction(nLongX,nLongY));
                 } break;
                 case ItemType::XCOLOR: break;
                 case ItemType::COLOR: break;
                 case ItemType::FONT: {
-                    static_cast<SvxFontItem*>(pNewItem)->SetFamily( FAMILY_DONTKNOW );
-                    static_cast<SvxFontItem*>(pNewItem)->SetFamilyName(aNewText);
-                    static_cast<SvxFontItem*>(pNewItem)->SetStyleName(OUString());
+                    static_cast<SvxFontItem*>(pNewItem.get())->SetFamily( FAMILY_DONTKNOW );
+                    static_cast<SvxFontItem*>(pNewItem.get())->SetFamilyName(aNewText);
+                    static_cast<SvxFontItem*>(pNewItem.get())->SetStyleName(OUString());
                 } break;
                 case ItemType::FONTHEIGHT: {
                     sal_uInt32 nHgt=0;
@@ -1201,20 +1201,19 @@ IMPL_LINK(SdrItemBrowser, ChangedHdl, SdrItemBrowserControl&, rBrowse, void)
                     } else {
                         nHgt=static_cast<sal_uInt32>(nLongVal);
                     }
-                    static_cast<SvxFontHeightItem*>(pNewItem)->SetHeight(nHgt,nProp);
+                    static_cast<SvxFontHeightItem*>(pNewItem.get())->SetHeight(nHgt,nProp);
                 } break;
                 case ItemType::FONTWIDTH: {
                     sal_uInt16 nProp=100;
                     if (aNewText.indexOf('%') != -1) {
                         nProp=static_cast<sal_uInt16>(nLongVal);
                     }
-                    static_cast<SvxCharScaleWidthItem*>(pNewItem)->SetValue(nProp);
+                    static_cast<SvxCharScaleWidthItem*>(pNewItem.get())->SetValue(nProp);
                 } break;
                 case ItemType::FIELD: break;
                 default: break;
             } // switch
             aNewSet.Put(*pNewItem);
-            delete pNewItem;
         }
         pView->SetAttributes(aNewSet,bDel);
     }
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


More information about the Libreoffice-commits mailing list