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 <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() );
}
}
}

View File

@ -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()

View File

@ -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 )

View File

@ -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;
}

View File

@ -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 ) &&

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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)