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

Avoid possible memory leaks in case of exceptions

Change-Id: Id8a85f6c7bcf8eed4688ebebf30b1b74676dae0d
üst 05cd0965
...@@ -344,10 +344,9 @@ long ScColumn::GetNeededSize( ...@@ -344,10 +344,9 @@ long ScColumn::GetNeededSize(
SfxItemSet* pSet = new SfxItemSet( pEngine->GetEmptyItemSet() ); SfxItemSet* pSet = new SfxItemSet( pEngine->GetEmptyItemSet() );
if ( ScStyleSheet* pPreviewStyle = pDocument->GetPreviewCellStyle( nCol, nRow, nTab ) ) if ( ScStyleSheet* pPreviewStyle = pDocument->GetPreviewCellStyle( nCol, nRow, nTab ) )
{ {
ScPatternAttr* pPreviewPattern = new ScPatternAttr( *pPattern ); boost::scoped_ptr<ScPatternAttr> pPreviewPattern(new ScPatternAttr( *pPattern ));
pPreviewPattern->SetStyleSheet(pPreviewStyle); pPreviewPattern->SetStyleSheet(pPreviewStyle);
pPreviewPattern->FillEditItemSet( pSet, pCondSet ); pPreviewPattern->FillEditItemSet( pSet, pCondSet );
delete pPreviewPattern;
} }
else else
{ {
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include "refupdatecontext.hxx" #include "refupdatecontext.hxx"
#include <svl/sharedstring.hxx> #include <svl/sharedstring.hxx>
#include <svl/sharedstringpool.hxx> #include <svl/sharedstringpool.hxx>
#include <boost/scoped_ptr.hpp>
using namespace formula; using namespace formula;
...@@ -627,12 +628,12 @@ void ScConditionEntry::Interpret( const ScAddress& rPos ) ...@@ -627,12 +628,12 @@ void ScConditionEntry::Interpret( const ScAddress& rPos )
bool bDirty = false; //! 1 und 2 getrennt ??? bool bDirty = false; //! 1 und 2 getrennt ???
ScFormulaCell* pTemp1 = NULL; boost::scoped_ptr<ScFormulaCell> pTemp1;
ScFormulaCell* pEff1 = pFCell1; ScFormulaCell* pEff1 = pFCell1;
if ( bRelRef1 ) if ( bRelRef1 )
{ {
pTemp1 = pFormula1 ? new ScFormulaCell(mpDoc, rPos, *pFormula1) : new ScFormulaCell(mpDoc, rPos); pTemp1.reset(pFormula1 ? new ScFormulaCell(mpDoc, rPos, *pFormula1) : new ScFormulaCell(mpDoc, rPos));
pEff1 = pTemp1; pEff1 = pTemp1.get();
} }
if ( pEff1 ) if ( pEff1 )
{ {
...@@ -655,14 +656,14 @@ void ScConditionEntry::Interpret( const ScAddress& rPos ) ...@@ -655,14 +656,14 @@ void ScConditionEntry::Interpret( const ScAddress& rPos )
} }
} }
} }
delete pTemp1; pTemp1.reset();
ScFormulaCell* pTemp2 = NULL; boost::scoped_ptr<ScFormulaCell> pTemp2;
ScFormulaCell* pEff2 = pFCell2; //@ 1!=2 ScFormulaCell* pEff2 = pFCell2; //@ 1!=2
if ( bRelRef2 ) if ( bRelRef2 )
{ {
pTemp2 = pFormula2 ? new ScFormulaCell(mpDoc, rPos, *pFormula2) : new ScFormulaCell(mpDoc, rPos); pTemp2.reset(pFormula2 ? new ScFormulaCell(mpDoc, rPos, *pFormula2) : new ScFormulaCell(mpDoc, rPos));
pEff2 = pTemp2; pEff2 = pTemp2.get();
} }
if ( pEff2 ) if ( pEff2 )
{ {
...@@ -684,7 +685,7 @@ void ScConditionEntry::Interpret( const ScAddress& rPos ) ...@@ -684,7 +685,7 @@ void ScConditionEntry::Interpret( const ScAddress& rPos )
} }
} }
} }
delete pTemp2; pTemp2.reset();
// wenn IsRunning, bleiben die letzten Werte erhalten // wenn IsRunning, bleiben die letzten Werte erhalten
......
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include "tokenarray.hxx" #include "tokenarray.hxx"
#include "scmatrix.hxx" #include "scmatrix.hxx"
#include <tokenstringcontext.hxx> #include <tokenstringcontext.hxx>
#include <boost/scoped_array.hpp>
using namespace formula; using namespace formula;
...@@ -1099,7 +1100,7 @@ void ScDocument::CompareDocument( ScDocument& rOtherDoc ) ...@@ -1099,7 +1100,7 @@ void ScDocument::CompareDocument( ScDocument& rOtherDoc )
SCTAB nThisCount = GetTableCount(); SCTAB nThisCount = GetTableCount();
SCTAB nOtherCount = rOtherDoc.GetTableCount(); SCTAB nOtherCount = rOtherDoc.GetTableCount();
SCTAB* pOtherTabs = new SCTAB[nThisCount]; boost::scoped_array<SCTAB> pOtherTabs(new SCTAB[nThisCount]);
SCTAB nThisTab; SCTAB nThisTab;
// Tabellen mit gleichen Namen vergleichen // Tabellen mit gleichen Namen vergleichen
...@@ -1356,11 +1357,6 @@ void ScDocument::CompareDocument( ScDocument& rOtherDoc ) ...@@ -1356,11 +1357,6 @@ void ScDocument::CompareDocument( ScDocument& rOtherDoc )
delete[] pTempRows; delete[] pTempRows;
} }
} }
//! Inhalt von eingefuegten / geloeschten Tabellen ???
//! Aktionen fuer eingefuegte / geloeschte Tabellen ???
delete[] pOtherTabs;
} }
......
...@@ -1176,7 +1176,7 @@ void ScDocument::TransliterateText( const ScMarkData& rMultiMark, sal_Int32 nTyp ...@@ -1176,7 +1176,7 @@ void ScDocument::TransliterateText( const ScMarkData& rMultiMark, sal_Int32 nTyp
bool bConsiderLanguage = aTranslitarationWrapper.needLanguageForTheMode(); bool bConsiderLanguage = aTranslitarationWrapper.needLanguageForTheMode();
sal_uInt16 nLanguage = LANGUAGE_SYSTEM; sal_uInt16 nLanguage = LANGUAGE_SYSTEM;
ScEditEngineDefaulter* pEngine = NULL; // not using pEditEngine member because of defaults boost::scoped_ptr<ScEditEngineDefaulter> pEngine; // not using pEditEngine member because of defaults
SCTAB nCount = GetTableCount(); SCTAB nCount = GetTableCount();
ScMarkData::const_iterator itr = rMultiMark.begin(), itrEnd = rMultiMark.end(); ScMarkData::const_iterator itr = rMultiMark.begin(), itrEnd = rMultiMark.end();
...@@ -1204,17 +1204,16 @@ void ScDocument::TransliterateText( const ScMarkData& rMultiMark, sal_Int32 nTyp ...@@ -1204,17 +1204,16 @@ void ScDocument::TransliterateText( const ScMarkData& rMultiMark, sal_Int32 nTyp
( nType == i18n::TransliterationModulesExtra::SENTENCE_CASE || nType == i18n::TransliterationModulesExtra::TITLE_CASE))) ( nType == i18n::TransliterationModulesExtra::SENTENCE_CASE || nType == i18n::TransliterationModulesExtra::TITLE_CASE)))
{ {
if (!pEngine) if (!pEngine)
pEngine = new ScFieldEditEngine(this, GetEnginePool(), GetEditPool()); pEngine.reset(new ScFieldEditEngine(this, GetEnginePool(), GetEditPool()));
// defaults from cell attributes must be set so right language is used // defaults from cell attributes must be set so right language is used
const ScPatternAttr* pPattern = GetPattern( nCol, nRow, nTab ); const ScPatternAttr* pPattern = GetPattern( nCol, nRow, nTab );
SfxItemSet* pDefaults = new SfxItemSet( pEngine->GetEmptyItemSet() ); SfxItemSet* pDefaults = new SfxItemSet( pEngine->GetEmptyItemSet() );
if ( ScStyleSheet* pPreviewStyle = GetPreviewCellStyle( nCol, nRow, nTab ) ) if ( ScStyleSheet* pPreviewStyle = GetPreviewCellStyle( nCol, nRow, nTab ) )
{ {
ScPatternAttr* pPreviewPattern = new ScPatternAttr( *pPattern ); boost::scoped_ptr<ScPatternAttr> pPreviewPattern(new ScPatternAttr( *pPattern ));
pPreviewPattern->SetStyleSheet(pPreviewStyle); pPreviewPattern->SetStyleSheet(pPreviewStyle);
pPreviewPattern->FillEditItemSet( pDefaults ); pPreviewPattern->FillEditItemSet( pDefaults );
delete pPreviewPattern;
} }
else else
{ {
...@@ -1239,7 +1238,7 @@ void ScDocument::TransliterateText( const ScMarkData& rMultiMark, sal_Int32 nTyp ...@@ -1239,7 +1238,7 @@ void ScDocument::TransliterateText( const ScMarkData& rMultiMark, sal_Int32 nTyp
if ( pEngine->IsModified() ) if ( pEngine->IsModified() )
{ {
ScEditAttrTester aTester( pEngine ); ScEditAttrTester aTester( pEngine.get() );
if ( aTester.NeedsObject() ) if ( aTester.NeedsObject() )
{ {
// remove defaults (paragraph attributes) before creating text object // remove defaults (paragraph attributes) before creating text object
...@@ -1285,7 +1284,6 @@ void ScDocument::TransliterateText( const ScMarkData& rMultiMark, sal_Int32 nTyp ...@@ -1285,7 +1284,6 @@ void ScDocument::TransliterateText( const ScMarkData& rMultiMark, sal_Int32 nTyp
bFound = GetNextMarkedCell( nCol, nRow, nTab, rMultiMark ); bFound = GetNextMarkedCell( nCol, nRow, nTab, rMultiMark );
} }
} }
delete pEngine;
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -77,6 +77,7 @@ ...@@ -77,6 +77,7 @@
#include "basegfx/matrix/b2dhommatrix.hxx" #include "basegfx/matrix/b2dhommatrix.hxx"
#include <vcl/field.hxx> #include <vcl/field.hxx>
#include <boost/scoped_array.hpp>
#define DET_ARROW_OFFSET 1000 #define DET_ARROW_OFFSET 1000
...@@ -1156,7 +1157,7 @@ void ScDrawLayer::DeleteObjectsInArea( SCTAB nTab, SCCOL nCol1,SCROW nRow1, ...@@ -1156,7 +1157,7 @@ void ScDrawLayer::DeleteObjectsInArea( SCTAB nTab, SCCOL nCol1,SCROW nRow1,
long nDelCount = 0; long nDelCount = 0;
Rectangle aDelRect = pDoc->GetMMRect( nCol1, nRow1, nCol2, nRow2, nTab ); Rectangle aDelRect = pDoc->GetMMRect( nCol1, nRow1, nCol2, nRow2, nTab );
SdrObject** ppObj = new SdrObject*[nObjCount]; boost::scoped_array<SdrObject*> ppObj(new SdrObject*[nObjCount]);
SdrObjListIter aIter( *pPage, IM_FLAT ); SdrObjListIter aIter( *pPage, IM_FLAT );
SdrObject* pObject = aIter.Next(); SdrObject* pObject = aIter.Next();
...@@ -1181,8 +1182,6 @@ void ScDrawLayer::DeleteObjectsInArea( SCTAB nTab, SCCOL nCol1,SCROW nRow1, ...@@ -1181,8 +1182,6 @@ void ScDrawLayer::DeleteObjectsInArea( SCTAB nTab, SCCOL nCol1,SCROW nRow1,
for (i=1; i<=nDelCount; i++) for (i=1; i<=nDelCount; i++)
pPage->RemoveObject( ppObj[nDelCount-i]->GetOrdNum() ); pPage->RemoveObject( ppObj[nDelCount-i]->GetOrdNum() );
delete[] ppObj;
} }
} }
...@@ -1216,7 +1215,7 @@ void ScDrawLayer::DeleteObjectsInSelection( const ScMarkData& rMark ) ...@@ -1216,7 +1215,7 @@ void ScDrawLayer::DeleteObjectsInSelection( const ScMarkData& rMark )
aMarkRange.aStart.Col(), aMarkRange.aStart.Row(), aMarkRange.aStart.Col(), aMarkRange.aStart.Row(),
aMarkRange.aEnd.Col(), aMarkRange.aEnd.Row(), nTab ); aMarkRange.aEnd.Col(), aMarkRange.aEnd.Row(), nTab );
SdrObject** ppObj = new SdrObject*[nObjCount]; boost::scoped_array<SdrObject*> ppObj(new SdrObject*[nObjCount]);
SdrObjListIter aIter( *pPage, IM_FLAT ); SdrObjListIter aIter( *pPage, IM_FLAT );
SdrObject* pObject = aIter.Next(); SdrObject* pObject = aIter.Next();
...@@ -1247,8 +1246,6 @@ void ScDrawLayer::DeleteObjectsInSelection( const ScMarkData& rMark ) ...@@ -1247,8 +1246,6 @@ void ScDrawLayer::DeleteObjectsInSelection( const ScMarkData& rMark )
for (i=1; i<=nDelCount; i++) for (i=1; i<=nDelCount; i++)
pPage->RemoveObject( ppObj[nDelCount-i]->GetOrdNum() ); pPage->RemoveObject( ppObj[nDelCount-i]->GetOrdNum() );
delete[] ppObj;
} }
} }
else else
......
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