cui/source/tabpages/page.cxx | 4 +- cui/source/tabpages/paragrph.cxx | 19 +++++--------- cui/source/tabpages/swpossizetabpage.cxx | 4 +- cui/source/tabpages/tparea.cxx | 42 +++++++++++++------------------ cui/source/tabpages/tpbitmap.cxx | 42 ++++++++++++++----------------- 5 files changed, 50 insertions(+), 61 deletions(-)
New commits: commit ee8f76a3e89c7070958a4c42b17818a0b90f3f0d Author: Takeshi Abe <t...@fixedpoint.jp> Date: Thu Jul 31 10:32:53 2014 +0900 Avoid possible memory leaks in case of exceptions Change-Id: I8bdb8ca84b75efde4effba1ce76704d2c7c3f214 diff --git a/cui/source/tabpages/page.cxx b/cui/source/tabpages/page.cxx index 76d2894..6c02b90 100644 --- a/cui/source/tabpages/page.cxx +++ b/cui/source/tabpages/page.cxx @@ -60,6 +60,7 @@ #include <svx/unobrushitemhelper.hxx> #include <numpages.hxx> +#include <boost/scoped_ptr.hpp> // static ---------------------------------------------------------------- @@ -874,7 +875,7 @@ bool SvxPageDescPage::FillItemSet( SfxItemSet* rSet ) (m_pRegisterCB->IsChecked() || m_pRegisterCB->IsValueChangedFromSaved())) { const SfxBoolItem& rRegItem = (const SfxBoolItem&)rOldSet.Get(SID_SWREGISTER_MODE); - SfxBoolItem* pRegItem = (SfxBoolItem*)rRegItem.Clone(); + boost::scoped_ptr<SfxBoolItem> pRegItem((SfxBoolItem*)rRegItem.Clone()); bool bCheck = m_pRegisterCB->IsChecked(); pRegItem->SetValue(bCheck); rSet->Put(*pRegItem); @@ -885,7 +886,6 @@ bool SvxPageDescPage::FillItemSet( SfxItemSet* rSet ) rSet->Put(SfxStringItem(SID_SWREGISTER_COLLECTION, m_pRegisterLB->GetSelectEntry())); } - delete pRegItem; } SvxFrameDirection eDirection = m_pTextFlowBox->GetSelectEntryValue(); diff --git a/cui/source/tabpages/paragrph.cxx b/cui/source/tabpages/paragrph.cxx index bbeb896..21dc407 100644 --- a/cui/source/tabpages/paragrph.cxx +++ b/cui/source/tabpages/paragrph.cxx @@ -51,6 +51,7 @@ #include <svl/eitem.hxx> #include <sfx2/request.hxx> #include <svl/intitem.hxx> +#include <boost/scoped_ptr.hpp> static const sal_uInt16 pStdRanges[] = { @@ -383,7 +384,7 @@ bool SvxStdParagraphTabPage::FillItemSet( SfxItemSet* rOutSet ) *rOutSet, SID_ATTR_PARA_REGISTER); if (!pBoolItem) return bModified; - SfxBoolItem* pRegItem = (SfxBoolItem*)pBoolItem->Clone(); + boost::scoped_ptr<SfxBoolItem> pRegItem((SfxBoolItem*)pBoolItem->Clone()); sal_uInt16 _nWhich = GetWhich( SID_ATTR_PARA_REGISTER ); bool bSet = pRegItem->GetValue(); @@ -395,7 +396,6 @@ bool SvxStdParagraphTabPage::FillItemSet( SfxItemSet* rOutSet ) } else if ( SFX_ITEM_DEFAULT == GetItemSet().GetItemState( _nWhich, false ) ) rOutSet->ClearItem(_nWhich); - delete pRegItem; } return bModified; @@ -2155,29 +2155,26 @@ bool SvxAsianTabPage::FillItemSet( SfxItemSet* rSet ) SfxItemPool* pPool = rSet->GetPool(); if (m_pScriptSpaceCB->IsEnabled() && m_pScriptSpaceCB->IsValueChangedFromSaved()) { - SfxBoolItem* pNewItem = (SfxBoolItem*)rSet->Get( - pPool->GetWhich(SID_ATTR_PARA_SCRIPTSPACE)).Clone(); + boost::scoped_ptr<SfxBoolItem> pNewItem((SfxBoolItem*)rSet->Get( + pPool->GetWhich(SID_ATTR_PARA_SCRIPTSPACE)).Clone()); pNewItem->SetValue(m_pScriptSpaceCB->IsChecked()); rSet->Put(*pNewItem); - delete pNewItem; bRet = true; } if (m_pHangingPunctCB->IsEnabled() && m_pHangingPunctCB->IsValueChangedFromSaved()) { - SfxBoolItem* pNewItem = (SfxBoolItem*)rSet->Get( - pPool->GetWhich(SID_ATTR_PARA_HANGPUNCTUATION)).Clone(); + boost::scoped_ptr<SfxBoolItem> pNewItem((SfxBoolItem*)rSet->Get( + pPool->GetWhich(SID_ATTR_PARA_HANGPUNCTUATION)).Clone()); pNewItem->SetValue(m_pHangingPunctCB->IsChecked()); rSet->Put(*pNewItem); - delete pNewItem; bRet = true; } if (m_pForbiddenRulesCB->IsEnabled() && m_pForbiddenRulesCB->IsValueChangedFromSaved()) { - SfxBoolItem* pNewItem = (SfxBoolItem*)rSet->Get( - pPool->GetWhich(SID_ATTR_PARA_FORBIDDEN_RULES)).Clone(); + boost::scoped_ptr<SfxBoolItem> pNewItem((SfxBoolItem*)rSet->Get( + pPool->GetWhich(SID_ATTR_PARA_FORBIDDEN_RULES)).Clone()); pNewItem->SetValue(m_pForbiddenRulesCB->IsChecked()); rSet->Put(*pNewItem); - delete pNewItem; bRet = true; } return bRet; diff --git a/cui/source/tabpages/swpossizetabpage.cxx b/cui/source/tabpages/swpossizetabpage.cxx index 666bc03..b471078 100644 --- a/cui/source/tabpages/swpossizetabpage.cxx +++ b/cui/source/tabpages/swpossizetabpage.cxx @@ -35,6 +35,7 @@ #include <com/sun/star/text/VertOrientation.hpp> #include <com/sun/star/text/RelOrientation.hpp> #include <svx/dialogs.hrc> +#include <boost/scoped_ptr.hpp> using namespace ::com::sun::star::text; #define SwFPos SvxSwFramePosString @@ -857,10 +858,9 @@ bool SvxSwPosSizeTabPage::FillItemSet( SfxItemSet* rSet) const SfxPoolItem* pItem = GetItem( rOldSet, SID_SW_FOLLOW_TEXT_FLOW); if(pItem) { - SfxBoolItem* pFollow = static_cast<SfxBoolItem*>(pItem->Clone()); + boost::scoped_ptr<SfxBoolItem> pFollow(static_cast<SfxBoolItem*>(pItem->Clone())); pFollow->SetValue(m_pFollowCB->IsChecked()); bModified |= 0 != rSet->Put(*pFollow); - delete pFollow; } } } diff --git a/cui/source/tabpages/tparea.cxx b/cui/source/tabpages/tparea.cxx index cc89a49..1b7a65e 100644 --- a/cui/source/tabpages/tparea.cxx +++ b/cui/source/tabpages/tparea.cxx @@ -44,6 +44,7 @@ //UUUU #include "sfx2/opengrf.hxx" #include <vcl/msgbox.hxx> +#include <boost/scoped_ptr.hpp> using namespace com::sun::star; @@ -1245,11 +1246,11 @@ bool SvxAreaTabPage::FillItemSet( SfxItemSet* rAttrs ) m_pTsbOriginal->IsEnabled() && m_pTsbScale->GetSavedValue() != TRISTATE_TRUE ) ) { - XFillBmpSizeLogItem* pItem = NULL; + boost::scoped_ptr<XFillBmpSizeLogItem> pItem; if( m_pTsbScale->IsEnabled() ) - pItem = new XFillBmpSizeLogItem( eState == TRISTATE_FALSE ); + pItem.reset(new XFillBmpSizeLogItem( eState == TRISTATE_FALSE )); else if( m_pTsbOriginal->IsEnabled() && m_pTsbOriginal->GetState() == TRISTATE_TRUE ) - pItem = new XFillBmpSizeLogItem( true ); + pItem.reset(new XFillBmpSizeLogItem( true )); if( pItem ) { @@ -1259,14 +1260,13 @@ bool SvxAreaTabPage::FillItemSet( SfxItemSet* rAttrs ) rAttrs->Put( *pItem ); bModified = true; } - delete pItem; } } //aMtrFldXSize OUString aStr = m_pMtrFldXSize->GetText(); { - XFillBmpSizeXItem* pItem = NULL; + boost::scoped_ptr<XFillBmpSizeXItem> pItem; TriState eScaleState = m_pTsbScale->GetState(); if( m_pMtrFldXSize->IsEnabled() && @@ -1274,18 +1274,18 @@ bool SvxAreaTabPage::FillItemSet( SfxItemSet* rAttrs ) aStr != m_pMtrFldXSize->GetSavedValue() ) { if( eScaleState == TRISTATE_FALSE ) - pItem = new XFillBmpSizeXItem( GetCoreValue( *m_pMtrFldXSize, ePoolUnit ) ); + pItem.reset(new XFillBmpSizeXItem( GetCoreValue( *m_pMtrFldXSize, ePoolUnit ) )); else { // Percentage values are set negatively, so that // they aren't scaled; this is considered in the item. - pItem = new XFillBmpSizeXItem( -labs( static_cast<long>(m_pMtrFldXSize->GetValue()) ) ); + pItem.reset(new XFillBmpSizeXItem( -labs( static_cast<long>(m_pMtrFldXSize->GetValue()) ) )); } } else if( m_pTsbOriginal->IsEnabled() && m_pTsbOriginal->GetState() == TRISTATE_TRUE && !m_pMtrFldXSize->GetSavedValue().isEmpty() ) - pItem = new XFillBmpSizeXItem( 0 ); + pItem.reset(new XFillBmpSizeXItem( 0 )); if( pItem ) { @@ -1295,14 +1295,13 @@ bool SvxAreaTabPage::FillItemSet( SfxItemSet* rAttrs ) rAttrs->Put( *pItem ); bModified = true; } - delete pItem; } } //aMtrFldYSize aStr = m_pMtrFldYSize->GetText(); { - XFillBmpSizeYItem* pItem = NULL; + boost::scoped_ptr<XFillBmpSizeYItem> pItem; TriState eScaleState = m_pTsbScale->GetState(); if( m_pMtrFldYSize->IsEnabled() && @@ -1310,19 +1309,19 @@ bool SvxAreaTabPage::FillItemSet( SfxItemSet* rAttrs ) aStr != m_pMtrFldYSize->GetSavedValue() ) { if( eScaleState == TRISTATE_FALSE ) - pItem = new XFillBmpSizeYItem( GetCoreValue( *m_pMtrFldYSize, ePoolUnit ) ); + pItem.reset(new XFillBmpSizeYItem( GetCoreValue( *m_pMtrFldYSize, ePoolUnit ) )); else { // Percentage values are set negatively, so that // they aren't scaled by the MetricItem; // this is considered in the item. - pItem = new XFillBmpSizeYItem( -labs( static_cast<long>(m_pMtrFldYSize->GetValue()) ) ); + pItem.reset(new XFillBmpSizeYItem( -labs( static_cast<long>(m_pMtrFldYSize->GetValue()) ) )); } } else if( m_pTsbOriginal->IsEnabled() && m_pTsbOriginal->GetState() == TRISTATE_TRUE && !m_pMtrFldYSize->GetSavedValue().isEmpty() ) - pItem = new XFillBmpSizeYItem( 0 ); + pItem.reset(new XFillBmpSizeYItem( 0 )); if( pItem ) { @@ -1332,7 +1331,6 @@ bool SvxAreaTabPage::FillItemSet( SfxItemSet* rAttrs ) rAttrs->Put( *pItem ); bModified = true; } - delete pItem; } } @@ -2262,17 +2260,15 @@ IMPL_LINK_NOARG(SvxAreaTabPage, ModifyTileHdl_Impl) if( m_pMtrFldXSize->IsEnabled() ) { - XFillBmpSizeXItem* pItem = NULL; + boost::scoped_ptr<XFillBmpSizeXItem> pItem; TriState eScaleState = m_pTsbScale->GetState(); if( eScaleState == TRISTATE_FALSE ) - pItem = new XFillBmpSizeXItem( GetCoreValue( *m_pMtrFldXSize, ePoolUnit ) ); + pItem.reset(new XFillBmpSizeXItem( GetCoreValue( *m_pMtrFldXSize, ePoolUnit ) )); else - pItem = new XFillBmpSizeXItem( -labs( static_cast<long>(m_pMtrFldXSize->GetValue()) ) ); + pItem.reset(new XFillBmpSizeXItem( -labs( static_cast<long>(m_pMtrFldXSize->GetValue()) ) )); rXFSet.Put( *pItem ); - - delete pItem; } else if( m_pTsbOriginal->IsEnabled() && m_pTsbOriginal->GetState() == TRISTATE_TRUE ) { @@ -2283,17 +2279,15 @@ IMPL_LINK_NOARG(SvxAreaTabPage, ModifyTileHdl_Impl) if( m_pMtrFldYSize->IsEnabled() ) { - XFillBmpSizeYItem* pItem = NULL; + boost::scoped_ptr<XFillBmpSizeYItem> pItem; TriState eScaleState = m_pTsbScale->GetState(); if( eScaleState == TRISTATE_FALSE ) - pItem = new XFillBmpSizeYItem( GetCoreValue( *m_pMtrFldYSize, ePoolUnit ) ); + pItem.reset(new XFillBmpSizeYItem( GetCoreValue( *m_pMtrFldYSize, ePoolUnit ) )); else - pItem = new XFillBmpSizeYItem( -labs( static_cast<long>(m_pMtrFldYSize->GetValue()) ) ); + pItem.reset(new XFillBmpSizeYItem( -labs( static_cast<long>(m_pMtrFldYSize->GetValue()) ) )); rXFSet.Put( *pItem ); - - delete pItem; } else if( m_pTsbOriginal->IsEnabled() && m_pTsbOriginal->GetState() == TRISTATE_TRUE ) { diff --git a/cui/source/tabpages/tpbitmap.cxx b/cui/source/tabpages/tpbitmap.cxx index c8d315b..85938a9 100644 --- a/cui/source/tabpages/tpbitmap.cxx +++ b/cui/source/tabpages/tpbitmap.cxx @@ -47,6 +47,7 @@ #include <dialmgr.hxx> #include "sfx2/opengrf.hxx" #include "paragrph.hrc" +#include <boost/scoped_ptr.hpp> using namespace com::sun::star; @@ -301,12 +302,12 @@ SfxTabPage* SvxBitmapTabPage::Create( Window* pWindow, IMPL_LINK_NOARG(SvxBitmapTabPage, ChangeBitmapHdl_Impl) { - GraphicObject* pGraphicObject = 0; + boost::scoped_ptr<GraphicObject> pGraphicObject; int nPos(m_pLbBitmaps->GetSelectEntryPos()); if(LISTBOX_ENTRY_NOTFOUND != nPos) { - pGraphicObject = new GraphicObject(pBitmapList->GetBitmap(nPos)->GetGraphicObject()); + pGraphicObject.reset(new GraphicObject(pBitmapList->GetBitmap(nPos)->GetGraphicObject())); } else { @@ -318,7 +319,7 @@ IMPL_LINK_NOARG(SvxBitmapTabPage, ChangeBitmapHdl_Impl) if((drawing::FillStyle_BITMAP == eXFS) && (SFX_ITEM_SET == rOutAttrs.GetItemState(GetWhich(XATTR_FILLBITMAP), true, &pPoolItem))) { - pGraphicObject = new GraphicObject(((const XFillBitmapItem*)pPoolItem)->GetGraphicObject()); + pGraphicObject.reset(new GraphicObject(((const XFillBitmapItem*)pPoolItem)->GetGraphicObject())); } } @@ -329,7 +330,7 @@ IMPL_LINK_NOARG(SvxBitmapTabPage, ChangeBitmapHdl_Impl) if(LISTBOX_ENTRY_NOTFOUND != nPos) { - pGraphicObject = new GraphicObject(pBitmapList->GetBitmap(nPos)->GetGraphicObject()); + pGraphicObject.reset(new GraphicObject(pBitmapList->GetBitmap(nPos)->GetGraphicObject())); } } } @@ -411,7 +412,6 @@ IMPL_LINK_NOARG(SvxBitmapTabPage, ChangeBitmapHdl_Impl) m_pCtlPreview->Invalidate(); bBmpChanged = false; - delete pGraphicObject; } return 0; @@ -428,10 +428,10 @@ long SvxBitmapTabPage::CheckChanges_Impl() { ResMgr& rMgr = CUI_MGR(); Image aWarningBoxImage = WarningBox::GetStandardImage(); - SvxMessDialog* aMessDlg = new SvxMessDialog(GetParentDialog(), + boost::scoped_ptr<SvxMessDialog> aMessDlg(new SvxMessDialog(GetParentDialog(), SVX_RES( RID_SVXSTR_BITMAP ), CUI_RES( RID_SVXSTR_ASK_CHANGE_BITMAP ), - &aWarningBoxImage ); + &aWarningBoxImage )); DBG_ASSERT(aMessDlg, "Dialog creation failed!"); aMessDlg->SetButtonText( MESS_BTN_1, ResId( RID_SVXSTR_CHANGE, rMgr ) ); aMessDlg->SetButtonText( MESS_BTN_2, ResId( RID_SVXSTR_ADD, rMgr ) ); @@ -456,7 +456,6 @@ long SvxBitmapTabPage::CheckChanges_Impl() case RET_CANCEL: break; } - delete aMessDlg; } } nPos = m_pLbBitmaps->GetSelectEntryPos(); @@ -492,9 +491,9 @@ IMPL_LINK_NOARG(SvxBitmapTabPage, ClickAddHdl_Impl) SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); DBG_ASSERT(pFact, "Dialog creation failed!"); - AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc ); + boost::scoped_ptr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc )); DBG_ASSERT(pDlg, "Dialog creation failed!"); - MessageDialog* pWarnBox = NULL; + boost::scoped_ptr<MessageDialog> pWarnBox; sal_uInt16 nError(1); while( pDlg->Execute() == RET_OK ) @@ -514,17 +513,17 @@ IMPL_LINK_NOARG(SvxBitmapTabPage, ClickAddHdl_Impl) if( !pWarnBox ) { - pWarnBox = new MessageDialog( GetParentDialog() + pWarnBox.reset(new MessageDialog( GetParentDialog() ,"DuplicateNameDialog" - ,"cui/ui/queryduplicatedialog.ui"); + ,"cui/ui/queryduplicatedialog.ui")); } if( pWarnBox->Execute() != RET_OK ) break; } - delete pDlg; - delete pWarnBox; + pDlg.reset(); + pWarnBox.reset(); if( !nError ) { @@ -594,14 +593,14 @@ IMPL_LINK_NOARG(SvxBitmapTabPage, ClickImportHdl_Impl) if( !nError ) { OUString aDesc( ResId(RID_SVXSTR_DESC_EXT_BITMAP, rMgr) ); - MessageDialog* pWarnBox = NULL; + boost::scoped_ptr<MessageDialog> pWarnBox; // convert file URL to UI name OUString aName; INetURLObject aURL( aDlg.GetPath() ); SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); DBG_ASSERT(pFact, "Dialog creation failed!"); - AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( GetParentDialog(), aURL.GetName().getToken( 0, '.' ), aDesc ); + boost::scoped_ptr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog( GetParentDialog(), aURL.GetName().getToken( 0, '.' ), aDesc )); DBG_ASSERT(pDlg, "Dialog creation failed!"); nError = 1; @@ -623,17 +622,17 @@ IMPL_LINK_NOARG(SvxBitmapTabPage, ClickImportHdl_Impl) if( !pWarnBox ) { - pWarnBox = new MessageDialog( GetParentDialog() + pWarnBox.reset(new MessageDialog( GetParentDialog() ,"DuplicateNameDialog" - ,"cui/ui/queryduplicatedialog.ui"); + ,"cui/ui/queryduplicatedialog.ui")); } if( pWarnBox->Execute() != RET_OK ) break; } - delete pDlg; - delete pWarnBox; + pDlg.reset(); + pWarnBox.reset(); if( !nError ) { @@ -674,7 +673,7 @@ IMPL_LINK_NOARG(SvxBitmapTabPage, ClickModifyHdl_Impl) SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); DBG_ASSERT(pFact, "Dialog creation failed!"); - AbstractSvxNameDialog* pDlg = pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc ); + boost::scoped_ptr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog( GetParentDialog(), aName, aDesc )); DBG_ASSERT(pDlg, "Dialog creation failed!"); long nCount = pBitmapList->Count(); @@ -719,7 +718,6 @@ IMPL_LINK_NOARG(SvxBitmapTabPage, ClickModifyHdl_Impl) aBox.Execute(); } } - delete pDlg; } return 0L; } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits