diff options
author | Takeshi Abe <tabe@fixedpoint.jp> | 2014-05-31 00:09:32 +0900 |
---|---|---|
committer | Takeshi Abe <tabe@fixedpoint.jp> | 2014-05-31 00:35:27 +0900 |
commit | 6a53ea218c669b99aa9a51ce77898845f262b6e0 (patch) | |
tree | a0466ab24ec5046475f35b8dc8c47f3a386040a4 /basic | |
parent | 95c0bc061d7f4cd218a0594eb66b504d4d308fad (diff) |
Avoid possible memory leaks in case of exceptions
Change-Id: Iad3de981a1c9660b1322315640e531c9891db0bf
Diffstat (limited to 'basic')
-rw-r--r-- | basic/source/runtime/runtime.cxx | 11 | ||||
-rw-r--r-- | basic/source/sbx/sbxdate.cxx | 8 | ||||
-rw-r--r-- | basic/source/uno/namecont.cxx | 13 | ||||
-rw-r--r-- | basic/source/uno/scriptcont.cxx | 12 |
4 files changed, 16 insertions, 28 deletions
diff --git a/basic/source/runtime/runtime.cxx b/basic/source/runtime/runtime.cxx index 43da65808b8a..e13855be478f 100644 --- a/basic/source/runtime/runtime.cxx +++ b/basic/source/runtime/runtime.cxx @@ -2279,9 +2279,9 @@ void SbiRuntime::StepREDIMP() else if (nDims > 0) { // Store dims to use them for copying later - 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]); // Compare bounds for( short i = 1 ; i <= nDims ; i++ ) @@ -2300,10 +2300,7 @@ void SbiRuntime::StepREDIMP() // (It would be faster to work on the flat internal data array of an // SbyArray but this solution is clearer and easier) implCopyDimArray( pNewArray, pOldArray, nDims - 1, - 0, pActualIndices, pLowerBounds, pUpperBounds ); - delete[] pUpperBounds; - delete[] pLowerBounds; - delete[] pActualIndices; + 0, pActualIndices.get(), pLowerBounds.get(), pUpperBounds.get() ); } refRedimpArray = NULL; diff --git a/basic/source/sbx/sbxdate.cxx b/basic/source/sbx/sbxdate.cxx index 751c7e101ce5..ec2da435ac9d 100644 --- a/basic/source/sbx/sbxdate.cxx +++ b/basic/source/sbx/sbxdate.cxx @@ -27,6 +27,7 @@ #include "sbxconv.hxx" #include "math.h" #include <comphelper/processfactory.hxx> +#include <boost/scoped_ptr.hpp> double ImpGetDate( const SbxValues* p ) @@ -99,7 +100,7 @@ double ImpGetDate( const SbxValues* p ) { LanguageType eLangType = GetpApp()->GetSettings().GetLanguageTag().getLanguageType(); - SvNumberFormatter* pFormatter = new SvNumberFormatter( comphelper::getProcessComponentContext(), eLangType ); + boost::scoped_ptr<SvNumberFormatter> pFormatter(new SvNumberFormatter( comphelper::getProcessComponentContext(), eLangType )); sal_uInt32 nIndex; sal_Int32 nCheckPos = 0; @@ -144,8 +145,6 @@ double ImpGetDate( const SbxValues* p ) { SbxBase::SetError( SbxERR_CONVERSION ); nRes = 0; } - - delete pFormatter; } break; case SbxOBJECT: @@ -269,7 +268,7 @@ start: Color* pColor; LanguageType eLangType = GetpApp()->GetSettings().GetLanguageTag().getLanguageType(); - SvNumberFormatter* pFormatter = new SvNumberFormatter( comphelper::getProcessComponentContext(), eLangType ); + boost::scoped_ptr<SvNumberFormatter> pFormatter(new SvNumberFormatter( comphelper::getProcessComponentContext(), eLangType )); sal_uInt32 nIndex; sal_Int32 nCheckPos = 0; @@ -314,7 +313,6 @@ start: LANGUAGE_GERMAN, eLangType ); pFormatter->GetOutputString( n, nIndex, *p->pOUString, &pColor ); - delete pFormatter; break; } case SbxOBJECT: diff --git a/basic/source/uno/namecont.cxx b/basic/source/uno/namecont.cxx index e7cf8f34d11c..78fbb357a966 100644 --- a/basic/source/uno/namecont.cxx +++ b/basic/source/uno/namecont.cxx @@ -757,7 +757,7 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL, } else { - INetURLObject* pLibInfoInetObj = NULL; + boost::scoped_ptr<INetURLObject> pLibInfoInetObj; if( meInitMode == CONTAINER_INIT_FILE ) { aFileName = aInitFileName; @@ -766,11 +766,11 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL, { if( nPass == 1 ) { - pLibInfoInetObj = new INetURLObject( maLibraryPath.getToken(0, (sal_Unicode)';') ); + pLibInfoInetObj.reset(new INetURLObject( maLibraryPath.getToken(0, (sal_Unicode)';') )); } else { - pLibInfoInetObj = new INetURLObject( maLibraryPath.getToken(1, (sal_Unicode)';') ); + pLibInfoInetObj.reset(new INetURLObject( maLibraryPath.getToken(1, (sal_Unicode)';') )); } pLibInfoInetObj->insertName( maInfoFileName, false, INetURLObject::LAST_SEGMENT, true, INetURLObject::ENCODE_ALL ); pLibInfoInetObj->setExtension( OUString("xlc") ); @@ -805,8 +805,6 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL, xInput.clear(); } } - - delete pLibInfoInetObj; } if( xInput.is() ) @@ -816,11 +814,11 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL, source.sSystemId = aFileName; // start parsing - ::xmlscript::LibDescriptorArray* pLibArray = new ::xmlscript::LibDescriptorArray(); + boost::scoped_ptr< ::xmlscript::LibDescriptorArray> pLibArray(new ::xmlscript::LibDescriptorArray()); try { - xParser->setDocumentHandler( ::xmlscript::importLibraryContainer( pLibArray ) ); + xParser->setDocumentHandler( ::xmlscript::importLibraryContainer( pLibArray.get() ) ); xParser->parseStream( source ); } catch ( const xml::sax::SAXException& e ) @@ -973,7 +971,6 @@ void SfxLibraryContainer::init_Impl( const OUString& rInitialDocumentURL, { mbOldInfoFormat = false; } - delete pLibArray; } } diff --git a/basic/source/uno/scriptcont.cxx b/basic/source/uno/scriptcont.cxx index 1606bfc7b556..4bf45cf30e87 100644 --- a/basic/source/uno/scriptcont.cxx +++ b/basic/source/uno/scriptcont.cxx @@ -59,6 +59,8 @@ #include <com/sun/star/util/VetoException.hpp> #include <com/sun/star/script/XLibraryQueryExecutable.hpp> #include <cppuhelper/implbase1.hxx> +#include <boost/scoped_ptr.hpp> + namespace basic { @@ -975,11 +977,10 @@ bool SfxScriptLibraryContainer::implLoadPasswordLibrary { throw uno::RuntimeException(); } - SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( xCodeStream ); + boost::scoped_ptr<SvStream> pStream(::utl::UcbStreamHelper::CreateStream( xCodeStream )); if ( !pStream || pStream->GetError() ) { sal_Int32 nError = pStream ? pStream->GetError() : ERRCODE_IO_GENERAL; - delete pStream; throw task::ErrorCodeIOException( ("utl::UcbStreamHelper::CreateStream failed for \"" + aCodeStreamName + "\": 0x" @@ -989,8 +990,6 @@ bool SfxScriptLibraryContainer::implLoadPasswordLibrary /*sal_Bool bRet = */pMod->LoadBinaryData( *pStream ); // TODO: Check return value - - delete pStream; } catch(const uno::Exception& ) { @@ -1093,11 +1092,10 @@ bool SfxScriptLibraryContainer::implLoadPasswordLibrary aCodeStreamName, embed::ElementModes::READ ); - SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( xCodeStream ); + boost::scoped_ptr<SvStream> pStream(::utl::UcbStreamHelper::CreateStream( xCodeStream )); if ( !pStream || pStream->GetError() ) { sal_Int32 nError = pStream ? pStream->GetError() : ERRCODE_IO_GENERAL; - delete pStream; throw task::ErrorCodeIOException( ("utl::UcbStreamHelper::CreateStream failed" " for code.bin: 0x" @@ -1108,8 +1106,6 @@ bool SfxScriptLibraryContainer::implLoadPasswordLibrary /*sal_Bool bRet = */pMod->LoadBinaryData( *pStream ); // TODO: Check return value - - delete pStream; } catch(const uno::Exception& ) { |