summaryrefslogtreecommitdiff
path: root/sfx2/source/control/bindings.cxx
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/source/control/bindings.cxx
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/source/control/bindings.cxx')
-rw-r--r--sfx2/source/control/bindings.cxx18
1 files changed, 8 insertions, 10 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;