summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi Abe <tabe@fixedpoint.jp>2014-04-27 22:45:29 +0900
committerTakeshi Abe <tabe@fixedpoint.jp>2014-04-27 22:48:33 +0900
commitf2e546efd96b5a8b7c0b339cf2673a9b1996190b (patch)
tree2fd2bc6e7a340015ce25c0d14a215ee5fd6ad0ff
parentc764a3d978beb2e6197a8d3f7df53d81ebf72467 (diff)
Avoid possible memory leaks in case of exceptions
Change-Id: Ifd4c87bf038b421a0468edb599eca030c78bad89
-rw-r--r--sc/source/core/data/table1.cxx5
-rw-r--r--sc/source/core/tool/chgtrack.cxx12
-rw-r--r--sc/source/core/tool/interpr4.cxx8
-rw-r--r--sc/source/filter/dif/difimp.cxx8
4 files changed, 14 insertions, 19 deletions
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index 77de5a8de3da..4827541d36d2 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -53,6 +53,7 @@
#include "formula/vectortoken.hxx"
#include <vector>
+#include <boost/scoped_array.hpp>
using ::std::vector;
@@ -1299,7 +1300,7 @@ void ScTable::GetNextPos( SCCOL& rCol, SCROW& rRow, SCsCOL nMovX, SCsROW nMovY,
if ( !ValidNextPos(nCol, nRow, rMark, bMarked, bUnprotected) )
{
- SCsROW* pNextRows = new SCsROW[MAXCOL+1];
+ boost::scoped_array<SCsROW> pNextRows(new SCsROW[MAXCOL+1]);
SCCOL i;
if ( nMovX > 0 ) // vorwaerts
@@ -1368,8 +1369,6 @@ void ScTable::GetNextPos( SCCOL& rCol, SCROW& rRow, SCsCOL nMovX, SCsROW nMovY,
}
while ( !ValidNextPos(nCol, nRow, rMark, bMarked, bUnprotected) );
}
-
- delete[] pNextRows;
}
}
diff --git a/sc/source/core/tool/chgtrack.cxx b/sc/source/core/tool/chgtrack.cxx
index df37e22c48d6..3b5a0b42532f 100644
--- a/sc/source/core/tool/chgtrack.cxx
+++ b/sc/source/core/tool/chgtrack.cxx
@@ -43,6 +43,7 @@
#include <sfx2/app.hxx>
#include <unotools/useroptions.hxx>
#include <sfx2/sfxsids.hrc>
+#include <boost/scoped_ptr.hpp>
IMPL_FIXEDMEMPOOL_NEWDEL( ScChangeActionCellListEntry )
IMPL_FIXEDMEMPOOL_NEWDEL( ScChangeActionLinkEntry )
@@ -1822,9 +1823,8 @@ void ScChangeActionContent::GetFormulaString(
else
{
OSL_FAIL( "ScChangeActionContent::GetFormulaString: aPos != pCell->aPos" );
- ScFormulaCell* pNew = new ScFormulaCell( *pCell, *pCell->GetDocument(), aPos );
+ boost::scoped_ptr<ScFormulaCell> pNew(new ScFormulaCell( *pCell, *pCell->GetDocument(), aPos ));
pNew->GetFormula( rStr );
- delete pNew;
}
}
@@ -4188,15 +4188,13 @@ bool ScChangeTrack::Reject( ScChangeAction* pAct, bool bShared )
if ( !pAct->IsRejectable() )
return false;
- ScChangeActionMap* pMap = NULL;
+ boost::scoped_ptr<ScChangeActionMap> pMap;
if ( pAct->HasDependent() )
{
- pMap = new ScChangeActionMap;
+ pMap.reset(new ScChangeActionMap);
GetDependents( pAct, *pMap, false, true );
}
- bool bRejected = Reject( pAct, pMap, false );
- if ( pMap )
- delete pMap;
+ bool bRejected = Reject( pAct, pMap.get(), false );
return bRejected;
}
diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index 1a3294d769e6..83197fd3bf33 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -72,6 +72,7 @@
#include <basic/basmgr.hxx>
#include <vbahelper/vbaaccesshelper.hxx>
#include <memory>
+#include <boost/scoped_array.hpp>
using namespace com::sun::star;
using namespace formula;
@@ -2635,12 +2636,11 @@ void ScInterpreter::ScExternal()
break;
case PTR_STRING :
{
- sal_Char* pcErg = new sal_Char[ADDIN_MAXSTRLEN];
- ppParam[0] = pcErg;
+ boost::scoped_array<sal_Char> pcErg(new sal_Char[ADDIN_MAXSTRLEN]);
+ ppParam[0] = pcErg.get();
pFuncData->Call(ppParam);
- OUString aUni( pcErg, strlen(pcErg), osl_getThreadTextEncoding() );
+ OUString aUni( pcErg.get(), strlen(pcErg.get()), osl_getThreadTextEncoding() );
PushString( aUni );
- delete[] pcErg;
}
break;
default:
diff --git a/sc/source/filter/dif/difimp.cxx b/sc/source/filter/dif/difimp.cxx
index 87c3fb0b2003..1ec7e809ed13 100644
--- a/sc/source/filter/dif/difimp.cxx
+++ b/sc/source/filter/dif/difimp.cxx
@@ -32,6 +32,7 @@
#include "scerrors.hxx"
#include "scitems.hxx"
#include "stringutil.hxx"
+#include <boost/scoped_ptr.hpp>
const sal_Unicode pKeyTABLE[] = { 'T', 'A', 'B', 'L', 'E', 0 };
const sal_Unicode pKeyVECTORS[] = { 'V', 'E', 'C', 'T', 'O', 'R', 'S', 0 };
@@ -951,7 +952,7 @@ void DifAttrCache::Apply( ScDocument& rDoc, SCTAB nTab )
{
if( bPlain )
{
- ScPatternAttr* pPatt = NULL;
+ boost::scoped_ptr<ScPatternAttr> pPatt;
for( SCCOL nCol = 0 ; nCol <= MAXCOL ; nCol++ )
{
@@ -959,7 +960,7 @@ void DifAttrCache::Apply( ScDocument& rDoc, SCTAB nTab )
{
if( !pPatt )
{
- pPatt = new ScPatternAttr( rDoc.GetPool() );
+ pPatt.reset(new ScPatternAttr( rDoc.GetPool() ));
pPatt->GetItemSet().Put( SfxUInt32Item( ATTR_VALUE_FORMAT,
rDoc.GetFormatTable()->GetStandardFormat( NUMBERFORMAT_LOGICAL ) ) );
}
@@ -967,9 +968,6 @@ void DifAttrCache::Apply( ScDocument& rDoc, SCTAB nTab )
ppCols[ nCol ]->Apply( rDoc, nCol, nTab, *pPatt );
}
}
-
- if( pPatt )
- delete pPatt;
}
else
{