summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi Abe <tabe@fixedpoint.jp>2014-05-29 09:27:30 +0900
committerTakeshi Abe <tabe@fixedpoint.jp>2014-05-29 09:29:15 +0900
commita71ae24a236aa7bf6c17cad92a1662e63b7a13bf (patch)
tree64a0298f173c4b05f525e1288d9c28fa563dc899
parent7c8b2f10310f0f64b111afb3012e82e9c4a690ac (diff)
Avoid possible memory leaks in case of exceptions
Change-Id: Iac63a5d60478e5cd8e2b77c889c7b312d3d15f67
-rw-r--r--basic/source/classes/sbunoobj.cxx13
-rw-r--r--basic/source/classes/sbxmod.cxx4
-rw-r--r--basic/source/comp/dim.cxx5
-rw-r--r--basic/source/comp/io.cxx30
-rw-r--r--basic/source/comp/loops.cxx5
-rw-r--r--basic/source/comp/sbcomp.cxx5
-rw-r--r--basic/source/runtime/inputbox.cxx6
-rw-r--r--basic/source/runtime/methods.cxx19
8 files changed, 42 insertions, 45 deletions
diff --git a/basic/source/classes/sbunoobj.cxx b/basic/source/classes/sbunoobj.cxx
index b5611fa05b1f..45e96a24b8dd 100644
--- a/basic/source/classes/sbunoobj.cxx
+++ b/basic/source/classes/sbunoobj.cxx
@@ -93,6 +93,7 @@ using namespace cppu;
#include <runtime.hxx>
#include <math.h>
+#include <boost/scoped_array.hpp>
#include <boost/unordered_map.hpp>
#include <com/sun/star/reflection/XTypeDescriptionEnumerationAccess.hpp>
#include <com/sun/star/reflection/XConstantsTypeDescription.hpp>
@@ -1399,9 +1400,9 @@ Any sbxToUnoValue( const SbxValue* pVar, const Type& rType, Property* pUnoProper
if( nSeqLevel == nDims )
{
- sal_Int32* pLowerBounds = new sal_Int32[nDims];
- sal_Int32* pUpperBounds = new sal_Int32[nDims];
- sal_Int32* pActualIndices = new sal_Int32[nDims];
+ boost::scoped_array<sal_Int32> pLowerBounds(new sal_Int32[nDims]);
+ boost::scoped_array<sal_Int32> pUpperBounds(new sal_Int32[nDims]);
+ boost::scoped_array<sal_Int32> pActualIndices(new sal_Int32[nDims]);
for( short i = 1 ; i <= nDims ; i++ )
{
sal_Int32 lBound, uBound;
@@ -1413,11 +1414,7 @@ Any sbxToUnoValue( const SbxValue* pVar, const Type& rType, Property* pUnoProper
}
aRetVal = implRekMultiDimArrayToSequence( pArray, aElemType,
- nDims - 1, 0, pActualIndices, pLowerBounds, pUpperBounds );
-
- delete[] pUpperBounds;
- delete[] pLowerBounds;
- delete[] pActualIndices;
+ nDims - 1, 0, pActualIndices.get(), pLowerBounds.get(), pUpperBounds.get() );
}
}
}
diff --git a/basic/source/classes/sbxmod.cxx b/basic/source/classes/sbxmod.cxx
index a7c3e45017da..078a4f941ac9 100644
--- a/basic/source/classes/sbxmod.cxx
+++ b/basic/source/classes/sbxmod.cxx
@@ -21,6 +21,7 @@
#include <list>
#include <boost/noncopyable.hpp>
+#include <boost/scoped_ptr.hpp>
#include <vcl/svapp.hxx>
#include <tools/stream.hxx>
#include <svl/brdcst.hxx>
@@ -1779,7 +1780,7 @@ void SbModule::GetCodeCompleteDataFromParse(CodeCompleteDataCache& aCache)
ErrorHdlResetter aErrHdl;
SbxBase::ResetError();
- SbiParser* pParser = new SbiParser( (StarBASIC*) GetParent(), this );
+ boost::scoped_ptr<SbiParser> pParser(new SbiParser( (StarBASIC*) GetParent(), this ));
pParser->SetCodeCompleting(true);
while( pParser->Parse() ) {}
@@ -1801,7 +1802,6 @@ void SbModule::GetCodeCompleteDataFromParse(CodeCompleteDataCache& aCache)
aCache.InsertLocalVar( pSymDef->GetName(), pChildSymDef->GetName(), pParser->aGblStrings.Find(pChildSymDef->GetTypeId()) );
}
}
- delete pParser;
}
SbxArrayRef SbModule::GetMethods()
diff --git a/basic/source/comp/dim.cxx b/basic/source/comp/dim.cxx
index 9d20c6d497e4..2d6dfab2ae8e 100644
--- a/basic/source/comp/dim.cxx
+++ b/basic/source/comp/dim.cxx
@@ -29,6 +29,7 @@
#include <com/sun/star/reflection/XIdlMethod.hpp>
#include <com/sun/star/uno/Exception.hpp>
#include <basic/codecompletecache.hxx>
+#include <boost/scoped_ptr.hpp>
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
@@ -965,7 +966,7 @@ SbiProcDef* SbiParser::ProcDecl( bool bDecl )
bool bError2 = true;
if( bOptional && bCompatible && eTok == EQ )
{
- SbiConstExpression* pDefaultExpr = new SbiConstExpression( this );
+ boost::scoped_ptr<SbiConstExpression> pDefaultExpr(new SbiConstExpression( this ));
SbxDataType eType2 = pDefaultExpr->GetType();
sal_uInt16 nStringId;
@@ -978,7 +979,7 @@ SbiProcDef* SbiParser::ProcDecl( bool bDecl )
nStringId = aGblStrings.Add( pDefaultExpr->GetValue(), eType2 );
}
pPar->SetDefaultId( nStringId );
- delete pDefaultExpr;
+ pDefaultExpr.reset();
eTok = Next();
if( eTok == COMMA || eTok == RPAREN )
diff --git a/basic/source/comp/io.cxx b/basic/source/comp/io.cxx
index 90e3dbb55a20..0ac30a693ded 100644
--- a/basic/source/comp/io.cxx
+++ b/basic/source/comp/io.cxx
@@ -19,6 +19,7 @@
#include "sbcomp.hxx"
#include "iosys.hxx"
+#include <boost/scoped_ptr.hpp>
// test if there's an I/O channel
@@ -51,9 +52,9 @@ void SbiParser::Print()
{
if( !IsEoln( Peek() ) )
{
- SbiExpression* pExpr = new SbiExpression( this );
+ boost::scoped_ptr<SbiExpression> pExpr(new SbiExpression( this ));
pExpr->Gen();
- delete pExpr;
+ pExpr.reset();
Peek();
aGen.Gen( eCurTok == COMMA ? _PRINTF : _BPRINT );
}
@@ -80,9 +81,9 @@ void SbiParser::Write()
while( !bAbort )
{
- SbiExpression* pExpr = new SbiExpression( this );
+ boost::scoped_ptr<SbiExpression> pExpr(new SbiExpression( this ));
pExpr->Gen();
- delete pExpr;
+ pExpr.reset();
aGen.Gen( _BWRITE );
if( Peek() == COMMA )
{
@@ -129,14 +130,14 @@ void SbiParser::Line()
void SbiParser::LineInput()
{
Channel( true );
- SbiExpression* pExpr = new SbiExpression( this, SbOPERAND );
+ boost::scoped_ptr<SbiExpression> pExpr(new SbiExpression( this, SbOPERAND ));
if( !pExpr->IsVariable() )
Error( SbERR_VAR_EXPECTED );
if( pExpr->GetType() != SbxVARIANT && pExpr->GetType() != SbxSTRING )
Error( SbERR_CONVERSION );
pExpr->Gen();
aGen.Gen( _LINPUT );
- delete pExpr;
+ pExpr.reset();
aGen.Gen( _CHAN0 ); // ResetChannel() not in StepLINPUT() anymore
}
@@ -146,7 +147,7 @@ void SbiParser::Input()
{
aGen.Gen( _RESTART );
Channel( true );
- SbiExpression* pExpr = new SbiExpression( this, SbOPERAND );
+ boost::scoped_ptr<SbiExpression> pExpr(new SbiExpression( this, SbOPERAND ));
while( !bAbort )
{
if( !pExpr->IsVariable() )
@@ -156,12 +157,11 @@ void SbiParser::Input()
if( Peek() == COMMA )
{
Next();
- delete pExpr;
- pExpr = new SbiExpression( this, SbOPERAND );
+ pExpr.reset(new SbiExpression( this, SbOPERAND ));
}
else break;
}
- delete pExpr;
+ pExpr.reset();
aGen.Gen( _CHAN0 );
}
@@ -240,20 +240,20 @@ void SbiParser::Open()
}
TestToken( AS );
// channel number
- SbiExpression* pChan = new SbiExpression( this );
+ boost::scoped_ptr<SbiExpression> pChan(new SbiExpression( this ));
if( !pChan )
Error( SbERR_SYNTAX );
- SbiExpression* pLen = NULL;
+ boost::scoped_ptr<SbiExpression> pLen;
if( Peek() == SYMBOL )
{
Next();
if( aSym.equalsIgnoreAsciiCase("LEN") )
{
TestToken( EQ );
- pLen = new SbiExpression( this );
+ pLen.reset(new SbiExpression( this ));
}
}
- if( !pLen ) pLen = new SbiExpression( this, 128, SbxINTEGER );
+ if( !pLen ) pLen.reset(new SbiExpression( this, 128, SbxINTEGER ));
// the stack for the OPEN command looks as follows:
// block length
// channel number
@@ -263,8 +263,6 @@ void SbiParser::Open()
pChan->Gen();
aFileName.Gen();
aGen.Gen( _OPEN, nMode, nFlags );
- delete pLen;
- delete pChan;
bInStatement = false;
}
diff --git a/basic/source/comp/loops.cxx b/basic/source/comp/loops.cxx
index 396f2833c99e..1de4e1568d60 100644
--- a/basic/source/comp/loops.cxx
+++ b/basic/source/comp/loops.cxx
@@ -19,6 +19,7 @@
#include "sbcomp.hxx"
+#include <boost/scoped_ptr.hpp>
// Single-line IF and Multiline IF
@@ -64,10 +65,10 @@ void SbiParser::If()
aGen.BackChain( nEndLbl );
aGen.Statement();
- SbiExpression* pCond = new SbiExpression( this );
+ boost::scoped_ptr<SbiExpression> pCond(new SbiExpression( this ));
pCond->Gen();
nEndLbl = aGen.Gen( _JUMPF, 0 );
- delete pCond;
+ pCond.reset();
TestToken( THEN );
eTok = Peek();
while( !( eTok == ELSEIF || eTok == ELSE || eTok == ENDIF ) &&
diff --git a/basic/source/comp/sbcomp.cxx b/basic/source/comp/sbcomp.cxx
index e3f49e74eebb..59b0fd7457e8 100644
--- a/basic/source/comp/sbcomp.cxx
+++ b/basic/source/comp/sbcomp.cxx
@@ -24,6 +24,7 @@
#include "sbobjmod.hxx"
#include <svtools/miscopt.hxx>
#include <stdio.h>
+#include <boost/scoped_ptr.hpp>
// To activate tracing enable in sbtrace.hxx
#ifdef DBG_TRACE_BASIC
@@ -954,11 +955,11 @@ bool SbModule::Compile()
SbModule* pOld = GetSbData()->pCompMod;
GetSbData()->pCompMod = this;
- SbiParser* pParser = new SbiParser( (StarBASIC*) GetParent(), this );
+ boost::scoped_ptr<SbiParser> pParser(new SbiParser( (StarBASIC*) GetParent(), this ));
while( pParser->Parse() ) {}
if( !pParser->GetErrors() )
pParser->aGen.Save();
- delete pParser;
+ pParser.reset();
// for the disassembler
if( pImage )
pImage->aOUSource = aOUSource;
diff --git a/basic/source/runtime/inputbox.cxx b/basic/source/runtime/inputbox.cxx
index 152d625e46f7..bec0dfbfa666 100644
--- a/basic/source/runtime/inputbox.cxx
+++ b/basic/source/runtime/inputbox.cxx
@@ -26,6 +26,7 @@
#include "runtime.hxx"
#include "stdobj.hxx"
#include "rtlproto.hxx"
+#include <boost/scoped_ptr.hpp>
class SvRTLInputBox : public ModalDialog
{
@@ -171,11 +172,10 @@ RTLFUNC(InputBox)
nX = rPar.Get(4)->GetLong();
nY = rPar.Get(5)->GetLong();
}
- SvRTLInputBox *pDlg=new SvRTLInputBox(GetpApp()->GetDefDialogParent(),
- rPrompt,aTitle,aDefault,nX,nY);
+ boost::scoped_ptr<SvRTLInputBox> pDlg(new SvRTLInputBox(GetpApp()->GetDefDialogParent(),
+ rPrompt,aTitle,aDefault,nX,nY));
pDlg->Execute();
rPar.Get(0)->PutString( pDlg->GetText() );
- delete pDlg;
}
}
diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx
index 2e3c375699b2..02d51db51f92 100644
--- a/basic/source/runtime/methods.cxx
+++ b/basic/source/runtime/methods.cxx
@@ -57,6 +57,7 @@
#include <ooo/vba/XHelperInterface.hpp>
#include <com/sun/star/bridge/oleautomation/XAutomationObject.hpp>
#include <boost/scoped_array.hpp>
+#include <boost/scoped_ptr.hpp>
using namespace comphelper;
using namespace osl;
@@ -4475,8 +4476,8 @@ RTLFUNC(LoadPicture)
}
OUString aFileURL = getFullPath( rPar.Get(1)->GetOUString() );
- SvStream* pStream = utl::UcbStreamHelper::CreateStream( aFileURL, STREAM_READ );
- if( pStream != NULL )
+ boost::scoped_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream( aFileURL, STREAM_READ ));
+ if( pStream )
{
Bitmap aBmp;
ReadDIB(aBmp, *pStream, true);
@@ -4486,7 +4487,6 @@ RTLFUNC(LoadPicture)
((SbStdPicture*)(SbxObject*)xRef)->SetGraphic( aGraphic );
rPar.Get(0)->PutObject( xRef );
}
- delete pStream;
}
RTLFUNC(SavePicture)
@@ -4601,7 +4601,7 @@ RTLFUNC(MsgBox)
}
nType &= (16+32+64);
- MessBox* pBox = 0;
+ boost::scoped_ptr<MessBox> pBox;
SolarMutexGuard aSolarGuard;
@@ -4609,19 +4609,19 @@ RTLFUNC(MsgBox)
switch( nType )
{
case 16:
- pBox = new ErrorBox( pParent, nWinBits, aMsg );
+ pBox.reset(new ErrorBox( pParent, nWinBits, aMsg ));
break;
case 32:
- pBox = new QueryBox( pParent, nWinBits, aMsg );
+ pBox.reset(new QueryBox( pParent, nWinBits, aMsg ));
break;
case 48:
- pBox = new WarningBox( pParent, nWinBits, aMsg );
+ pBox.reset(new WarningBox( pParent, nWinBits, aMsg ));
break;
case 64:
- pBox = new InfoBox( pParent, nWinBits, aMsg );
+ pBox.reset(new InfoBox( pParent, nWinBits, aMsg ));
break;
default:
- pBox = new MessBox( pParent, nWinBits, aTitle, aMsg );
+ pBox.reset(new MessBox( pParent, nWinBits, aTitle, aMsg ));
}
pBox->SetText( aTitle );
sal_uInt16 nRet = (sal_uInt16)pBox->Execute();
@@ -4643,7 +4643,6 @@ RTLFUNC(MsgBox)
nMappedRet = nButtonMap[ nRet ];
}
rPar.Get(0)->PutInteger( nMappedRet );
- delete pBox;
}
RTLFUNC(SetAttr)