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