summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2015-12-08 18:57:32 +0100
committerStephan Bergmann <sbergman@redhat.com>2015-12-09 07:16:34 +0000
commit4754afddc3030347ef49b401a9b798cea8fe523c (patch)
treea7505da2dae9b8eae70ed463309521c11780d4c4 /sfx2
parent6fd3f3caad1a559165dc9332249cbd0d84930775 (diff)
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@libreoffice.org> Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/source/control/bindings.cxx18
-rw-r--r--sfx2/source/menu/mnumgr.cxx5
-rw-r--r--sfx2/source/sidebar/ControllerItem.cxx5
3 files changed, 12 insertions, 16 deletions
diff --git a/sfx2/source/control/bindings.cxx b/sfx2/source/control/bindings.cxx
index 5d1369315421..41b5194953fd 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 908c3667938a..00438ff78aff 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 ed4fa3b1f365..d6243c80ce22 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()