diff options
author | Takeshi Abe <tabe@fixedpoint.jp> | 2014-06-05 14:10:15 +0900 |
---|---|---|
committer | Takeshi Abe <tabe@fixedpoint.jp> | 2014-06-05 15:36:35 +0900 |
commit | e0057072817ccad2a54eca45ffdb84d1c99ee7a7 (patch) | |
tree | bf7c4c41f586e2361f3fe630f45689fa2962dee8 /sw/source | |
parent | e6f8ec366bb9b565bc9fc14989b3c28af9693c0d (diff) |
Avoid possible memory leaks in case of exceptions
Change-Id: Ia8bc0e24a76dd953000b73806ac21f21db4c4ca3
Diffstat (limited to 'sw/source')
-rw-r--r-- | sw/source/uibase/dialog/regionsw.cxx | 14 | ||||
-rw-r--r-- | sw/source/uibase/dochdl/swdtflvr.cxx | 59 | ||||
-rw-r--r-- | sw/source/uibase/docvw/DashedLine.cxx | 6 | ||||
-rw-r--r-- | sw/source/uibase/docvw/HeaderFooterWin.cxx | 6 | ||||
-rw-r--r-- | sw/source/uibase/docvw/PageBreakWin.cxx | 6 | ||||
-rw-r--r-- | sw/source/uibase/docvw/PostItMgr.cxx | 5 | ||||
-rw-r--r-- | sw/source/uibase/docvw/SidebarTxtControl.cxx | 4 | ||||
-rw-r--r-- | sw/source/uibase/docvw/SidebarWin.cxx | 7 | ||||
-rw-r--r-- | sw/source/uibase/docvw/edtwin.cxx | 10 |
9 files changed, 54 insertions, 63 deletions
diff --git a/sw/source/uibase/dialog/regionsw.cxx b/sw/source/uibase/dialog/regionsw.cxx index 299c26c23f56..938c5525e5a4 100644 --- a/sw/source/uibase/dialog/regionsw.cxx +++ b/sw/source/uibase/dialog/regionsw.cxx @@ -83,12 +83,11 @@ void SwBaseShell::InsertRegionDialog(SfxRequest& rReq) aSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(nWidth, nWidth))); SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); OSL_ENSURE(pFact, "Dialogdiet fail!"); - AbstractInsertSectionTabDialog* aTabDlg = pFact->CreateInsertSectionTabDialog( - &GetView().GetViewFrame()->GetWindow(), aSet , rSh); + boost::scoped_ptr<AbstractInsertSectionTabDialog> aTabDlg(pFact->CreateInsertSectionTabDialog( + &GetView().GetViewFrame()->GetWindow(), aSet , rSh)); OSL_ENSURE(aTabDlg, "Dialogdiet fail!"); aTabDlg->Execute(); rReq.Ignore(); - delete aTabDlg; } else { @@ -194,13 +193,11 @@ IMPL_STATIC_LINK( SwWrtShell, InsertRegionDialog, SwSectionData*, pSect ) aSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(nWidth, nWidth))); SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); OSL_ENSURE(pFact, "Dialogdiet fail!"); - AbstractInsertSectionTabDialog* aTabDlg = pFact->CreateInsertSectionTabDialog( - &pThis->GetView().GetViewFrame()->GetWindow(),aSet , *pThis); + boost::scoped_ptr<AbstractInsertSectionTabDialog> aTabDlg(pFact->CreateInsertSectionTabDialog( + &pThis->GetView().GetViewFrame()->GetWindow(),aSet , *pThis)); OSL_ENSURE(aTabDlg, "Dialogdiet fail!"); aTabDlg->SetSectionData(*xSectionData); aTabDlg->Execute(); - - delete aTabDlg; } return 0; } @@ -222,14 +219,13 @@ void SwBaseShell::EditRegionDialog(SfxRequest& rReq) { SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); OSL_ENSURE(pFact, "Dialogdiet fail!"); - AbstractEditRegionDlg* pEditRegionDlg = pFact->CreateEditRegionDlg(pParentWin, rWrtShell); + boost::scoped_ptr<AbstractEditRegionDlg> pEditRegionDlg(pFact->CreateEditRegionDlg(pParentWin, rWrtShell)); OSL_ENSURE(pEditRegionDlg, "Dialogdiet fail!"); if(pItem && pItem->ISA(SfxStringItem)) { pEditRegionDlg->SelectSection(((const SfxStringItem*)pItem)->GetValue()); } pEditRegionDlg->Execute(); - delete pEditRegionDlg; } } break; diff --git a/sw/source/uibase/dochdl/swdtflvr.cxx b/sw/source/uibase/dochdl/swdtflvr.cxx index 572f51a47ed1..f34c1fab83e7 100644 --- a/sw/source/uibase/dochdl/swdtflvr.cxx +++ b/sw/source/uibase/dochdl/swdtflvr.cxx @@ -124,6 +124,7 @@ #include <vcl/GraphicNativeTransform.hxx> #include <vcl/GraphicNativeMetadata.hxx> +#include <boost/scoped_array.hpp> #include <boost/scoped_ptr.hpp> extern bool bFrmDrag; @@ -2632,14 +2633,14 @@ bool SwTransferable::_PasteDBData( TransferableDataHelper& rData, } else if( nWh ) { - SfxUsrAnyItem* pConnectionItem = 0; - SfxUsrAnyItem* pCursorItem = 0; - SfxUsrAnyItem* pColumnItem = 0; - SfxUsrAnyItem* pSourceItem = 0; - SfxUsrAnyItem* pCommandItem = 0; - SfxUsrAnyItem* pCommandTypeItem = 0; - SfxUsrAnyItem* pColumnNameItem = 0; - SfxUsrAnyItem* pSelectionItem = 0; + boost::scoped_ptr<SfxUsrAnyItem> pConnectionItem; + boost::scoped_ptr<SfxUsrAnyItem> pCursorItem; + boost::scoped_ptr<SfxUsrAnyItem> pColumnItem; + boost::scoped_ptr<SfxUsrAnyItem> pSourceItem; + boost::scoped_ptr<SfxUsrAnyItem> pCommandItem; + boost::scoped_ptr<SfxUsrAnyItem> pCommandTypeItem; + boost::scoped_ptr<SfxUsrAnyItem> pColumnNameItem; + boost::scoped_ptr<SfxUsrAnyItem> pSelectionItem; bool bDataAvailable = true; ODataAccessDescriptor aDesc; @@ -2652,14 +2653,14 @@ bool SwTransferable::_PasteDBData( TransferableDataHelper& rData, if ( bDataAvailable ) { - pConnectionItem = new SfxUsrAnyItem(FN_DB_CONNECTION_ANY, aDesc[daConnection]); - pColumnItem = new SfxUsrAnyItem(FN_DB_COLUMN_ANY, aDesc[daColumnObject]); - pSourceItem = new SfxUsrAnyItem(FN_DB_DATA_SOURCE_ANY, makeAny(aDesc.getDataSource())); - pCommandItem = new SfxUsrAnyItem(FN_DB_DATA_COMMAND_ANY, aDesc[daCommand]); - pCommandTypeItem = new SfxUsrAnyItem(FN_DB_DATA_COMMAND_TYPE_ANY, aDesc[daCommandType]); - pColumnNameItem = new SfxUsrAnyItem(FN_DB_DATA_COLUMN_NAME_ANY, aDesc[daColumnName]); - pSelectionItem = new SfxUsrAnyItem(FN_DB_DATA_SELECTION_ANY, aDesc[daSelection]); - pCursorItem = new SfxUsrAnyItem(FN_DB_DATA_CURSOR_ANY, aDesc[daCursor]); + pConnectionItem.reset(new SfxUsrAnyItem(FN_DB_CONNECTION_ANY, aDesc[daConnection])); + pColumnItem.reset(new SfxUsrAnyItem(FN_DB_COLUMN_ANY, aDesc[daColumnObject])); + pSourceItem.reset(new SfxUsrAnyItem(FN_DB_DATA_SOURCE_ANY, makeAny(aDesc.getDataSource()))); + pCommandItem.reset(new SfxUsrAnyItem(FN_DB_DATA_COMMAND_ANY, aDesc[daCommand])); + pCommandTypeItem.reset(new SfxUsrAnyItem(FN_DB_DATA_COMMAND_TYPE_ANY, aDesc[daCommandType])); + pColumnNameItem.reset(new SfxUsrAnyItem(FN_DB_DATA_COLUMN_NAME_ANY, aDesc[daColumnName])); + pSelectionItem.reset(new SfxUsrAnyItem(FN_DB_DATA_SELECTION_ANY, aDesc[daSelection])); + pCursorItem.reset(new SfxUsrAnyItem(FN_DB_DATA_CURSOR_ANY, aDesc[daCursor])); } SwView& rView = rSh.GetView(); @@ -2669,17 +2670,9 @@ bool SwTransferable::_PasteDBData( TransferableDataHelper& rData, SfxStringItem aDataDesc( nWh, sTxt ); rView.GetViewFrame()->GetDispatcher()->Execute( nWh, SFX_CALLMODE_ASYNCHRON, &aDataDesc, - pConnectionItem, pColumnItem, - pSourceItem, pCommandItem, pCommandTypeItem, - pColumnNameItem, pSelectionItem, pCursorItem,0L); - delete pConnectionItem; - delete pColumnItem; - delete pSourceItem; - delete pCommandItem; - delete pCommandTypeItem; - delete pColumnNameItem; - delete pSelectionItem; - delete pCursorItem; + pConnectionItem.get(), pColumnItem.get(), + pSourceItem.get(), pCommandItem.get(), pCommandTypeItem.get(), + pColumnNameItem.get(), pSelectionItem.get(), pCursorItem.get(), 0L); } else { @@ -3671,21 +3664,21 @@ bool SwTrnsfrDdeLink::WriteData( SvStream& rStrm ) pDocShell->GetTitle(SFX_TITLE_FULLNAME), eEncoding)); const OString aName(OUStringToOString(sName, eEncoding)); - sal_Char* pMem = new sal_Char[ aAppNm.getLength() + aTopic.getLength() + aName.getLength() + 4 ]; + boost::scoped_array<sal_Char> pMem(new sal_Char[ aAppNm.getLength() + aTopic.getLength() + aName.getLength() + 4 ]); sal_Int32 nLen = aAppNm.getLength(); - memcpy( pMem, aAppNm.getStr(), nLen ); + memcpy( pMem.get(), aAppNm.getStr(), nLen ); pMem[ nLen++ ] = 0; - memcpy( pMem + nLen, aTopic.getStr(), aTopic.getLength() ); + memcpy( pMem.get() + nLen, aTopic.getStr(), aTopic.getLength() ); nLen = nLen + aTopic.getLength(); pMem[ nLen++ ] = 0; - memcpy( pMem + nLen, aName.getStr(), aName.getLength() ); + memcpy( pMem.get() + nLen, aName.getStr(), aName.getLength() ); nLen = nLen + aName.getLength(); pMem[ nLen++ ] = 0; pMem[ nLen++ ] = 0; - rStrm.Write( pMem, nLen ); - delete[] pMem; + rStrm.Write( pMem.get(), nLen ); + pMem.reset(); IDocumentMarkAccess* const pMarkAccess = pDocShell->GetDoc()->getIDocumentMarkAccess(); IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->findMark(sName); diff --git a/sw/source/uibase/docvw/DashedLine.cxx b/sw/source/uibase/docvw/DashedLine.cxx index e9e343b3dc27..824e7c32c2b7 100644 --- a/sw/source/uibase/docvw/DashedLine.cxx +++ b/sw/source/uibase/docvw/DashedLine.cxx @@ -17,6 +17,7 @@ #include <drawinglayer/processor2d/processorfromoutputdevice.hxx> #include <vcl/svapp.hxx> #include <vcl/settings.hxx> +#include <boost/scoped_ptr.hpp> SwDashedLine::SwDashedLine( Window* pParent, Color& ( *pColorFn )() ) : FixedLine( pParent, WB_DIALOGCONTROL | WB_HORZ ), @@ -31,9 +32,9 @@ SwDashedLine::~SwDashedLine( ) void SwDashedLine::Paint( const Rectangle& ) { const drawinglayer::geometry::ViewInformation2D aNewViewInfos; - drawinglayer::processor2d::BaseProcessor2D * pProcessor = + boost::scoped_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor( drawinglayer::processor2d::createBaseProcessor2DFromOutputDevice( - *this, aNewViewInfos ); + *this, aNewViewInfos )); // Compute the start and end points const Rectangle aRect( Rectangle( Point( 0, 0 ), PixelToLogic( GetSizePixel() ) ) ); @@ -91,7 +92,6 @@ void SwDashedLine::Paint( const Rectangle& ) aSeq[ aSeq.getLength() - 1 ] = drawinglayer::primitive2d::Primitive2DReference( pLine ); pProcessor->process( aSeq ); - delete pProcessor; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/uibase/docvw/HeaderFooterWin.cxx b/sw/source/uibase/docvw/HeaderFooterWin.cxx index b68c59a194d8..17d95ffd7461 100644 --- a/sw/source/uibase/docvw/HeaderFooterWin.cxx +++ b/sw/source/uibase/docvw/HeaderFooterWin.cxx @@ -48,6 +48,7 @@ #include <vcl/menubtn.hxx> #include <vcl/svapp.hxx> #include <vcl/settings.hxx> +#include <boost/scoped_ptr.hpp> #define TEXT_PADDING 5 #define BOX_DISTANCE 10 @@ -351,9 +352,9 @@ void SwHeaderFooterWin::Paint( const Rectangle& ) // Create the processor and process the primitives const drawinglayer::geometry::ViewInformation2D aNewViewInfos; - drawinglayer::processor2d::BaseProcessor2D * pProcessor = + boost::scoped_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor( drawinglayer::processor2d::createBaseProcessor2DFromOutputDevice( - *this, aNewViewInfos ); + *this, aNewViewInfos )); // TODO Ghost it all if needed drawinglayer::primitive2d::Primitive2DSequence aGhostedSeq( 1 ); @@ -366,7 +367,6 @@ void SwHeaderFooterWin::Paint( const Rectangle& ) aSeq, aBColorModifier ) ); pProcessor->process( aGhostedSeq ); - delete pProcessor; } bool SwHeaderFooterWin::IsEmptyHeaderFooter( ) diff --git a/sw/source/uibase/docvw/PageBreakWin.cxx b/sw/source/uibase/docvw/PageBreakWin.cxx index 876961aab601..cba0d11cab24 100644 --- a/sw/source/uibase/docvw/PageBreakWin.cxx +++ b/sw/source/uibase/docvw/PageBreakWin.cxx @@ -41,6 +41,7 @@ #include <svl/stritem.hxx> #include <vcl/svapp.hxx> #include <vcl/settings.hxx> +#include <boost/scoped_ptr.hpp> #define BUTTON_WIDTH 30 #define BUTTON_HEIGHT 19 @@ -197,12 +198,11 @@ void SwPageBreakWin::Paint( const Rectangle& ) // Create the processor and process the primitives const drawinglayer::geometry::ViewInformation2D aNewViewInfos; - drawinglayer::processor2d::BaseProcessor2D * pProcessor = + boost::scoped_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor( drawinglayer::processor2d::createBaseProcessor2DFromOutputDevice( - *this, aNewViewInfos ); + *this, aNewViewInfos )); pProcessor->process( aGhostedSeq ); - delete pProcessor; } void SwPageBreakWin::Select( ) diff --git a/sw/source/uibase/docvw/PostItMgr.cxx b/sw/source/uibase/docvw/PostItMgr.cxx index e370f79e216f..4b6fd1d9c688 100644 --- a/sw/source/uibase/docvw/PostItMgr.cxx +++ b/sw/source/uibase/docvw/PostItMgr.cxx @@ -78,6 +78,7 @@ #include "swabstdlg.hxx" #include "swevent.hxx" #include "switerator.hxx" +#include <boost/scoped_ptr.hpp> // distance between Anchor Y and initial note position #define POSTIT_INITIAL_ANCHOR_DISTANCE 20 @@ -1270,14 +1271,14 @@ void SwPostItMgr::ExecuteFormatAllDialog(SwView& rView) SfxItemSet aDlgAttr(*pPool, EE_ITEMS_START, EE_ITEMS_END); aDlgAttr.Put(aEditAttr); SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create(); - SfxAbstractTabDialog* pDlg = pFact->CreateSwCharDlg(rView.GetWindow(), rView, aDlgAttr, DLG_CHAR_ANN); + boost::scoped_ptr<SfxAbstractTabDialog> pDlg(pFact->CreateSwCharDlg(rView.GetWindow(), rView, aDlgAttr, DLG_CHAR_ANN)); sal_uInt16 nRet = pDlg->Execute(); if (RET_OK == nRet) { aDlgAttr.Put(*pDlg->GetOutputItemSet()); FormatAll(aDlgAttr); } - delete pDlg; + pDlg.reset(); SetActiveSidebarWin(pOrigActiveWin); } diff --git a/sw/source/uibase/docvw/SidebarTxtControl.cxx b/sw/source/uibase/docvw/SidebarTxtControl.cxx index 5834c020832a..4d23b448e202 100644 --- a/sw/source/uibase/docvw/SidebarTxtControl.cxx +++ b/sw/source/uibase/docvw/SidebarTxtControl.cxx @@ -52,6 +52,7 @@ #include <wrtsh.hxx> #include <shellres.hxx> #include <SwRewriter.hxx> +#include <boost/scoped_ptr.hpp> namespace sw { namespace sidebarwindows { @@ -346,7 +347,7 @@ void SidebarTxtControl::Command( const CommandEvent& rCEvt ) } else { - SfxPopupMenuManager* pMgr = mrDocView.GetViewFrame()->GetDispatcher()->Popup(0, this,&rCEvt.GetMousePosPixel()); + boost::scoped_ptr<SfxPopupMenuManager> pMgr(mrDocView.GetViewFrame()->GetDispatcher()->Popup(0, this,&rCEvt.GetMousePosPixel())); ((PopupMenu*)pMgr->GetSVMenu())->SetSelectHdl( LINK(this, SidebarTxtControl, Select) ); { @@ -370,7 +371,6 @@ void SidebarTxtControl::Command( const CommandEvent& rCEvt ) //!! pointer created in the call to Popup. //!! Otherwise we would have a memory leak (see also #i107205#) pMgr->Execute( aPos, this ); - delete pMgr; } } else diff --git a/sw/source/uibase/docvw/SidebarWin.cxx b/sw/source/uibase/docvw/SidebarWin.cxx index 34aaa23243c7..3abc911a4e98 100644 --- a/sw/source/uibase/docvw/SidebarWin.cxx +++ b/sw/source/uibase/docvw/SidebarWin.cxx @@ -79,6 +79,7 @@ #include <drawinglayer/primitive2d/polygonprimitive2d.hxx> #include <drawinglayer/processor2d/processorfromoutputdevice.hxx> #include <drawinglayer/primitive2d/shadowprimitive2d.hxx> +#include <boost/scoped_ptr.hpp> namespace sw { namespace sidebarwindows { @@ -262,15 +263,15 @@ void SwSidebarWin::Draw(OutputDevice* pDev, const Point& rPt, const Size& rSz, s mpSidebarTxtControl->Draw(pDev, rPt, rSz, nInFlags); const drawinglayer::geometry::ViewInformation2D aNewViewInfos; - drawinglayer::processor2d::BaseProcessor2D * pProcessor = + boost::scoped_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor( drawinglayer::processor2d::createBaseProcessor2DFromOutputDevice( - *pDev, aNewViewInfos ); + *pDev, aNewViewInfos )); if (mpAnchor) pProcessor->process(mpAnchor->getOverlayObjectPrimitive2DSequence()); if (mpTextRangeOverlay) pProcessor->process(mpTextRangeOverlay->getOverlayObjectPrimitive2DSequence()); - delete pProcessor; + pProcessor.reset(); if (mpVScrollbar->IsVisible()) { diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx index c84e91f8e402..11521509fc67 100644 --- a/sw/source/uibase/docvw/edtwin.cxx +++ b/sw/source/uibase/docvw/edtwin.cxx @@ -145,6 +145,8 @@ #include "../../core/inc/rootfrm.hxx" #include <unotools/syslocaleoptions.hxx> +#include <boost/scoped_array.hpp> +#include <boost/scoped_ptr.hpp> using namespace sw::mark; using namespace ::com::sun::star; @@ -5099,7 +5101,7 @@ void SwEditWin::Command( const CommandEvent& rCEvt ) if ( m_rView.GetDocShell()->IsReadOnly() ) { - SwReadOnlyPopup* pROPopup = new SwReadOnlyPopup( aDocPos, m_rView ); + boost::scoped_ptr<SwReadOnlyPopup> pROPopup(new SwReadOnlyPopup( aDocPos, m_rView )); ui::ContextMenuExecuteEvent aEvent; aEvent.SourceWindow = VCLUnoHelper::GetInterface( this ); @@ -5118,7 +5120,6 @@ void SwEditWin::Command( const CommandEvent& rCEvt ) else pROPopup->Execute(this, aPixPos); } - delete pROPopup; } else if ( !m_rView.ExecSpellPopup( aDocPos ) ) GetView().GetViewFrame()->GetDispatcher()->ExecutePopup( 0, this, &aPixPos); @@ -5409,7 +5410,7 @@ void SwEditWin::Command( const CommandEvent& rCEvt ) } else { - Rectangle* aRects = new Rectangle[ nSize ]; + boost::scoped_array<Rectangle> aRects(new Rectangle[ nSize ]); int nRectIndex = 0; for ( SwIndex nIndex = rStart.nContent; nIndex < rEnd.nContent; ++nIndex ) { @@ -5419,8 +5420,7 @@ void SwEditWin::Command( const CommandEvent& rCEvt ) aRects[ nRectIndex ] = Rectangle( aRect.Left(), aRect.Top(), aRect.Right(), aRect.Bottom() ); ++nRectIndex; } - rWin.SetCompositionCharRect( aRects, nSize, bVertical ); - delete[] aRects; + rWin.SetCompositionCharRect( aRects.get(), nSize, bVertical ); } } bCallBase = false; |