From 4754afddc3030347ef49b401a9b798cea8fe523c Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Tue, 8 Dec 2015 18:57:32 +0100 Subject: 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 Reviewed-by: Stephan Bergmann --- sfx2/source/control/bindings.cxx | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'sfx2/source/control/bindings.cxx') 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 &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::get() ) { sal_uInt32 nTemp = 0; aAny >>= nTemp ; - pItem = new SfxUInt32Item( nSlot, nTemp ); + rpState.reset(new SfxUInt32Item( nSlot, nTemp )); } else if ( pType == cppu::UnoType::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; -- cgit