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

Avoid possible memory leaks in case of exceptions

Change-Id: Iaf672463cf51d596148822d9b5effe5ab40f70d4
üst 06b63d3d
......@@ -40,6 +40,7 @@
#include <globals.hrc>
#include <misc.hrc>
#include <boost/scoped_ptr.hpp>
using namespace ::com::sun::star;
......@@ -143,7 +144,7 @@ SfxTabPage* SwFootNotePage::Create(Window *pParent, const SfxItemSet &rSet)
void SwFootNotePage::Reset(const SfxItemSet &rSet)
{
// if no example exists, otherwise Init here in Activate
SwPageFtnInfo* pDefFtnInfo = 0;
boost::scoped_ptr<SwPageFtnInfo> pDefFtnInfo;
const SwPageFtnInfo* pFtnInfo;
const SfxPoolItem* pItem = SfxTabPage::GetItem(rSet, FN_PARAM_FTN_INFO);
if( pItem )
......@@ -154,8 +155,8 @@ void SwFootNotePage::Reset(const SfxItemSet &rSet)
{
// when "standard" is being activated the footnote item is deleted,
// that's why a footnote structure has to be created here
pDefFtnInfo = new SwPageFtnInfo();
pFtnInfo = pDefFtnInfo;
pDefFtnInfo.reset(new SwPageFtnInfo());
pFtnInfo = pDefFtnInfo.get();
}
// footnote area's height
SwTwips lHeight = pFtnInfo->GetHeight();
......@@ -250,7 +251,6 @@ void SwFootNotePage::Reset(const SfxItemSet &rSet)
m_pLineDistEdit->SetValue(
m_pLineDistEdit->Normalize(pFtnInfo->GetBottomDist()), FUNIT_TWIP);
ActivatePage( rSet );
delete pDefFtnInfo;
}
// stuff attributes into the set, when OK
......
......@@ -39,6 +39,7 @@
#include <node.hxx>
#include <tblsel.hxx>
#include <sfx2/request.hxx>
#include <boost/scoped_ptr.hpp>
static bool bCheck1 = true;
static bool bCheck2 = false;
......@@ -368,16 +369,14 @@ IMPL_LINK_NOARG(SwSortDlg, DelimCharHdl)
{
SfxAllItemSet aSet( rSh.GetAttrPool() );
aSet.Put( SfxInt32Item( SID_ATTR_CHAR, GetDelimChar() ) );
SfxAbstractDialog* pMap = pFact->CreateSfxDialog( m_pDelimPB, aSet,
rSh.GetView().GetViewFrame()->GetFrame().GetFrameInterface(), RID_SVXDLG_CHARMAP );
boost::scoped_ptr<SfxAbstractDialog> pMap(pFact->CreateSfxDialog( m_pDelimPB, aSet,
rSh.GetView().GetViewFrame()->GetFrame().GetFrameInterface(), RID_SVXDLG_CHARMAP ));
if( RET_OK == pMap->Execute() )
{
SFX_ITEMSET_ARG( pMap->GetOutputItemSet(), pItem, SfxInt32Item, SID_ATTR_CHAR, false );
if ( pItem )
m_pDelimEdt->SetText( OUString(pItem->GetValue()) );
}
delete pMap;
}
return 0;
}
......
......@@ -34,6 +34,7 @@
#include "app.hrc"
#include "table.hrc"
#include "swabstdlg.hxx"
#include <boost/scoped_ptr.hpp>
namespace swui
{
......@@ -185,11 +186,10 @@ IMPL_LINK( SwConvertTableDlg, AutoFmtHdl, PushButton*, pButton )
SwAbstractDialogFactory* pFact = swui::GetFactory();
OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
AbstractSwAutoFormatDlg* pDlg = pFact->CreateSwAutoFormatDlg(pButton, pShell, false, pTAutoFmt);
boost::scoped_ptr<AbstractSwAutoFormatDlg> pDlg(pFact->CreateSwAutoFormatDlg(pButton, pShell, false, pTAutoFmt));
OSL_ENSURE(pDlg, "Dialogdiet fail!");
if( RET_OK == pDlg->Execute())
pDlg->FillAutoFmtOfIndex( pTAutoFmt );
delete pDlg;
return 0;
}
......
......@@ -32,6 +32,7 @@
#include "table.hrc"
#include "swabstdlg.hxx"
#include <boost/scoped_ptr.hpp>
namespace swui
{
......@@ -190,11 +191,10 @@ IMPL_LINK( SwInsTableDlg, AutoFmtHdl, PushButton*, pButton )
SwAbstractDialogFactory* pFact = swui::GetFactory();
OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
AbstractSwAutoFormatDlg* pDlg = pFact->CreateSwAutoFormatDlg(pButton,pShell, false, pTAutoFmt);
boost::scoped_ptr<AbstractSwAutoFormatDlg> pDlg(pFact->CreateSwAutoFormatDlg(pButton,pShell, false, pTAutoFmt));
OSL_ENSURE(pDlg, "Dialogdiet fail!");
if( RET_OK == pDlg->Execute())
pDlg->FillAutoFmtOfIndex( pTAutoFmt );
delete pDlg;
return 0;
}
......
......@@ -38,6 +38,7 @@
#include "tblafmt.hxx"
#include "tautofmt.hxx"
#include "shellres.hxx"
#include <boost/scoped_ptr.hpp>
using namespace com::sun::star;
......@@ -286,10 +287,10 @@ IMPL_LINK_NOARG(SwAutoFormatDlg, AddHdl)
bool bOk = false, bFmtInserted = false;
while( !bOk )
{
SwStringInputDlg* pDlg = new SwStringInputDlg( this,
boost::scoped_ptr<SwStringInputDlg> pDlg(new SwStringInputDlg( this,
aStrTitle,
aStrLabel,
OUString() );
OUString() ));
if( RET_OK == pDlg->Execute() )
{
const OUString aFormatName( pDlg->GetInputString() );
......@@ -337,7 +338,6 @@ IMPL_LINK_NOARG(SwAutoFormatDlg, AddHdl)
}
else
bOk = true;
delete pDlg;
}
return 0;
}
......@@ -349,8 +349,8 @@ IMPL_LINK_NOARG(SwAutoFormatDlg, RemoveHdl)
aMessage += m_pLbFormat->GetSelectEntry();
aMessage += "\n";
MessBox* pBox = new MessBox( this, WinBits( WB_OK_CANCEL ),
aStrDelTitle, aMessage);
boost::scoped_ptr<MessBox> pBox(new MessBox( this, WinBits( WB_OK_CANCEL ),
aStrDelTitle, aMessage));
if ( pBox->Execute() == RET_OK )
{
......@@ -372,7 +372,7 @@ IMPL_LINK_NOARG(SwAutoFormatDlg, RemoveHdl)
bCoreDataChanged = true;
}
}
delete pBox;
pBox.reset();
SelFmtHdl( 0 );
......@@ -384,10 +384,10 @@ IMPL_LINK_NOARG(SwAutoFormatDlg, RenameHdl)
bool bOk = false;
while( !bOk )
{
SwStringInputDlg* pDlg = new SwStringInputDlg( this,
boost::scoped_ptr<SwStringInputDlg> pDlg(new SwStringInputDlg( this,
aStrRenameTitle,
m_pLbFormat->GetSelectEntry(),
OUString() );
OUString() ));
if( pDlg->Execute() == RET_OK )
{
bool bFmtRenamed = false;
......@@ -439,7 +439,6 @@ IMPL_LINK_NOARG(SwAutoFormatDlg, RenameHdl)
}
else
bOk = true;
delete pDlg;
}
return 0;
}
......
......@@ -486,8 +486,8 @@ void SwDocShell::Execute(SfxRequest& rReq)
if ( aFileName.isEmpty() )
{
SvtPathOptions aPathOpt;
SfxNewFileDialog* pNewFileDlg =
new SfxNewFileDialog(&GetView()->GetViewFrame()->GetWindow(), SFXWB_LOAD_TEMPLATE);
boost::scoped_ptr<SfxNewFileDialog> pNewFileDlg(
new SfxNewFileDialog(&GetView()->GetViewFrame()->GetWindow(), SFXWB_LOAD_TEMPLATE));
pNewFileDlg->SetTemplateFlags(nFlags);
nRet = pNewFileDlg->Execute();
......@@ -551,7 +551,6 @@ void SwDocShell::Execute(SfxRequest& rReq)
nFlags = pNewFileDlg->GetTemplateFlags();
rReq.AppendItem( SfxStringItem( SID_TEMPLATE_NAME, aFileName ) );
rReq.AppendItem( SfxInt32Item( SID_TEMPLATE_LOAD, (long) nFlags ) );
delete pNewFileDlg;
}
if( !aFileName.isEmpty() )
......@@ -1062,17 +1061,15 @@ void SwDocShell::Execute(SfxRequest& rReq)
//search for the view that created the call
if(pViewShell->GetObjectShell() == this && pViewShell->GetDispatcher())
{
SfxFrameItem* pFrameItem = new SfxFrameItem( SID_DOCFRAME,
pViewShell->GetViewFrame() );
boost::scoped_ptr<SfxFrameItem> pFrameItem(new SfxFrameItem( SID_DOCFRAME,
pViewShell->GetViewFrame() ));
SfxDispatcher* pDispatch = pViewShell->GetDispatcher();
pDispatch->Execute(
SID_OPENDOC,
SFX_CALLMODE_ASYNCHRON,
&aName,
&aReferer,
pFrameItem, 0L );
delete pFrameItem;
pFrameItem.get(), 0L );
break;
}
pViewShell = SfxViewShell::GetNext(*pViewShell);
......
......@@ -84,6 +84,7 @@
// text grid
#include <tgrditem.hxx>
#include <boost/scoped_ptr.hpp>
using namespace ::com::sun::star::i18n;
using namespace ::com::sun::star::lang;
......@@ -170,7 +171,7 @@ bool SwDocShell::InitNew( const uno::Reference < embed::XStorage >& xStor )
{
sal_uInt16 nFontWhich = aFontWhich[i];
sal_uInt16 nFontId = aFontIds[i];
SvxFontItem* pFontItem = 0;
boost::scoped_ptr<SvxFontItem> pFontItem;
const SvxLanguageItem& rLang = (const SvxLanguageItem&)pDoc->GetDefault( aLangTypes[i] );
LanguageType eLanguage = rLang.GetLanguage();
if(!pStdFont->IsFontDefault(nFontId))
......@@ -183,8 +184,8 @@ bool SwDocShell::InitNew( const uno::Reference < embed::XStorage >& xStor )
aFont = pPrt->GetFontMetric( aFont );
}
pFontItem = new SvxFontItem(aFont.GetFamily(), aFont.GetName(),
aEmptyOUStr, aFont.GetPitch(), aFont.GetCharSet(), nFontWhich);
pFontItem.reset(new SvxFontItem(aFont.GetFamily(), aFont.GetName(),
aEmptyOUStr, aFont.GetPitch(), aFont.GetCharSet(), nFontWhich));
}
else
{
......@@ -200,8 +201,8 @@ bool SwDocShell::InitNew( const uno::Reference < embed::XStorage >& xStor )
nFontTypes[i],
eLanguage,
DEFAULTFONT_FLAGS_ONLYONE );
pFontItem = new SvxFontItem(aLangDefFont.GetFamily(), aLangDefFont.GetName(),
aEmptyOUStr, aLangDefFont.GetPitch(), aLangDefFont.GetCharSet(), nFontWhich);
pFontItem.reset(new SvxFontItem(aLangDefFont.GetFamily(), aLangDefFont.GetName(),
aEmptyOUStr, aLangDefFont.GetPitch(), aLangDefFont.GetCharSet(), nFontWhich));
}
pDoc->SetDefault(*pFontItem);
if( !bHTMLTemplSet )
......@@ -209,7 +210,7 @@ bool SwDocShell::InitNew( const uno::Reference < embed::XStorage >& xStor )
SwTxtFmtColl *pColl = pDoc->GetTxtCollFromPool(RES_POOLCOLL_STANDARD);
pColl->ResetFmtAttr(nFontWhich);
}
delete pFontItem;
pFontItem.reset();
sal_Int32 nFontHeight = pStdFont->GetFontHeight( FONT_STANDARD, i, eLanguage );
if(nFontHeight <= 0)
nFontHeight = pStdFont->GetDefaultHeightFor( nFontId, eLanguage );
......
......@@ -57,6 +57,7 @@
#include <misc.hrc>
#include <IDocumentFieldsAccess.hxx>
#include <boost/scoped_ptr.hpp>
using namespace ::com::sun::star;
......@@ -75,7 +76,7 @@ void SwGlossaryHdl::GlossaryDlg()
{
SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
OSL_ENSURE(pFact, "Dialogdiet fail!");
AbstractGlossaryDlg* pDlg = pFact->CreateGlossaryDlg(pViewFrame, this, pWrtShell);
boost::scoped_ptr<AbstractGlossaryDlg> pDlg(pFact->CreateGlossaryDlg(pViewFrame, this, pWrtShell));
OSL_ENSURE(pDlg, "Dialogdiet fail!");
OUString sName;
OUString sShortName;
......@@ -86,7 +87,7 @@ void SwGlossaryHdl::GlossaryDlg()
sShortName = pDlg->GetCurrShortName();
}
delete pDlg;
pDlg.reset();
DELETEZ(pCurGrp);
if(HasGlossaryList())
{
......@@ -448,7 +449,7 @@ bool SwGlossaryHdl::Expand( const OUString& rShortName,
SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
AbstractSwSelGlossaryDlg* pDlg = pFact->CreateSwSelGlossaryDlg(0, aShortName);
boost::scoped_ptr<AbstractSwSelGlossaryDlg> pDlg(pFact->CreateSwSelGlossaryDlg(0, aShortName));
OSL_ENSURE(pDlg, "Dialogdiet fail!");
for(sal_uInt16 i = 0; i < aFoundArr.size(); ++i)
{
......@@ -459,7 +460,7 @@ bool SwGlossaryHdl::Expand( const OUString& rShortName,
const sal_Int32 nRet = RET_OK == pDlg->Execute()?
pDlg->GetSelectedIdx():
LISTBOX_ENTRY_NOTFOUND;
delete pDlg;
pDlg.reset();
if(LISTBOX_ENTRY_NOTFOUND != nRet)
{
TextBlockInfo_Impl* pData = &aFoundArr[nRet];
......@@ -723,7 +724,7 @@ bool SwGlossaryHdl::ImportGlossaries( const OUString& rName )
if( !rName.isEmpty() )
{
const SfxFilter* pFilter = 0;
SfxMedium* pMed = new SfxMedium( rName, STREAM_READ, 0, 0 );
boost::scoped_ptr<SfxMedium> pMed(new SfxMedium( rName, STREAM_READ, 0, 0 ));
SfxFilterMatcher aMatcher( OUString("swriter") );
pMed->UseInteractionHandler( true );
if( !aMatcher.GuessFilter( *pMed, &pFilter, sal_False ) )
......@@ -743,7 +744,6 @@ bool SwGlossaryHdl::ImportGlossaries( const OUString& rName )
}
}
}
DELETEZ(pMed);
}
return bRet;
}
......
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