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

Avoid possible memory leaks in case of exceptions

Change-Id: I6542885b0de6dad0244726f1ee8bf9cdc851e746
üst 0b92cacb
...@@ -92,7 +92,7 @@ void ScViewFunc::PasteRTF( SCCOL nStartCol, SCROW nStartRow, ...@@ -92,7 +92,7 @@ void ScViewFunc::PasteRTF( SCCOL nStartCol, SCROW nStartRow,
const bool bRecord (pDoc->IsUndoEnabled()); const bool bRecord (pDoc->IsUndoEnabled());
const ScPatternAttr* pPattern = pDoc->GetPattern( nStartCol, nStartRow, nTab ); const ScPatternAttr* pPattern = pDoc->GetPattern( nStartCol, nStartRow, nTab );
ScTabEditEngine* pEngine = new ScTabEditEngine( *pPattern, pDoc->GetEnginePool() ); boost::scoped_ptr<ScTabEditEngine> pEngine(new ScTabEditEngine( *pPattern, pDoc->GetEnginePool() ));
pEngine->EnableUndo( false ); pEngine->EnableUndo( false );
Window* pActWin = GetActiveWin(); Window* pActWin = GetActiveWin();
...@@ -100,7 +100,7 @@ void ScViewFunc::PasteRTF( SCCOL nStartCol, SCROW nStartRow, ...@@ -100,7 +100,7 @@ void ScViewFunc::PasteRTF( SCCOL nStartCol, SCROW nStartRow,
{ {
pEngine->SetPaperSize(Size(100000,100000)); pEngine->SetPaperSize(Size(100000,100000));
Window aWin( pActWin ); Window aWin( pActWin );
EditView aEditView( pEngine, &aWin ); EditView aEditView( pEngine.get(), &aWin );
aEditView.SetOutputArea(Rectangle(0,0,100000,100000)); aEditView.SetOutputArea(Rectangle(0,0,100000,100000));
// same method now for clipboard or drag&drop // same method now for clipboard or drag&drop
...@@ -152,7 +152,7 @@ void ScViewFunc::PasteRTF( SCCOL nStartCol, SCROW nStartRow, ...@@ -152,7 +152,7 @@ void ScViewFunc::PasteRTF( SCCOL nStartCol, SCROW nStartRow,
} }
} }
delete pEngine; pEngine.reset();
ShowAllCursors(); ShowAllCursors();
} }
...@@ -495,23 +495,23 @@ void ScViewFunc::DoSheetConversion( const ScConversionParam& rConvParam, bool bR ...@@ -495,23 +495,23 @@ void ScViewFunc::DoSheetConversion( const ScConversionParam& rConvParam, bool bR
// *** create and init the edit engine *** -------------------------------- // *** create and init the edit engine *** --------------------------------
ScConversionEngineBase* pEngine = NULL; boost::scoped_ptr<ScConversionEngineBase> pEngine;
switch( rConvParam.GetType() ) switch( rConvParam.GetType() )
{ {
case SC_CONVERSION_SPELLCHECK: case SC_CONVERSION_SPELLCHECK:
pEngine = new ScSpellingEngine( pEngine.reset(new ScSpellingEngine(
pDoc->GetEnginePool(), rViewData, pUndoDoc, pRedoDoc, LinguMgr::GetSpellChecker() ); pDoc->GetEnginePool(), rViewData, pUndoDoc, pRedoDoc, LinguMgr::GetSpellChecker() ));
break; break;
case SC_CONVERSION_HANGULHANJA: case SC_CONVERSION_HANGULHANJA:
case SC_CONVERSION_CHINESE_TRANSL: case SC_CONVERSION_CHINESE_TRANSL:
pEngine = new ScTextConversionEngine( pEngine.reset(new ScTextConversionEngine(
pDoc->GetEnginePool(), rViewData, rConvParam, pUndoDoc, pRedoDoc ); pDoc->GetEnginePool(), rViewData, rConvParam, pUndoDoc, pRedoDoc ));
break; break;
default: default:
OSL_FAIL( "ScViewFunc::DoSheetConversion - unknown conversion type" ); OSL_FAIL( "ScViewFunc::DoSheetConversion - unknown conversion type" );
} }
MakeEditView( pEngine, nCol, nRow ); MakeEditView( pEngine.get(), nCol, nRow );
pEngine->SetRefDevice( rViewData.GetActiveWin() ); pEngine->SetRefDevice( rViewData.GetActiveWin() );
// dummy Zelle simulieren: // dummy Zelle simulieren:
pEditView = rViewData.GetEditView( rViewData.GetActivePart() ); pEditView = rViewData.GetEditView( rViewData.GetActivePart() );
...@@ -558,7 +558,7 @@ void ScViewFunc::DoSheetConversion( const ScConversionParam& rConvParam, bool bR ...@@ -558,7 +558,7 @@ void ScViewFunc::DoSheetConversion( const ScConversionParam& rConvParam, bool bR
rViewData.SetSpellingView( NULL ); rViewData.SetSpellingView( NULL );
KillEditView(true); KillEditView(true);
delete pEngine; pEngine.reset();
pDocSh->PostPaintGridAll(); pDocSh->PostPaintGridAll();
rViewData.GetViewShell()->UpdateInputHandler(); rViewData.GetViewShell()->UpdateInputHandler();
pDoc->EnableIdle(bOldEnabled); pDoc->EnableIdle(bOldEnabled);
......
...@@ -67,6 +67,7 @@ ...@@ -67,6 +67,7 @@
#include <vcl/msgbox.hxx> #include <vcl/msgbox.hxx>
#include <sfx2/viewfrm.hxx> #include <sfx2/viewfrm.hxx>
#include <svx/dbaexchange.hxx> #include <svx/dbaexchange.hxx>
#include <boost/scoped_ptr.hpp>
using namespace com::sun::star; using namespace com::sun::star;
...@@ -139,7 +140,7 @@ bool ScViewFunc::PasteDataFormat( sal_uLong nFormatId, ...@@ -139,7 +140,7 @@ bool ScViewFunc::PasteDataFormat( sal_uLong nFormatId,
ScMarkData aSrcMark; ScMarkData aSrcMark;
aSrcMark.SelectOneTable( nSrcTab ); // for CopyToClip aSrcMark.SelectOneTable( nSrcTab ); // for CopyToClip
ScDocument* pClipDoc = new ScDocument( SCDOCMODE_CLIP ); boost::scoped_ptr<ScDocument> pClipDoc(new ScDocument( SCDOCMODE_CLIP ));
SCCOL nFirstCol, nLastCol; SCCOL nFirstCol, nLastCol;
SCROW nFirstRow, nLastRow; SCROW nFirstRow, nLastRow;
...@@ -151,15 +152,14 @@ bool ScViewFunc::PasteDataFormat( sal_uLong nFormatId, ...@@ -151,15 +152,14 @@ bool ScViewFunc::PasteDataFormat( sal_uLong nFormatId,
nFirstRow = nLastRow = 0; nFirstRow = nLastRow = 0;
} }
ScClipParam aClipParam(ScRange(nFirstCol, nFirstRow, nSrcTab, nLastCol, nLastRow, nSrcTab), false); ScClipParam aClipParam(ScRange(nFirstCol, nFirstRow, nSrcTab, nLastCol, nLastRow, nSrcTab), false);
pSrcDoc->CopyToClip(aClipParam, pClipDoc, &aSrcMark); pSrcDoc->CopyToClip(aClipParam, pClipDoc.get(), &aSrcMark);
ScGlobal::SetClipDocName( xDocShRef->GetTitle( SFX_TITLE_FULLNAME ) ); ScGlobal::SetClipDocName( xDocShRef->GetTitle( SFX_TITLE_FULLNAME ) );
SetCursor( nPosX, nPosY ); SetCursor( nPosX, nPosY );
Unmark(); Unmark();
PasteFromClip( IDF_ALL, pClipDoc, PasteFromClip( IDF_ALL, pClipDoc.get(),
PASTE_NOFUNC, false, false, false, INS_NONE, IDF_NONE, PASTE_NOFUNC, false, false, false, INS_NONE, IDF_NONE,
bAllowDialogs ); bAllowDialogs );
delete pClipDoc;
bRet = true; bRet = true;
} }
...@@ -333,9 +333,9 @@ bool ScViewFunc::PasteDataFormat( sal_uLong nFormatId, ...@@ -333,9 +333,9 @@ bool ScViewFunc::PasteDataFormat( sal_uLong nFormatId,
ScImportStringStream aStrm( aStr); ScImportStringStream aStrm( aStr);
ScAbstractDialogFactory* pFact = ScAbstractDialogFactory* pFact =
ScAbstractDialogFactory::Create(); ScAbstractDialogFactory::Create();
AbstractScImportAsciiDlg *pDlg = boost::scoped_ptr<AbstractScImportAsciiDlg> pDlg(
pFact->CreateScImportAsciiDlg( NULL, OUString(), &aStrm, pFact->CreateScImportAsciiDlg( NULL, OUString(), &aStrm,
SC_PASTETEXT); SC_PASTETEXT));
if (pDlg->Execute() == RET_OK) if (pDlg->Execute() == RET_OK)
{ {
...@@ -356,7 +356,6 @@ bool ScViewFunc::PasteDataFormat( sal_uLong nFormatId, ...@@ -356,7 +356,6 @@ bool ScViewFunc::PasteDataFormat( sal_uLong nFormatId,
bRet = true; bRet = true;
// Yes, no failure, don't raise a "couldn't paste" // Yes, no failure, don't raise a "couldn't paste"
// dialog if user cancelled. // dialog if user cancelled.
delete pDlg;
} }
else else
bRet = aObj.ImportString( aStr, nFormatId ); bRet = aObj.ImportString( aStr, nFormatId );
...@@ -491,13 +490,13 @@ bool ScViewFunc::PasteDataFormat( sal_uLong nFormatId, ...@@ -491,13 +490,13 @@ bool ScViewFunc::PasteDataFormat( sal_uLong nFormatId,
ScDocShellRef aDragShellRef( new ScDocShell ); ScDocShellRef aDragShellRef( new ScDocShell );
aDragShellRef->DoInitNew(NULL); aDragShellRef->DoInitNew(NULL);
FmFormModel* pModel = new FmFormModel( aPath, NULL, aDragShellRef ); boost::scoped_ptr<FmFormModel> pModel(new FmFormModel( aPath, NULL, aDragShellRef ));
pModel->GetItemPool().FreezeIdRanges(); pModel->GetItemPool().FreezeIdRanges();
xStm->Seek(0); xStm->Seek(0);
com::sun::star::uno::Reference< com::sun::star::io::XInputStream > xInputStream( new utl::OInputStreamWrapper( *xStm ) ); com::sun::star::uno::Reference< com::sun::star::io::XInputStream > xInputStream( new utl::OInputStreamWrapper( *xStm ) );
SvxDrawingLayerImport( pModel, xInputStream ); SvxDrawingLayerImport( pModel.get(), xInputStream );
// set everything to right layer: // set everything to right layer:
sal_uLong nObjCount = 0; sal_uLong nObjCount = 0;
...@@ -519,8 +518,8 @@ bool ScViewFunc::PasteDataFormat( sal_uLong nFormatId, ...@@ -519,8 +518,8 @@ bool ScViewFunc::PasteDataFormat( sal_uLong nFormatId,
nObjCount += pPage->GetObjCount(); // count group object only once nObjCount += pPage->GetObjCount(); // count group object only once
} }
PasteDraw( aPos, pModel, (nObjCount > 1) ); // grouped if more than 1 object PasteDraw( aPos, pModel.get(), (nObjCount > 1) ); // grouped if more than 1 object
delete pModel; pModel.reset();
aDragShellRef->DoClose(); aDragShellRef->DoClose();
bRet = true; bRet = true;
} }
......
...@@ -76,6 +76,7 @@ ...@@ -76,6 +76,7 @@
#include "cellsuno.hxx" #include "cellsuno.hxx"
#include "tokenarray.hxx" #include "tokenarray.hxx"
#include <rowheightcontext.hxx> #include <rowheightcontext.hxx>
#include <boost/scoped_ptr.hpp>
static void lcl_PostRepaintCondFormat( const ScConditionalFormat *pCondFmt, ScDocShell *pDocSh ) static void lcl_PostRepaintCondFormat( const ScConditionalFormat *pCondFmt, ScDocShell *pDocSh )
{ {
...@@ -625,7 +626,7 @@ void ScViewFunc::EnterData( SCCOL nCol, SCROW nRow, SCTAB nTab, ...@@ -625,7 +626,7 @@ void ScViewFunc::EnterData( SCCOL nCol, SCROW nRow, SCTAB nTab,
bool bSimple = false; bool bSimple = false;
bool bCommon = false; bool bCommon = false;
ScPatternAttr* pCellAttrs = NULL; boost::scoped_ptr<ScPatternAttr> pCellAttrs;
OUString aString; OUString aString;
const ScPatternAttr* pOldPattern = pDoc->GetPattern( nCol, nRow, nTab ); const ScPatternAttr* pOldPattern = pDoc->GetPattern( nCol, nRow, nTab );
...@@ -650,7 +651,7 @@ void ScViewFunc::EnterData( SCCOL nCol, SCROW nRow, SCTAB nTab, ...@@ -650,7 +651,7 @@ void ScViewFunc::EnterData( SCCOL nCol, SCROW nRow, SCTAB nTab,
if (bCommon) // attribute for tab if (bCommon) // attribute for tab
{ {
pCellAttrs = new ScPatternAttr( *pOldPattern ); pCellAttrs.reset(new ScPatternAttr( *pOldPattern ));
pCellAttrs->GetFromEditItemSet( &aAttrTester.GetAttribs() ); pCellAttrs->GetFromEditItemSet( &aAttrTester.GetAttribs() );
//! remove common attributes from EditEngine? //! remove common attributes from EditEngine?
} }
...@@ -726,8 +727,6 @@ void ScViewFunc::EnterData( SCCOL nCol, SCROW nRow, SCTAB nTab, ...@@ -726,8 +727,6 @@ void ScViewFunc::EnterData( SCCOL nCol, SCROW nRow, SCTAB nTab,
aModificator.SetDocumentModified(); aModificator.SetDocumentModified();
} }
lcl_PostRepaintCondFormat( pDoc->GetCondFormat( nCol, nRow, nTab ), pDocSh ); lcl_PostRepaintCondFormat( pDoc->GetCondFormat( nCol, nRow, nTab ), pDocSh );
delete pCellAttrs;
} }
else else
{ {
...@@ -1207,7 +1206,7 @@ void ScViewFunc::ApplySelectionPattern( const ScPatternAttr& rAttr, ...@@ -1207,7 +1206,7 @@ void ScViewFunc::ApplySelectionPattern( const ScPatternAttr& rAttr,
} }
aChangeRanges.Append(aPos); aChangeRanges.Append(aPos);
ScPatternAttr* pOldPat = new ScPatternAttr(*pDoc->GetPattern( nCol, nRow, nTab )); boost::scoped_ptr<ScPatternAttr> pOldPat(new ScPatternAttr(*pDoc->GetPattern( nCol, nRow, nTab )));
pDoc->ApplyPattern( nCol, nRow, nTab, rAttr ); pDoc->ApplyPattern( nCol, nRow, nTab, rAttr );
...@@ -1216,11 +1215,11 @@ void ScViewFunc::ApplySelectionPattern( const ScPatternAttr& rAttr, ...@@ -1216,11 +1215,11 @@ void ScViewFunc::ApplySelectionPattern( const ScPatternAttr& rAttr,
if (bRecord) if (bRecord)
{ {
ScUndoCursorAttr* pUndo = new ScUndoCursorAttr( ScUndoCursorAttr* pUndo = new ScUndoCursorAttr(
pDocSh, nCol, nRow, nTab, pOldPat, pNewPat, &rAttr, false ); pDocSh, nCol, nRow, nTab, pOldPat.get(), pNewPat, &rAttr, false );
pUndo->SetEditData(pOldEditData, pNewEditData); pUndo->SetEditData(pOldEditData, pNewEditData);
pDocSh->GetUndoManager()->AddUndoAction(pUndo); pDocSh->GetUndoManager()->AddUndoAction(pUndo);
} }
delete pOldPat; // is copied in undo (Pool) pOldPat.reset(); // is copied in undo (Pool)
pDocSh->PostPaint( nCol,nRow,nTab, nCol,nRow,nTab, PAINT_GRID, nExtFlags | SC_PF_TESTMERGE ); pDocSh->PostPaint( nCol,nRow,nTab, nCol,nRow,nTab, PAINT_GRID, nExtFlags | SC_PF_TESTMERGE );
pDocSh->UpdateOle(GetViewData()); pDocSh->UpdateOle(GetViewData());
......
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
#include <svx/svxdlg.hxx> #include <svx/svxdlg.hxx>
#include <svx/dialogs.hrc> #include <svx/dialogs.hrc>
#include <boost/scoped_ptr.hpp>
void ScViewUtil::PutItemScript( SfxItemSet& rShellSet, const SfxItemSet& rCoreSet, void ScViewUtil::PutItemScript( SfxItemSet& rShellSet, const SfxItemSet& rCoreSet,
sal_uInt16 nWhichId, sal_uInt16 nScript ) sal_uInt16 nWhichId, sal_uInt16 nScript )
...@@ -352,7 +352,7 @@ bool ScViewUtil::ExecuteCharMap( const SvxFontItem& rOldFont, ...@@ -352,7 +352,7 @@ bool ScViewUtil::ExecuteCharMap( const SvxFontItem& rOldFont,
SfxAllItemSet aSet( rFrame.GetObjectShell()->GetPool() ); SfxAllItemSet aSet( rFrame.GetObjectShell()->GetPool() );
aSet.Put( SfxBoolItem( FN_PARAM_1, false ) ); aSet.Put( SfxBoolItem( FN_PARAM_1, false ) );
aSet.Put( SvxFontItem( rOldFont.GetFamily(), rOldFont.GetFamilyName(), rOldFont.GetStyleName(), rOldFont.GetPitch(), rOldFont.GetCharSet(), aSet.GetPool()->GetWhich( SID_ATTR_CHAR_FONT ) ) ); aSet.Put( SvxFontItem( rOldFont.GetFamily(), rOldFont.GetFamilyName(), rOldFont.GetStyleName(), rOldFont.GetPitch(), rOldFont.GetCharSet(), aSet.GetPool()->GetWhich( SID_ATTR_CHAR_FONT ) ) );
SfxAbstractDialog* pDlg = pFact->CreateSfxDialog( &rFrame.GetWindow(), aSet, rFrame.GetFrame().GetFrameInterface(), RID_SVXDLG_CHARMAP ); boost::scoped_ptr<SfxAbstractDialog> pDlg(pFact->CreateSfxDialog( &rFrame.GetWindow(), aSet, rFrame.GetFrame().GetFrameInterface(), RID_SVXDLG_CHARMAP ));
if ( pDlg->Execute() == RET_OK ) if ( pDlg->Execute() == RET_OK )
{ {
SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pItem, SfxStringItem, SID_CHARMAP, false ); SFX_ITEMSET_ARG( pDlg->GetOutputItemSet(), pItem, SfxStringItem, SID_CHARMAP, false );
...@@ -363,7 +363,6 @@ bool ScViewUtil::ExecuteCharMap( const SvxFontItem& rOldFont, ...@@ -363,7 +363,6 @@ bool ScViewUtil::ExecuteCharMap( const SvxFontItem& rOldFont,
rNewFont = SvxFontItem( pFontItem->GetFamily(), pFontItem->GetFamilyName(), pFontItem->GetStyleName(), pFontItem->GetPitch(), pFontItem->GetCharSet(), rNewFont.Which() ); rNewFont = SvxFontItem( pFontItem->GetFamily(), pFontItem->GetFamilyName(), pFontItem->GetStyleName(), pFontItem->GetPitch(), pFontItem->GetCharSet(), rNewFont.Which() );
bRet = true; bRet = true;
} }
delete pDlg;
} }
return bRet; 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