Avoid possible memory leaks in case of exceptions

Change-Id: Iac63a5d60478e5cd8e2b77c889c7b312d3d15f67
This commit is contained in:
Takeshi Abe 2014-05-29 09:27:30 +09:00
parent 7c8b2f1031
commit a71ae24a23
8 changed files with 42 additions and 45 deletions

View File

@ -93,6 +93,7 @@ using namespace cppu;
#include <runtime.hxx> #include <runtime.hxx>
#include <math.h> #include <math.h>
#include <boost/scoped_array.hpp>
#include <boost/unordered_map.hpp> #include <boost/unordered_map.hpp>
#include <com/sun/star/reflection/XTypeDescriptionEnumerationAccess.hpp> #include <com/sun/star/reflection/XTypeDescriptionEnumerationAccess.hpp>
#include <com/sun/star/reflection/XConstantsTypeDescription.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 ) if( nSeqLevel == nDims )
{ {
sal_Int32* pLowerBounds = new sal_Int32[nDims]; boost::scoped_array<sal_Int32> pLowerBounds(new sal_Int32[nDims]);
sal_Int32* pUpperBounds = new sal_Int32[nDims]; boost::scoped_array<sal_Int32> pUpperBounds(new sal_Int32[nDims]);
sal_Int32* pActualIndices = new sal_Int32[nDims]; boost::scoped_array<sal_Int32> pActualIndices(new sal_Int32[nDims]);
for( short i = 1 ; i <= nDims ; i++ ) for( short i = 1 ; i <= nDims ; i++ )
{ {
sal_Int32 lBound, uBound; sal_Int32 lBound, uBound;
@ -1413,11 +1414,7 @@ Any sbxToUnoValue( const SbxValue* pVar, const Type& rType, Property* pUnoProper
} }
aRetVal = implRekMultiDimArrayToSequence( pArray, aElemType, aRetVal = implRekMultiDimArrayToSequence( pArray, aElemType,
nDims - 1, 0, pActualIndices, pLowerBounds, pUpperBounds ); nDims - 1, 0, pActualIndices.get(), pLowerBounds.get(), pUpperBounds.get() );
delete[] pUpperBounds;
delete[] pLowerBounds;
delete[] pActualIndices;
} }
} }
} }

View File

@ -21,6 +21,7 @@
#include <list> #include <list>
#include <boost/noncopyable.hpp> #include <boost/noncopyable.hpp>
#include <boost/scoped_ptr.hpp>
#include <vcl/svapp.hxx> #include <vcl/svapp.hxx>
#include <tools/stream.hxx> #include <tools/stream.hxx>
#include <svl/brdcst.hxx> #include <svl/brdcst.hxx>
@ -1779,7 +1780,7 @@ void SbModule::GetCodeCompleteDataFromParse(CodeCompleteDataCache& aCache)
ErrorHdlResetter aErrHdl; ErrorHdlResetter aErrHdl;
SbxBase::ResetError(); SbxBase::ResetError();
SbiParser* pParser = new SbiParser( (StarBASIC*) GetParent(), this ); boost::scoped_ptr<SbiParser> pParser(new SbiParser( (StarBASIC*) GetParent(), this ));
pParser->SetCodeCompleting(true); pParser->SetCodeCompleting(true);
while( pParser->Parse() ) {} while( pParser->Parse() ) {}
@ -1801,7 +1802,6 @@ void SbModule::GetCodeCompleteDataFromParse(CodeCompleteDataCache& aCache)
aCache.InsertLocalVar( pSymDef->GetName(), pChildSymDef->GetName(), pParser->aGblStrings.Find(pChildSymDef->GetTypeId()) ); aCache.InsertLocalVar( pSymDef->GetName(), pChildSymDef->GetName(), pParser->aGblStrings.Find(pChildSymDef->GetTypeId()) );
} }
} }
delete pParser;
} }
SbxArrayRef SbModule::GetMethods() SbxArrayRef SbModule::GetMethods()

View File

@ -29,6 +29,7 @@
#include <com/sun/star/reflection/XIdlMethod.hpp> #include <com/sun/star/reflection/XIdlMethod.hpp>
#include <com/sun/star/uno/Exception.hpp> #include <com/sun/star/uno/Exception.hpp>
#include <basic/codecompletecache.hxx> #include <basic/codecompletecache.hxx>
#include <boost/scoped_ptr.hpp>
using namespace ::com::sun::star; using namespace ::com::sun::star;
using namespace ::com::sun::star::uno; using namespace ::com::sun::star::uno;
@ -965,7 +966,7 @@ SbiProcDef* SbiParser::ProcDecl( bool bDecl )
bool bError2 = true; bool bError2 = true;
if( bOptional && bCompatible && eTok == EQ ) if( bOptional && bCompatible && eTok == EQ )
{ {
SbiConstExpression* pDefaultExpr = new SbiConstExpression( this ); boost::scoped_ptr<SbiConstExpression> pDefaultExpr(new SbiConstExpression( this ));
SbxDataType eType2 = pDefaultExpr->GetType(); SbxDataType eType2 = pDefaultExpr->GetType();
sal_uInt16 nStringId; sal_uInt16 nStringId;
@ -978,7 +979,7 @@ SbiProcDef* SbiParser::ProcDecl( bool bDecl )
nStringId = aGblStrings.Add( pDefaultExpr->GetValue(), eType2 ); nStringId = aGblStrings.Add( pDefaultExpr->GetValue(), eType2 );
} }
pPar->SetDefaultId( nStringId ); pPar->SetDefaultId( nStringId );
delete pDefaultExpr; pDefaultExpr.reset();
eTok = Next(); eTok = Next();
if( eTok == COMMA || eTok == RPAREN ) if( eTok == COMMA || eTok == RPAREN )

View File

@ -19,6 +19,7 @@
#include "sbcomp.hxx" #include "sbcomp.hxx"
#include "iosys.hxx" #include "iosys.hxx"
#include <boost/scoped_ptr.hpp>
// test if there's an I/O channel // test if there's an I/O channel
@ -51,9 +52,9 @@ void SbiParser::Print()
{ {
if( !IsEoln( Peek() ) ) if( !IsEoln( Peek() ) )
{ {
SbiExpression* pExpr = new SbiExpression( this ); boost::scoped_ptr<SbiExpression> pExpr(new SbiExpression( this ));
pExpr->Gen(); pExpr->Gen();
delete pExpr; pExpr.reset();
Peek(); Peek();
aGen.Gen( eCurTok == COMMA ? _PRINTF : _BPRINT ); aGen.Gen( eCurTok == COMMA ? _PRINTF : _BPRINT );
} }
@ -80,9 +81,9 @@ void SbiParser::Write()
while( !bAbort ) while( !bAbort )
{ {
SbiExpression* pExpr = new SbiExpression( this ); boost::scoped_ptr<SbiExpression> pExpr(new SbiExpression( this ));
pExpr->Gen(); pExpr->Gen();
delete pExpr; pExpr.reset();
aGen.Gen( _BWRITE ); aGen.Gen( _BWRITE );
if( Peek() == COMMA ) if( Peek() == COMMA )
{ {
@ -129,14 +130,14 @@ void SbiParser::Line()
void SbiParser::LineInput() void SbiParser::LineInput()
{ {
Channel( true ); Channel( true );
SbiExpression* pExpr = new SbiExpression( this, SbOPERAND ); boost::scoped_ptr<SbiExpression> pExpr(new SbiExpression( this, SbOPERAND ));
if( !pExpr->IsVariable() ) if( !pExpr->IsVariable() )
Error( SbERR_VAR_EXPECTED ); Error( SbERR_VAR_EXPECTED );
if( pExpr->GetType() != SbxVARIANT && pExpr->GetType() != SbxSTRING ) if( pExpr->GetType() != SbxVARIANT && pExpr->GetType() != SbxSTRING )
Error( SbERR_CONVERSION ); Error( SbERR_CONVERSION );
pExpr->Gen(); pExpr->Gen();
aGen.Gen( _LINPUT ); aGen.Gen( _LINPUT );
delete pExpr; pExpr.reset();
aGen.Gen( _CHAN0 ); // ResetChannel() not in StepLINPUT() anymore aGen.Gen( _CHAN0 ); // ResetChannel() not in StepLINPUT() anymore
} }
@ -146,7 +147,7 @@ void SbiParser::Input()
{ {
aGen.Gen( _RESTART ); aGen.Gen( _RESTART );
Channel( true ); Channel( true );
SbiExpression* pExpr = new SbiExpression( this, SbOPERAND ); boost::scoped_ptr<SbiExpression> pExpr(new SbiExpression( this, SbOPERAND ));
while( !bAbort ) while( !bAbort )
{ {
if( !pExpr->IsVariable() ) if( !pExpr->IsVariable() )
@ -156,12 +157,11 @@ void SbiParser::Input()
if( Peek() == COMMA ) if( Peek() == COMMA )
{ {
Next(); Next();
delete pExpr; pExpr.reset(new SbiExpression( this, SbOPERAND ));
pExpr = new SbiExpression( this, SbOPERAND );
} }
else break; else break;
} }
delete pExpr; pExpr.reset();
aGen.Gen( _CHAN0 ); aGen.Gen( _CHAN0 );
} }
@ -240,20 +240,20 @@ void SbiParser::Open()
} }
TestToken( AS ); TestToken( AS );
// channel number // channel number
SbiExpression* pChan = new SbiExpression( this ); boost::scoped_ptr<SbiExpression> pChan(new SbiExpression( this ));
if( !pChan ) if( !pChan )
Error( SbERR_SYNTAX ); Error( SbERR_SYNTAX );
SbiExpression* pLen = NULL; boost::scoped_ptr<SbiExpression> pLen;
if( Peek() == SYMBOL ) if( Peek() == SYMBOL )
{ {
Next(); Next();
if( aSym.equalsIgnoreAsciiCase("LEN") ) if( aSym.equalsIgnoreAsciiCase("LEN") )
{ {
TestToken( EQ ); 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: // the stack for the OPEN command looks as follows:
// block length // block length
// channel number // channel number
@ -263,8 +263,6 @@ void SbiParser::Open()
pChan->Gen(); pChan->Gen();
aFileName.Gen(); aFileName.Gen();
aGen.Gen( _OPEN, nMode, nFlags ); aGen.Gen( _OPEN, nMode, nFlags );
delete pLen;
delete pChan;
bInStatement = false; bInStatement = false;
} }

View File

@ -19,6 +19,7 @@
#include "sbcomp.hxx" #include "sbcomp.hxx"
#include <boost/scoped_ptr.hpp>
// Single-line IF and Multiline IF // Single-line IF and Multiline IF
@ -64,10 +65,10 @@ void SbiParser::If()
aGen.BackChain( nEndLbl ); aGen.BackChain( nEndLbl );
aGen.Statement(); aGen.Statement();
SbiExpression* pCond = new SbiExpression( this ); boost::scoped_ptr<SbiExpression> pCond(new SbiExpression( this ));
pCond->Gen(); pCond->Gen();
nEndLbl = aGen.Gen( _JUMPF, 0 ); nEndLbl = aGen.Gen( _JUMPF, 0 );
delete pCond; pCond.reset();
TestToken( THEN ); TestToken( THEN );
eTok = Peek(); eTok = Peek();
while( !( eTok == ELSEIF || eTok == ELSE || eTok == ENDIF ) && while( !( eTok == ELSEIF || eTok == ELSE || eTok == ENDIF ) &&

View File

@ -24,6 +24,7 @@
#include "sbobjmod.hxx" #include "sbobjmod.hxx"
#include <svtools/miscopt.hxx> #include <svtools/miscopt.hxx>
#include <stdio.h> #include <stdio.h>
#include <boost/scoped_ptr.hpp>
// To activate tracing enable in sbtrace.hxx // To activate tracing enable in sbtrace.hxx
#ifdef DBG_TRACE_BASIC #ifdef DBG_TRACE_BASIC
@ -954,11 +955,11 @@ bool SbModule::Compile()
SbModule* pOld = GetSbData()->pCompMod; SbModule* pOld = GetSbData()->pCompMod;
GetSbData()->pCompMod = this; GetSbData()->pCompMod = this;
SbiParser* pParser = new SbiParser( (StarBASIC*) GetParent(), this ); boost::scoped_ptr<SbiParser> pParser(new SbiParser( (StarBASIC*) GetParent(), this ));
while( pParser->Parse() ) {} while( pParser->Parse() ) {}
if( !pParser->GetErrors() ) if( !pParser->GetErrors() )
pParser->aGen.Save(); pParser->aGen.Save();
delete pParser; pParser.reset();
// for the disassembler // for the disassembler
if( pImage ) if( pImage )
pImage->aOUSource = aOUSource; pImage->aOUSource = aOUSource;

View File

@ -26,6 +26,7 @@
#include "runtime.hxx" #include "runtime.hxx"
#include "stdobj.hxx" #include "stdobj.hxx"
#include "rtlproto.hxx" #include "rtlproto.hxx"
#include <boost/scoped_ptr.hpp>
class SvRTLInputBox : public ModalDialog class SvRTLInputBox : public ModalDialog
{ {
@ -171,11 +172,10 @@ RTLFUNC(InputBox)
nX = rPar.Get(4)->GetLong(); nX = rPar.Get(4)->GetLong();
nY = rPar.Get(5)->GetLong(); nY = rPar.Get(5)->GetLong();
} }
SvRTLInputBox *pDlg=new SvRTLInputBox(GetpApp()->GetDefDialogParent(), boost::scoped_ptr<SvRTLInputBox> pDlg(new SvRTLInputBox(GetpApp()->GetDefDialogParent(),
rPrompt,aTitle,aDefault,nX,nY); rPrompt,aTitle,aDefault,nX,nY));
pDlg->Execute(); pDlg->Execute();
rPar.Get(0)->PutString( pDlg->GetText() ); rPar.Get(0)->PutString( pDlg->GetText() );
delete pDlg;
} }
} }

View File

@ -57,6 +57,7 @@
#include <ooo/vba/XHelperInterface.hpp> #include <ooo/vba/XHelperInterface.hpp>
#include <com/sun/star/bridge/oleautomation/XAutomationObject.hpp> #include <com/sun/star/bridge/oleautomation/XAutomationObject.hpp>
#include <boost/scoped_array.hpp> #include <boost/scoped_array.hpp>
#include <boost/scoped_ptr.hpp>
using namespace comphelper; using namespace comphelper;
using namespace osl; using namespace osl;
@ -4475,8 +4476,8 @@ RTLFUNC(LoadPicture)
} }
OUString aFileURL = getFullPath( rPar.Get(1)->GetOUString() ); OUString aFileURL = getFullPath( rPar.Get(1)->GetOUString() );
SvStream* pStream = utl::UcbStreamHelper::CreateStream( aFileURL, STREAM_READ ); boost::scoped_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream( aFileURL, STREAM_READ ));
if( pStream != NULL ) if( pStream )
{ {
Bitmap aBmp; Bitmap aBmp;
ReadDIB(aBmp, *pStream, true); ReadDIB(aBmp, *pStream, true);
@ -4486,7 +4487,6 @@ RTLFUNC(LoadPicture)
((SbStdPicture*)(SbxObject*)xRef)->SetGraphic( aGraphic ); ((SbStdPicture*)(SbxObject*)xRef)->SetGraphic( aGraphic );
rPar.Get(0)->PutObject( xRef ); rPar.Get(0)->PutObject( xRef );
} }
delete pStream;
} }
RTLFUNC(SavePicture) RTLFUNC(SavePicture)
@ -4601,7 +4601,7 @@ RTLFUNC(MsgBox)
} }
nType &= (16+32+64); nType &= (16+32+64);
MessBox* pBox = 0; boost::scoped_ptr<MessBox> pBox;
SolarMutexGuard aSolarGuard; SolarMutexGuard aSolarGuard;
@ -4609,19 +4609,19 @@ RTLFUNC(MsgBox)
switch( nType ) switch( nType )
{ {
case 16: case 16:
pBox = new ErrorBox( pParent, nWinBits, aMsg ); pBox.reset(new ErrorBox( pParent, nWinBits, aMsg ));
break; break;
case 32: case 32:
pBox = new QueryBox( pParent, nWinBits, aMsg ); pBox.reset(new QueryBox( pParent, nWinBits, aMsg ));
break; break;
case 48: case 48:
pBox = new WarningBox( pParent, nWinBits, aMsg ); pBox.reset(new WarningBox( pParent, nWinBits, aMsg ));
break; break;
case 64: case 64:
pBox = new InfoBox( pParent, nWinBits, aMsg ); pBox.reset(new InfoBox( pParent, nWinBits, aMsg ));
break; break;
default: default:
pBox = new MessBox( pParent, nWinBits, aTitle, aMsg ); pBox.reset(new MessBox( pParent, nWinBits, aTitle, aMsg ));
} }
pBox->SetText( aTitle ); pBox->SetText( aTitle );
sal_uInt16 nRet = (sal_uInt16)pBox->Execute(); sal_uInt16 nRet = (sal_uInt16)pBox->Execute();
@ -4643,7 +4643,6 @@ RTLFUNC(MsgBox)
nMappedRet = nButtonMap[ nRet ]; nMappedRet = nButtonMap[ nRet ];
} }
rPar.Get(0)->PutInteger( nMappedRet ); rPar.Get(0)->PutInteger( nMappedRet );
delete pBox;
} }
RTLFUNC(SetAttr) RTLFUNC(SetAttr)