[Libreoffice-commits] core.git: cui/source include/sfx2 sc/source sd/source sfx2/source svx/source sw/source

Stephan Bergmann sbergman at redhat.com
Tue Dec 8 23:16:57 PST 2015


 cui/source/tabpages/chardlg.cxx        |    3 +--
 include/sfx2/bindings.hxx              |    5 ++++-
 sc/source/ui/view/cellsh3.cxx          |    6 ++----
 sc/source/ui/view/formatsh.cxx         |   10 ++++------
 sc/source/ui/view/viewutil.cxx         |    5 ++---
 sd/source/ui/view/drviewsf.cxx         |   20 ++++++++------------
 sd/source/ui/view/outlnvsh.cxx         |    5 ++---
 sfx2/source/control/bindings.cxx       |   18 ++++++++----------
 sfx2/source/menu/mnumgr.cxx            |    5 ++---
 sfx2/source/sidebar/ControllerItem.cxx |    5 ++---
 svx/source/dialog/rubydialog.cxx       |   10 ++++------
 svx/source/fmcomp/fmgridcl.cxx         |    7 +++----
 sw/source/uibase/app/docst.cxx         |    5 ++---
 sw/source/uibase/docvw/romenu.cxx      |   15 +++++----------
 14 files changed, 49 insertions(+), 70 deletions(-)

New commits:
commit 4754afddc3030347ef49b401a9b798cea8fe523c
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Tue Dec 8 18:57:32 2015 +0100

    Use unique_ptr out-arg to in SfxBindings::QueryState to avoid mem leaks
    
    Change-Id: I35df02de675068478a36ef05266ffc2d3054b07f
    Reviewed-on: https://gerrit.libreoffice.org/20477
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>

diff --git a/cui/source/tabpages/chardlg.cxx b/cui/source/tabpages/chardlg.cxx
index 9e47e24..ed1a26d 100644
--- a/cui/source/tabpages/chardlg.cxx
+++ b/cui/source/tabpages/chardlg.cxx
@@ -1468,7 +1468,7 @@ void SvxCharEffectsPage::Initialize()
     m_pFontColorLB->SetUpdateMode( false );
 
     {
-        SfxPoolItem* pDummy = nullptr;
+        std::unique_ptr<SfxPoolItem> pDummy;
         SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pDocSh );
         if ( !pFrame ||
              SfxItemState::DEFAULT > pFrame->GetBindings().QueryState( SID_ATTR_AUTO_COLOR_INVALID, pDummy ) )
@@ -1477,7 +1477,6 @@ void SvxCharEffectsPage::Initialize()
             m_pOverlineColorLB->InsertAutomaticEntryColor( Color( COL_AUTO ) );
             m_pFontColorLB->InsertAutomaticEntryColor( Color( COL_AUTO ) );
         }
-        delete pDummy;
     }
     for ( long i = 0; i < pColorTable->Count(); i++ )
     {
diff --git a/include/sfx2/bindings.hxx b/include/sfx2/bindings.hxx
index bbe5cc4..413ce7e 100644
--- a/include/sfx2/bindings.hxx
+++ b/include/sfx2/bindings.hxx
@@ -20,6 +20,9 @@
 #define INCLUDED_SFX2_BINDINGS_HXX
 
 #include <sal/config.h>
+
+#include <memory>
+
 #include <sfx2/dllapi.h>
 #include <sal/types.h>
 #include <rtl/strbuf.hxx>
@@ -163,7 +166,7 @@ public:
     /**
      * @param rpState the caller has to delete the pointer
      */
-    SfxItemState     QueryState( sal_uInt16 nSID, SfxPoolItem* &rpState );
+    SfxItemState     QueryState( sal_uInt16 nSID, std::unique_ptr<SfxPoolItem> &rpState );
 
     const SfxPoolItem*  ExecuteSynchron( sal_uInt16 nSlot,
                                  const SfxPoolItem **pArgs = nullptr,
diff --git a/sc/source/ui/view/cellsh3.cxx b/sc/source/ui/view/cellsh3.cxx
index d2fd259..ff6822f 100644
--- a/sc/source/ui/view/cellsh3.cxx
+++ b/sc/source/ui/view/cellsh3.cxx
@@ -729,11 +729,9 @@ void ScCellShell::Execute( SfxRequest& rReq )
                     case FID_MERGE_TOGGLE:
                     {
                         bCenter = true;
-                        SfxPoolItem* pItem = nullptr;
+                        std::unique_ptr<SfxPoolItem> pItem;
                         if( rBindings.QueryState( nSlot, pItem ) >= SfxItemState::DEFAULT )
-                            bMerge = !static_cast< SfxBoolItem* >( pItem )->GetValue();
-
-                        delete pItem;
+                            bMerge = !static_cast< SfxBoolItem* >( pItem.get() )->GetValue();
                     }
                     break;
                 }
diff --git a/sc/source/ui/view/formatsh.cxx b/sc/source/ui/view/formatsh.cxx
index 7f19086..abd34e4 100644
--- a/sc/source/ui/view/formatsh.cxx
+++ b/sc/source/ui/view/formatsh.cxx
@@ -212,12 +212,11 @@ void ScFormatShell::GetStyleState( SfxItemSet& rSet )
 
             case SID_STYLE_UPDATE_BY_EXAMPLE:
             {
-                SfxPoolItem* pItem = nullptr;
+                std::unique_ptr<SfxPoolItem> pItem;
                 pTabViewShell->GetViewFrame()->GetBindings().QueryState(SID_STYLE_FAMILY, pItem);
-                SfxUInt16Item* pFamilyItem = dynamic_cast<SfxUInt16Item*>(pItem);
+                SfxUInt16Item* pFamilyItem = dynamic_cast<SfxUInt16Item*>(pItem.get());
 
                 bool bPage = pFamilyItem && SFX_STYLE_FAMILY_PAGE == SfxTemplate::NIdToSfxFamilyId(pFamilyItem->GetValue());
-                delete pItem;
 
                 if ( bProtected || bPage )
                     rSet.DisableItem( nSlotId );
@@ -229,11 +228,10 @@ void ScFormatShell::GetStyleState( SfxItemSet& rSet )
             case SID_STYLE_HIDE:
             case SID_STYLE_SHOW:
             {
-                SfxPoolItem* pItem = nullptr;
+                std::unique_ptr<SfxPoolItem> pItem;
                 pTabViewShell->GetViewFrame()->GetBindings().QueryState(SID_STYLE_FAMILY, pItem);
-                SfxUInt16Item* pFamilyItem = dynamic_cast<SfxUInt16Item*>(pItem);
+                SfxUInt16Item* pFamilyItem = dynamic_cast<SfxUInt16Item*>(pItem.get());
                 bool bPage = pFamilyItem && SFX_STYLE_FAMILY_PAGE == SfxTemplate::NIdToSfxFamilyId(pFamilyItem->GetValue());
-                delete pItem;
 
                 if ( bProtected && !bPage )
                     rSet.DisableItem( nSlotId );
diff --git a/sc/source/ui/view/viewutil.cxx b/sc/source/ui/view/viewutil.cxx
index 4f71d63..41df6e5 100644
--- a/sc/source/ui/view/viewutil.cxx
+++ b/sc/source/ui/view/viewutil.cxx
@@ -368,12 +368,11 @@ bool ScViewUtil::ExecuteCharMap( const SvxFontItem& rOldFont,
 bool ScViewUtil::IsFullScreen( SfxViewShell& rViewShell )
 {
     SfxBindings&    rBindings       = rViewShell.GetViewFrame()->GetBindings();
-    SfxPoolItem*    pItem           = nullptr;
+    std::unique_ptr<SfxPoolItem> pItem;
     bool            bIsFullScreen   = false;
 
     if (rBindings.QueryState( SID_WIN_FULLSCREEN, pItem ) >= SfxItemState::DEFAULT)
-        bIsFullScreen = static_cast< SfxBoolItem* >( pItem )->GetValue();
-    delete pItem;
+        bIsFullScreen = static_cast< SfxBoolItem* >( pItem.get() )->GetValue();
 
     return bIsFullScreen;
 }
diff --git a/sd/source/ui/view/drviewsf.cxx b/sd/source/ui/view/drviewsf.cxx
index d3e8276..15bb40e 100644
--- a/sd/source/ui/view/drviewsf.cxx
+++ b/sd/source/ui/view/drviewsf.cxx
@@ -488,9 +488,9 @@ void DrawViewShell::GetAttrState( SfxItemSet& rSet )
 
             case SID_STYLE_WATERCAN:
             {
-                SfxPoolItem* pItem = nullptr;
+                std::unique_ptr<SfxPoolItem> pItem;
                 GetViewFrame()->GetBindings().QueryState(SID_STYLE_FAMILY, pItem);
-                SfxUInt16Item* pFamilyItem = dynamic_cast<SfxUInt16Item*>(pItem);
+                SfxUInt16Item* pFamilyItem = dynamic_cast<SfxUInt16Item*>(pItem.get());
                 if (pFamilyItem && SfxTemplate::NIdToSfxFamilyId(pFamilyItem->GetValue()) == SD_STYLE_FAMILY_PSEUDO)
                     rSet.Put(SfxBoolItem(nWhich,false));
                 else
@@ -498,31 +498,28 @@ void DrawViewShell::GetAttrState( SfxItemSet& rSet )
                     SfxBoolItem aItem(nWhich, SD_MOD()->GetWaterCan());
                     aAllSet.Put( aItem, aItem.Which());
                 }
-                delete pItem;
             }
             break;
 
             case SID_STYLE_NEW:
             {
-                SfxPoolItem* pItem = nullptr;
+                std::unique_ptr<SfxPoolItem> pItem;
                 GetViewFrame()->GetBindings().QueryState(SID_STYLE_FAMILY, pItem);
-                SfxUInt16Item* pFamilyItem = dynamic_cast<SfxUInt16Item*>(pItem);
+                SfxUInt16Item* pFamilyItem = dynamic_cast<SfxUInt16Item*>(pItem.get());
                 if (pFamilyItem && SfxTemplate::NIdToSfxFamilyId(pFamilyItem->GetValue()) == SD_STYLE_FAMILY_PSEUDO)
                 {
                     rSet.DisableItem(nWhich);
                 }
-                delete pItem;
             }
             break;
 
             case SID_STYLE_DRAGHIERARCHIE:
             {
-                SfxPoolItem* pItem = nullptr;
+                std::unique_ptr<SfxPoolItem> pItem;
                 GetViewFrame()->GetBindings().QueryState(SID_STYLE_FAMILY, pItem);
-                SfxUInt16Item* pFamilyItem = dynamic_cast<SfxUInt16Item*>(pItem);
+                SfxUInt16Item* pFamilyItem = dynamic_cast<SfxUInt16Item*>(pItem.get());
                 if (pFamilyItem && SfxTemplate::NIdToSfxFamilyId(pFamilyItem->GetValue()) == SD_STYLE_FAMILY_PSEUDO)
                     rSet.DisableItem(nWhich);
-                delete pItem;
             }
             break;
 
@@ -531,9 +528,9 @@ void DrawViewShell::GetAttrState( SfxItemSet& rSet )
                 // It is not possible to create PseudoStyleSheets 'by Example';
                 // normal style sheets need a selected object for that
 
-                SfxPoolItem* pItem = nullptr;
+                std::unique_ptr<SfxPoolItem> pItem;
                 GetViewFrame()->GetBindings().QueryState(SID_STYLE_FAMILY, pItem);
-                SfxUInt16Item* pFamilyItem = dynamic_cast<SfxUInt16Item*>(pItem);
+                SfxUInt16Item* pFamilyItem = dynamic_cast<SfxUInt16Item*>(pItem.get());
                 if (pFamilyItem)
                 {
                     if (SfxTemplate::NIdToSfxFamilyId(pFamilyItem->GetValue()) == SD_STYLE_FAMILY_PSEUDO)
@@ -557,7 +554,6 @@ void DrawViewShell::GetAttrState( SfxItemSet& rSet )
                         rSet.DisableItem(nWhich);
                     }
                 }
-                delete pItem;
             }
             break;
 
diff --git a/sd/source/ui/view/outlnvsh.cxx b/sd/source/ui/view/outlnvsh.cxx
index 8acacd4..c81906b 100644
--- a/sd/source/ui/view/outlnvsh.cxx
+++ b/sd/source/ui/view/outlnvsh.cxx
@@ -1481,9 +1481,9 @@ void OutlineViewShell::GetAttrState( SfxItemSet& rSet )
 
             case SID_STYLE_EDIT:
             {
-                SfxPoolItem* pItem = nullptr;
+                std::unique_ptr<SfxPoolItem> pItem;
                 GetViewFrame()->GetBindings().QueryState(SID_STYLE_FAMILY, pItem);
-                SfxUInt16Item* pFamilyItem = dynamic_cast<SfxUInt16Item*>(pItem);
+                SfxUInt16Item* pFamilyItem = dynamic_cast<SfxUInt16Item*>(pItem.get());
                 if (pFamilyItem && SfxTemplate::NIdToSfxFamilyId(pFamilyItem->GetValue()) == SD_STYLE_FAMILY_PSEUDO)
                 {
                     SfxItemSet aSet(*rSet.GetPool(), SID_STATUS_LAYOUT, SID_STATUS_LAYOUT);
@@ -1495,7 +1495,6 @@ void OutlineViewShell::GetAttrState( SfxItemSet& rSet )
                         rSet.DisableItem(nWhich);
                     }
                 }
-                delete pItem;
             }
             break;
 
diff --git a/sfx2/source/control/bindings.cxx b/sfx2/source/control/bindings.cxx
index 5d13693..41b5194 100644
--- a/sfx2/source/control/bindings.cxx
+++ b/sfx2/source/control/bindings.cxx
@@ -1879,7 +1879,7 @@ void SfxBindings::StartUpdate_Impl( bool bComplete )
 
 
 
-SfxItemState SfxBindings::QueryState( sal_uInt16 nSlot, SfxPoolItem* &rpState )
+SfxItemState SfxBindings::QueryState( sal_uInt16 nSlot, std::unique_ptr<SfxPoolItem> &rpState )
 {
     css::uno::Reference< css::frame::XDispatch >  xDisp;
     SfxStateCache *pCache = GetStateCache( nSlot );
@@ -1923,7 +1923,6 @@ SfxItemState SfxBindings::QueryState( sal_uInt16 nSlot, SfxPoolItem* &rpState )
                 }
 
                 SfxItemState eState = SfxItemState::SET;
-                SfxPoolItem *pItem=nullptr;
                 BindDispatch_Impl *pBind = new BindDispatch_Impl( xDisp, aURL, pCache, pSlot );
                 pBind->acquire();
                 xDisp->addStatusListener( pBind, aURL );
@@ -1940,33 +1939,32 @@ SfxItemState SfxBindings::QueryState( sal_uInt16 nSlot, SfxPoolItem* &rpState )
                     {
                         bool bTemp = false;
                         aAny >>= bTemp ;
-                        pItem = new SfxBoolItem( nSlot, bTemp );
+                        rpState.reset(new SfxBoolItem( nSlot, bTemp ));
                     }
                     else if ( pType == ::cppu::UnoType< ::cppu::UnoUnsignedShortType >::get() )
                     {
                         sal_uInt16 nTemp = 0;
                         aAny >>= nTemp ;
-                        pItem = new SfxUInt16Item( nSlot, nTemp );
+                        rpState.reset(new SfxUInt16Item( nSlot, nTemp ));
                     }
                     else if ( pType == cppu::UnoType<sal_uInt32>::get() )
                     {
                         sal_uInt32 nTemp = 0;
                         aAny >>= nTemp ;
-                        pItem = new SfxUInt32Item( nSlot, nTemp );
+                        rpState.reset(new SfxUInt32Item( nSlot, nTemp ));
                     }
                     else if ( pType == cppu::UnoType<OUString>::get() )
                     {
                         OUString sTemp ;
                         aAny >>= sTemp ;
-                        pItem = new SfxStringItem( nSlot, sTemp );
+                        rpState.reset(new SfxStringItem( nSlot, sTemp ));
                     }
                     else
-                        pItem = new SfxVoidItem( nSlot );
+                        rpState.reset(new SfxVoidItem( nSlot ));
                 }
 
                 xDisp->removeStatusListener( pBind, aURL );
                 pBind->Release();
-                rpState = pItem;
                 if ( bDeleteCache )
                     DELETEZ( pCache );
                 return eState;
@@ -1983,11 +1981,11 @@ SfxItemState SfxBindings::QueryState( sal_uInt16 nSlot, SfxPoolItem* &rpState )
     {
         DBG_ASSERT( pItem, "SfxItemState::SET but no item!" );
         if ( pItem )
-            rpState = pItem->Clone();
+            rpState.reset(pItem->Clone());
     }
     else if ( eState == SfxItemState::DEFAULT && pItem )
     {
-        rpState = pItem->Clone();
+        rpState.reset(pItem->Clone());
     }
 
     return eState;
diff --git a/sfx2/source/menu/mnumgr.cxx b/sfx2/source/menu/mnumgr.cxx
index 908c366..00438ff 100644
--- a/sfx2/source/menu/mnumgr.cxx
+++ b/sfx2/source/menu/mnumgr.cxx
@@ -134,17 +134,16 @@ PopupMenu* InsertThesaurusSubmenu_Impl( SfxBindings* pBindings, Menu* pSVMenu )
     // build thesaurus sub menu if look-up string is available
 
     PopupMenu* pThesSubMenu = nullptr;
-    SfxPoolItem *pItem = nullptr;
+    std::unique_ptr<SfxPoolItem> pItem;
     pBindings->QueryState( SID_THES, pItem );
     OUString aThesLookUpStr;
-    SfxStringItem *pStrItem = dynamic_cast< SfxStringItem * >(pItem);
+    SfxStringItem *pStrItem = dynamic_cast< SfxStringItem * >(pItem.get());
     sal_Int32 nDelimPos = -1;
     if (pStrItem)
     {
         aThesLookUpStr = pStrItem->GetValue();
         nDelimPos = aThesLookUpStr.lastIndexOf( '#' );
     }
-    delete pItem;
     if ( !aThesLookUpStr.isEmpty() && nDelimPos != -1 )
     {
         // get synonym list for sub menu
diff --git a/sfx2/source/sidebar/ControllerItem.cxx b/sfx2/source/sidebar/ControllerItem.cxx
index ed4fa3b..d6243c8 100644
--- a/sfx2/source/sidebar/ControllerItem.cxx
+++ b/sfx2/source/sidebar/ControllerItem.cxx
@@ -164,10 +164,9 @@ bool ControllerItem::IsEnabled (SfxItemState eState) const
 
 void ControllerItem::RequestUpdate()
 {
-    SfxPoolItem* pState = nullptr;
+    std::unique_ptr<SfxPoolItem> pState;
     const SfxItemState eState (GetBindings().QueryState(GetId(), pState));
-    mrItemUpdateReceiver.NotifyItemUpdate(GetId(), eState, pState, IsEnabled(eState));
-    delete pState;
+    mrItemUpdateReceiver.NotifyItemUpdate(GetId(), eState, pState.get(), IsEnabled(eState));
 }
 
 void ControllerItem::NotifyFrameContextChange()
diff --git a/svx/source/dialog/rubydialog.cxx b/svx/source/dialog/rubydialog.cxx
index 6e30819..1dffa9b 100644
--- a/svx/source/dialog/rubydialog.cxx
+++ b/svx/source/dialog/rubydialog.cxx
@@ -326,10 +326,9 @@ bool SvxRubyDialog::Close()
 void SvxRubyDialog::Activate()
 {
     SfxModelessDialog::Activate();
-    SfxPoolItem* pState = nullptr;
+    std::unique_ptr<SfxPoolItem> pState;
     SfxItemState    eState = pBindings->QueryState( SID_STYLE_DESIGNER, pState );
-    bool bEnable = (eState < SfxItemState::DEFAULT) || !pState || !static_cast<SfxBoolItem*>(pState)->GetValue();
-    delete pState;
+    bool bEnable = (eState < SfxItemState::DEFAULT) || !pState || !static_cast<SfxBoolItem*>(pState.get())->GetValue();
     m_pStylistPB->Enable(bEnable);
     //get selection from current view frame
     SfxViewFrame* pCurFrm = SfxViewFrame::Current();
@@ -598,14 +597,13 @@ IMPL_LINK_NOARG_TYPED(SvxRubyDialog, CloseHdl_Impl, Button*, void)
 
 IMPL_LINK_NOARG_TYPED(SvxRubyDialog, StylistHdl_Impl, Button*, void)
 {
-    SfxPoolItem* pState = nullptr;
+    std::unique_ptr<SfxPoolItem> pState;
     SfxItemState eState = pBindings->QueryState(SID_STYLE_DESIGNER, pState);
-    if (eState <= SfxItemState::SET || !pState || !static_cast<SfxBoolItem*>(pState)->GetValue())
+    if (eState <= SfxItemState::SET || !pState || !static_cast<SfxBoolItem*>(pState.get())->GetValue())
     {
         pBindings->GetDispatcher()->Execute(SID_STYLE_DESIGNER,
                                             SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
     }
-    delete pState;
 }
 
 IMPL_LINK_TYPED(SvxRubyDialog, AdjustHdl_Impl, ListBox&, rBox, void)
diff --git a/svx/source/fmcomp/fmgridcl.cxx b/svx/source/fmcomp/fmgridcl.cxx
index 2de7905..2e5c50c 100644
--- a/svx/source/fmcomp/fmgridcl.cxx
+++ b/svx/source/fmcomp/fmgridcl.cxx
@@ -761,15 +761,14 @@ void FmGridHeader::PreExecuteColumnContextMenu(sal_uInt16 nColId, PopupMenu& rMe
         // ask the bindings of the current view frame (which should be the one we're residing in) for the state
         if (pCurrentFrame)
         {
-            SfxPoolItem* pItem = nullptr;
+            std::unique_ptr<SfxPoolItem> pItem;
             eState = pCurrentFrame->GetBindings().QueryState(SID_FM_CTL_PROPERTIES, pItem);
 
-            if (eState >= SfxItemState::DEFAULT && pItem )
+            if (eState >= SfxItemState::DEFAULT && pItem.get() != nullptr )
             {
-                bool bChecked = dynamic_cast<const SfxBoolItem*>( pItem) != nullptr && static_cast<SfxBoolItem*>(pItem)->GetValue();
+                bool bChecked = dynamic_cast<const SfxBoolItem*>( pItem.get()) != nullptr && static_cast<SfxBoolItem*>(pItem.get())->GetValue();
                 rMenu.CheckItem(SID_FM_SHOW_PROPERTY_BROWSER,bChecked);
             }
-            delete pItem;
         }
     }
 }
diff --git a/sw/source/uibase/app/docst.cxx b/sw/source/uibase/app/docst.cxx
index e29f9109..cdd704e 100644
--- a/sw/source/uibase/app/docst.cxx
+++ b/sw/source/uibase/app/docst.cxx
@@ -108,14 +108,13 @@ void  SwDocShell::StateStyleSheet(SfxItemSet& rSet, SwWrtShell* pSh)
     else
     {
         SfxViewFrame* pFrame = pShell->GetView().GetViewFrame();
-        SfxPoolItem* pItem = nullptr;
+        std::unique_ptr<SfxPoolItem> pItem;
         pFrame->GetBindings().QueryState(SID_STYLE_FAMILY, pItem);
-        SfxUInt16Item* pFamilyItem = dynamic_cast<SfxUInt16Item*>(pItem);
+        SfxUInt16Item* pFamilyItem = dynamic_cast<SfxUInt16Item*>(pItem.get());
         if (pFamilyItem)
         {
             nActualFamily = static_cast<sal_uInt16>(SfxTemplate::NIdToSfxFamilyId(pFamilyItem->GetValue()));
         }
-        delete pItem;
     }
 
     while (nWhich)
diff --git a/sw/source/uibase/docvw/romenu.cxx b/sw/source/uibase/docvw/romenu.cxx
index f7abc6a..c7de73d 100644
--- a/sw/source/uibase/docvw/romenu.cxx
+++ b/sw/source/uibase/docvw/romenu.cxx
@@ -59,16 +59,16 @@ SwReadOnlyPopup::~SwReadOnlyPopup()
 
 void SwReadOnlyPopup::Check( sal_uInt16 nMID, sal_uInt16 nSID, SfxDispatcher &rDis )
 {
-    SfxPoolItem *_pItem = nullptr;
+    std::unique_ptr<SfxPoolItem> _pItem;
     SfxItemState eState = rDis.GetBindings()->QueryState( nSID, _pItem );
     if (eState >= SfxItemState::DEFAULT)
     {
         EnableItem( nMID );
         if (_pItem)
         {
-            CheckItem ( nMID, dynamic_cast< const SfxVoidItem *>( _pItem ) ==  nullptr &&
-                            dynamic_cast< const SfxBoolItem *>( _pItem ) !=  nullptr &&
-                            static_cast<SfxBoolItem*>(_pItem)->GetValue());
+            CheckItem ( nMID, dynamic_cast< const SfxVoidItem *>( _pItem.get() ) ==  nullptr &&
+                            dynamic_cast< const SfxBoolItem *>( _pItem.get() ) !=  nullptr &&
+                            static_cast<SfxBoolItem*>(_pItem.get())->GetValue());
             //remove full screen entry when not in full screen mode
             if( SID_WIN_FULLSCREEN == nSID && !IsItemChecked(SID_WIN_FULLSCREEN) )
                 EnableItem(nMID, false);
@@ -76,8 +76,6 @@ void SwReadOnlyPopup::Check( sal_uInt16 nMID, sal_uInt16 nSID, SfxDispatcher &rD
     }
     else
         EnableItem( nMID, false );
-
-    delete _pItem;
 }
 
 SwReadOnlyPopup::SwReadOnlyPopup( const Point &rDPos, SwView &rV ) :
@@ -198,14 +196,12 @@ SwReadOnlyPopup::SwReadOnlyPopup( const Point &rDPos, SwView &rV ) :
     Check( MN_READONLY_OPENURL,         SID_OPENDOC,        rDis );
     Check( MN_READONLY_OPENURLNEW,      SID_OPENDOC,        rDis );
 
-    SfxPoolItem* pState = nullptr;
+    std::unique_ptr<SfxPoolItem> pState;
 
     SfxItemState eState = pVFrame->GetBindings().QueryState( SID_COPY, pState );
     Check( MN_READONLY_COPY,            SID_COPY,           rDis );
     if(eState < SfxItemState::DEFAULT)
         EnableItem( MN_READONLY_COPY, false );
-    delete pState;
-    pState = nullptr;
 
     eState = pVFrame->GetBindings().QueryState( SID_EDITDOC, pState );
     if (
@@ -215,7 +211,6 @@ SwReadOnlyPopup::SwReadOnlyPopup( const Point &rDPos, SwView &rV ) :
     {
         EnableItem( MN_READONLY_EDITDOC, false );
     }
-    delete pState;
 
     if ( sURL.isEmpty() )
     {


More information about the Libreoffice-commits mailing list