Kaydet (Commit) c260abe3 authored tarafından Takeshi Abe's avatar Takeshi Abe

Avoid possible memory leaks in case of exceptions

Change-Id: I27a0c3639c346720df471ffa3940783565c47f7d
üst f8cd68ba
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
#include <vcl/svapp.hxx> #include <vcl/svapp.hxx>
#include <vcl/settings.hxx> #include <vcl/settings.hxx>
#include "dlgunit.hxx" #include "dlgunit.hxx"
#include <boost/scoped_ptr.hpp>
#define SELF_TARGET "_self" #define SELF_TARGET "_self"
#define IMAP_ALL_FILTER OUString("<Alle>") #define IMAP_ALL_FILTER OUString("<Alle>")
...@@ -484,7 +485,7 @@ void SvxIMapDlg::DoOpen() ...@@ -484,7 +485,7 @@ void SvxIMapDlg::DoOpen()
{ {
INetURLObject aURL( aDlg.GetPath() ); INetURLObject aURL( aDlg.GetPath() );
DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" ); DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ ); boost::scoped_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ ));
if( pIStm ) if( pIStm )
{ {
...@@ -497,8 +498,6 @@ void SvxIMapDlg::DoOpen() ...@@ -497,8 +498,6 @@ void SvxIMapDlg::DoOpen()
} }
else else
pIMapWnd->SetImageMap( aLoadIMap ); pIMapWnd->SetImageMap( aLoadIMap );
delete pIStm;
} }
pIMapWnd->Invalidate(); pIMapWnd->Invalidate();
...@@ -561,7 +560,7 @@ bool SvxIMapDlg::DoSave() ...@@ -561,7 +560,7 @@ bool SvxIMapDlg::DoSave()
if( aURL.getExtension().isEmpty() ) if( aURL.getExtension().isEmpty() )
aURL.setExtension( aExt ); aURL.setExtension( aExt );
SvStream* pOStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE | STREAM_TRUNC ); boost::scoped_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE | STREAM_TRUNC ));
if( pOStm ) if( pOStm )
{ {
pIMapWnd->GetImageMap().Write( *pOStm, nFormat, "" ); pIMapWnd->GetImageMap().Write( *pOStm, nFormat, "" );
...@@ -569,7 +568,7 @@ bool SvxIMapDlg::DoSave() ...@@ -569,7 +568,7 @@ bool SvxIMapDlg::DoSave()
if( pOStm->GetError() ) if( pOStm->GetError() )
ErrorHandler::HandleError( ERRCODE_IO_GENERAL ); ErrorHandler::HandleError( ERRCODE_IO_GENERAL );
delete pOStm; pOStm.reset();
pModel->SetChanged( bChanged ); pModel->SetChanged( bChanged );
bRet = true; bRet = true;
} }
......
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
#include <svx/svxdlg.hxx> #include <svx/svxdlg.hxx>
#include <basegfx/point/b2dpoint.hxx> #include <basegfx/point/b2dpoint.hxx>
#include <basegfx/polygon/b2dpolygon.hxx> #include <basegfx/polygon/b2dpolygon.hxx>
#include <boost/scoped_ptr.hpp>
using ::com::sun::star::frame::XFrame; using ::com::sun::star::frame::XFrame;
using ::com::sun::star::uno::Reference; using ::com::sun::star::uno::Reference;
...@@ -643,7 +644,7 @@ void IMapWindow::DoMacroAssign() ...@@ -643,7 +644,7 @@ void IMapWindow::DoMacroAssign()
aSet.Put( aMacroItem, SID_ATTR_MACROITEM ); aSet.Put( aMacroItem, SID_ATTR_MACROITEM );
SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
SfxAbstractDialog* pMacroDlg = pFact->CreateSfxDialog( this, aSet, mxDocumentFrame, SID_EVENTCONFIG ); boost::scoped_ptr<SfxAbstractDialog> pMacroDlg(pFact->CreateSfxDialog( this, aSet, mxDocumentFrame, SID_EVENTCONFIG ));
if ( pMacroDlg && pMacroDlg->Execute() == RET_OK ) if ( pMacroDlg && pMacroDlg->Execute() == RET_OK )
{ {
...@@ -652,8 +653,6 @@ void IMapWindow::DoMacroAssign() ...@@ -652,8 +653,6 @@ void IMapWindow::DoMacroAssign()
pModel->SetChanged( true ); pModel->SetChanged( true );
UpdateInfo( false ); UpdateInfo( false );
} }
delete pMacroDlg;
} }
} }
...@@ -667,8 +666,8 @@ void IMapWindow::DoPropertyDialog() ...@@ -667,8 +666,8 @@ void IMapWindow::DoPropertyDialog()
SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
if(pFact) if(pFact)
{ {
AbstractURLDlg* aDlg = pFact->CreateURLDialog( this, pIMapObj->GetURL(), pIMapObj->GetAltText(), pIMapObj->GetDesc(), boost::scoped_ptr<AbstractURLDlg> aDlg(pFact->CreateURLDialog( this, pIMapObj->GetURL(), pIMapObj->GetAltText(), pIMapObj->GetDesc(),
pIMapObj->GetTarget(), pIMapObj->GetName(), aTargetList ); pIMapObj->GetTarget(), pIMapObj->GetName(), aTargetList ));
DBG_ASSERT(aDlg, "Dialogdiet fail!"); DBG_ASSERT(aDlg, "Dialogdiet fail!");
if ( aDlg->Execute() == RET_OK ) if ( aDlg->Execute() == RET_OK )
{ {
...@@ -690,7 +689,6 @@ void IMapWindow::DoPropertyDialog() ...@@ -690,7 +689,6 @@ void IMapWindow::DoPropertyDialog()
pModel->SetChanged( true ); pModel->SetChanged( true );
UpdateInfo( true ); UpdateInfo( true );
} }
delete aDlg;
} }
} }
} }
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "svx/dlgutil.hxx" #include "svx/dlgutil.hxx"
#include <vcl/builder.hxx> #include <vcl/builder.hxx>
#include <vcl/settings.hxx> #include <vcl/settings.hxx>
#include <boost/scoped_ptr.hpp>
SvxXMeasurePreview::SvxXMeasurePreview( Window* pParent, WinBits nStyle) SvxXMeasurePreview::SvxXMeasurePreview( Window* pParent, WinBits nStyle)
: Control(pParent, nStyle) : Control(pParent, nStyle)
...@@ -110,21 +111,21 @@ void SvxXMeasurePreview::MouseButtonDown( const MouseEvent& rMEvt ) ...@@ -110,21 +111,21 @@ void SvxXMeasurePreview::MouseButtonDown( const MouseEvent& rMEvt )
MapMode aMapMode = GetMapMode(); MapMode aMapMode = GetMapMode();
Fraction aXFrac = aMapMode.GetScaleX(); Fraction aXFrac = aMapMode.GetScaleX();
Fraction aYFrac = aMapMode.GetScaleY(); Fraction aYFrac = aMapMode.GetScaleY();
Fraction* pMultFrac; boost::scoped_ptr<Fraction> pMultFrac;
if( bZoomIn ) if( bZoomIn )
{ {
if( bCtrl ) if( bCtrl )
pMultFrac = new Fraction( 3, 2 ); pMultFrac.reset(new Fraction( 3, 2 ));
else else
pMultFrac = new Fraction( 11, 10 ); pMultFrac.reset(new Fraction( 11, 10 ));
} }
else else
{ {
if( bCtrl ) if( bCtrl )
pMultFrac = new Fraction( 2, 3 ); pMultFrac.reset(new Fraction( 2, 3 ));
else else
pMultFrac = new Fraction( 10, 11 ); pMultFrac.reset(new Fraction( 10, 11 ));
} }
aXFrac *= *pMultFrac; aXFrac *= *pMultFrac;
...@@ -149,7 +150,6 @@ void SvxXMeasurePreview::MouseButtonDown( const MouseEvent& rMEvt ) ...@@ -149,7 +150,6 @@ void SvxXMeasurePreview::MouseButtonDown( const MouseEvent& rMEvt )
Invalidate(); Invalidate();
} }
delete pMultFrac;
} }
} }
......
...@@ -67,6 +67,8 @@ ...@@ -67,6 +67,8 @@
#include <tools/resary.hxx> #include <tools/resary.hxx>
#include <svx/svxdlg.hxx> #include <svx/svxdlg.hxx>
#include <vcl/toolbox.hxx> #include <vcl/toolbox.hxx>
#include <boost/scoped_array.hpp>
#include <boost/scoped_ptr.hpp>
using namespace com::sun::star::i18n; using namespace com::sun::star::i18n;
using namespace com::sun::star::uno; using namespace com::sun::star::uno;
...@@ -1285,11 +1287,11 @@ IMPL_LINK( SvxSearchDialog, CommandHdl_Impl, Button *, pBtn ) ...@@ -1285,11 +1287,11 @@ IMPL_LINK( SvxSearchDialog, CommandHdl_Impl, Button *, pBtn )
SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
if(pFact) if(pFact)
{ {
AbstractSvxSearchSimilarityDialog* pDlg = pFact->CreateSvxSearchSimilarityDialog( this, boost::scoped_ptr<AbstractSvxSearchSimilarityDialog> pDlg(pFact->CreateSvxSearchSimilarityDialog( this,
pSearchItem->IsLEVRelaxed(), pSearchItem->IsLEVRelaxed(),
pSearchItem->GetLEVOther(), pSearchItem->GetLEVOther(),
pSearchItem->GetLEVShorter(), pSearchItem->GetLEVShorter(),
pSearchItem->GetLEVLonger() ); pSearchItem->GetLEVLonger() ));
DBG_ASSERT(pDlg, "Dialogdiet fail!"); DBG_ASSERT(pDlg, "Dialogdiet fail!");
if ( pDlg && pDlg->Execute() == RET_OK ) if ( pDlg && pDlg->Execute() == RET_OK )
{ {
...@@ -1299,7 +1301,6 @@ IMPL_LINK( SvxSearchDialog, CommandHdl_Impl, Button *, pBtn ) ...@@ -1299,7 +1301,6 @@ IMPL_LINK( SvxSearchDialog, CommandHdl_Impl, Button *, pBtn )
pSearchItem->SetLEVLonger( pDlg->GetLonger() ); pSearchItem->SetLEVLonger( pDlg->GetLonger() );
SaveToModule_Impl(); SaveToModule_Impl();
} }
delete pDlg;
} }
} }
else if (pBtn == m_pJapOptionsBtn) else if (pBtn == m_pJapOptionsBtn)
...@@ -1309,8 +1310,8 @@ IMPL_LINK( SvxSearchDialog, CommandHdl_Impl, Button *, pBtn ) ...@@ -1309,8 +1310,8 @@ IMPL_LINK( SvxSearchDialog, CommandHdl_Impl, Button *, pBtn )
SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
if(pFact) if(pFact)
{ {
AbstractSvxJSearchOptionsDialog* aDlg = pFact->CreateSvxJSearchOptionsDialog( this, aSet, boost::scoped_ptr<AbstractSvxJSearchOptionsDialog> aDlg(pFact->CreateSvxJSearchOptionsDialog( this, aSet,
pSearchItem->GetTransliterationFlags() ); pSearchItem->GetTransliterationFlags() ));
DBG_ASSERT(aDlg, "Dialogdiet fail!"); DBG_ASSERT(aDlg, "Dialogdiet fail!");
int nRet = aDlg->Execute(); int nRet = aDlg->Execute();
if (RET_OK == nRet) //! true only if FillItemSet of SvxJSearchOptionsPage returns true if (RET_OK == nRet) //! true only if FillItemSet of SvxJSearchOptionsPage returns true
...@@ -1319,7 +1320,6 @@ IMPL_LINK( SvxSearchDialog, CommandHdl_Impl, Button *, pBtn ) ...@@ -1319,7 +1320,6 @@ IMPL_LINK( SvxSearchDialog, CommandHdl_Impl, Button *, pBtn )
pSearchItem->SetTransliterationFlags( nFlags ); pSearchItem->SetTransliterationFlags( nFlags );
ApplyTransliterationFlags_Impl( nFlags ); ApplyTransliterationFlags_Impl( nFlags );
} }
delete aDlg;
} }
} }
else if (pBtn == m_pSearchComponent1PB || pBtn == m_pSearchComponent2PB) else if (pBtn == m_pSearchComponent1PB || pBtn == m_pSearchComponent2PB)
...@@ -1850,7 +1850,7 @@ IMPL_LINK_NOARG(SvxSearchDialog, FormatHdl_Impl) ...@@ -1850,7 +1850,7 @@ IMPL_LINK_NOARG(SvxSearchDialog, FormatHdl_Impl)
while( *pTmp ) while( *pTmp )
pTmp++; pTmp++;
nCnt = pTmp - pPtr + 7; nCnt = pTmp - pPtr + 7;
sal_uInt16* pWhRanges = new sal_uInt16[nCnt]; boost::scoped_array<sal_uInt16> pWhRanges(new sal_uInt16[nCnt]);
sal_uInt16 nPos = 0; sal_uInt16 nPos = 0;
while( *pPtr ) while( *pPtr )
...@@ -1868,7 +1868,7 @@ IMPL_LINK_NOARG(SvxSearchDialog, FormatHdl_Impl) ...@@ -1868,7 +1868,7 @@ IMPL_LINK_NOARG(SvxSearchDialog, FormatHdl_Impl)
pWhRanges[nPos++] = SID_PARA_BACKGRND_DESTINATION; pWhRanges[nPos++] = SID_PARA_BACKGRND_DESTINATION;
pWhRanges[nPos] = 0; pWhRanges[nPos] = 0;
SfxItemPool& rPool = pSh->GetPool(); SfxItemPool& rPool = pSh->GetPool();
SfxItemSet aSet( rPool, pWhRanges ); SfxItemSet aSet( rPool, pWhRanges.get() );
OUString aTxt; OUString aTxt;
aSet.InvalidateAllItems(); aSet.InvalidateAllItems();
...@@ -1893,7 +1893,7 @@ IMPL_LINK_NOARG(SvxSearchDialog, FormatHdl_Impl) ...@@ -1893,7 +1893,7 @@ IMPL_LINK_NOARG(SvxSearchDialog, FormatHdl_Impl)
SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
if(pFact) if(pFact)
{ {
SfxAbstractTabDialog* pDlg = pFact->CreateTabItemDialog(this, aSet); boost::scoped_ptr<SfxAbstractTabDialog> pDlg(pFact->CreateTabItemDialog(this, aSet));
DBG_ASSERT(pDlg, "Dialogdiet fail!"); DBG_ASSERT(pDlg, "Dialogdiet fail!");
aTxt = pDlg->GetText() + aTxt; aTxt = pDlg->GetText() + aTxt;
pDlg->SetText( aTxt ); pDlg->SetText( aTxt );
...@@ -1922,9 +1922,7 @@ IMPL_LINK_NOARG(SvxSearchDialog, FormatHdl_Impl) ...@@ -1922,9 +1922,7 @@ IMPL_LINK_NOARG(SvxSearchDialog, FormatHdl_Impl)
PaintAttrText_Impl(); // Set AttributText in GroupBox PaintAttrText_Impl(); // Set AttributText in GroupBox
} }
delete pDlg;
} }
delete[] pWhRanges;
return 0; return 0;
} }
...@@ -1979,10 +1977,9 @@ IMPL_LINK_NOARG(SvxSearchDialog, AttributeHdl_Impl) ...@@ -1979,10 +1977,9 @@ IMPL_LINK_NOARG(SvxSearchDialog, AttributeHdl_Impl)
SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
if(pFact) if(pFact)
{ {
VclAbstractDialog* pDlg = pFact->CreateSvxSearchAttributeDialog( this, *pSearchList, pImpl->pRanges ); boost::scoped_ptr<VclAbstractDialog> pDlg(pFact->CreateSvxSearchAttributeDialog( this, *pSearchList, pImpl->pRanges ));
DBG_ASSERT(pDlg, "Dialogdiet fail!"); DBG_ASSERT(pDlg, "Dialogdiet fail!");
pDlg->Execute(); pDlg->Execute();
delete pDlg;
} }
PaintAttrText_Impl(); PaintAttrText_Impl();
return 0; return 0;
......
...@@ -72,6 +72,7 @@ ...@@ -72,6 +72,7 @@
#include <vcl/settings.hxx> #include <vcl/settings.hxx>
#include <math.h> #include <math.h>
#include <boost/scoped_ptr.hpp>
using namespace ::com::sun::star::uno; using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::view; using namespace ::com::sun::star::view;
...@@ -859,11 +860,10 @@ void FmGridHeader::PostExecuteColumnContextMenu(sal_uInt16 nColId, const PopupMe ...@@ -859,11 +860,10 @@ void FmGridHeader::PostExecuteColumnContextMenu(sal_uInt16 nColId, const PopupMe
SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
if(pFact) if(pFact)
{ {
AbstractFmShowColsDialog* pDlg = pFact->CreateFmShowColsDialog(NULL); boost::scoped_ptr<AbstractFmShowColsDialog> pDlg(pFact->CreateFmShowColsDialog(NULL));
DBG_ASSERT(pDlg, "Dialogdiet fail!"); DBG_ASSERT(pDlg, "Dialogdiet fail!");
pDlg->SetColumns(xCols); pDlg->SetColumns(xCols);
pDlg->Execute(); pDlg->Execute();
delete pDlg;
} }
} }
......
...@@ -78,7 +78,7 @@ void SwWrtShell::Insert(SwField &rFld) ...@@ -78,7 +78,7 @@ void SwWrtShell::Insert(SwField &rFld)
StartUndo(UNDO_INSERT, &aRewriter); StartUndo(UNDO_INSERT, &aRewriter);
bool bDeleted = false; bool bDeleted = false;
const SwPaM* pAnnotationTextRange = NULL; boost::scoped_ptr<SwPaM> pAnnotationTextRange;
if ( HasSelection() ) if ( HasSelection() )
{ {
if ( rFld.GetTyp()->Which() == RES_POSTITFLD ) if ( rFld.GetTyp()->Which() == RES_POSTITFLD )
...@@ -96,13 +96,13 @@ void SwWrtShell::Insert(SwField &rFld) ...@@ -96,13 +96,13 @@ void SwWrtShell::Insert(SwField &rFld)
EndPara(); EndPara();
} }
const SwPosition rEndPos( *GetCurrentShellCursor().GetPoint() ); const SwPosition rEndPos( *GetCurrentShellCursor().GetPoint() );
pAnnotationTextRange = new SwPaM( rStartPos, rEndPos ); pAnnotationTextRange.reset(new SwPaM( rStartPos, rEndPos ));
} }
else else
{ {
NormalizePam( false ); NormalizePam( false );
const SwPaM& rCurrPaM = GetCurrentShellCursor(); const SwPaM& rCurrPaM = GetCurrentShellCursor();
pAnnotationTextRange = new SwPaM( *rCurrPaM.GetPoint(), *rCurrPaM.GetMark() ); pAnnotationTextRange.reset(new SwPaM( *rCurrPaM.GetPoint(), *rCurrPaM.GetMark() ));
ClearMark(); ClearMark();
} }
} }
...@@ -114,14 +114,14 @@ void SwWrtShell::Insert(SwField &rFld) ...@@ -114,14 +114,14 @@ void SwWrtShell::Insert(SwField &rFld)
SwEditShell::Insert2(rFld, bDeleted); SwEditShell::Insert2(rFld, bDeleted);
if ( pAnnotationTextRange != NULL ) if ( pAnnotationTextRange )
{ {
if ( GetDoc() != NULL ) if ( GetDoc() != NULL )
{ {
IDocumentMarkAccess* pMarksAccess = GetDoc()->getIDocumentMarkAccess(); IDocumentMarkAccess* pMarksAccess = GetDoc()->getIDocumentMarkAccess();
pMarksAccess->makeAnnotationMark( *pAnnotationTextRange, ::rtl::OUString() ); pMarksAccess->makeAnnotationMark( *pAnnotationTextRange, ::rtl::OUString() );
} }
delete pAnnotationTextRange; pAnnotationTextRange.reset();
} }
EndUndo(); EndUndo();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment