Kaydet (Commit) c414389e authored tarafından Takeshi Abe's avatar Takeshi Abe

Avoid possible memory leaks in case of exceptions

Change-Id: I46d49b515f5212a34612e80a82a3330a041b956c
üst 6a9d51b2
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#include <svtools/svtresid.hxx> #include <svtools/svtresid.hxx>
#include <svtools/svtools.hrc> #include <svtools/svtools.hrc>
#include <svtools/sfxecode.hxx> #include <svtools/sfxecode.hxx>
#include <boost/scoped_ptr.hpp>
static sal_uInt16 aWndFunc( static sal_uInt16 aWndFunc(
...@@ -89,29 +89,28 @@ static sal_uInt16 aWndFunc( ...@@ -89,29 +89,28 @@ static sal_uInt16 aWndFunc(
aErr = aErr.replaceAll("$(ACTION)", aAction); aErr = aErr.replaceAll("$(ACTION)", aAction);
aErr = aErr.replaceAll("$(ERROR)", rErr); aErr = aErr.replaceAll("$(ERROR)", rErr);
MessBox* pBox; boost::scoped_ptr<MessBox> pBox;
switch ( nFlags & 0xf000 ) switch ( nFlags & 0xf000 )
{ {
case ERRCODE_MSG_ERROR: case ERRCODE_MSG_ERROR:
pBox = new ErrorBox(pWin, eBits, aErr); pBox.reset(new ErrorBox(pWin, eBits, aErr));
break; break;
case ERRCODE_MSG_WARNING: case ERRCODE_MSG_WARNING:
pBox = new WarningBox(pWin, eBits, aErr); pBox.reset(new WarningBox(pWin, eBits, aErr));
break; break;
case ERRCODE_MSG_INFO: case ERRCODE_MSG_INFO:
pBox = new InfoBox(pWin, aErr); pBox.reset(new InfoBox(pWin, aErr));
break; break;
case ERRCODE_MSG_QUERY: case ERRCODE_MSG_QUERY:
pBox = new QueryBox(pWin, eBits, aErr); pBox.reset(new QueryBox(pWin, eBits, aErr));
break; break;
default: default:
{ {
SAL_WARN( "svtools.misc", "no MessBox type"); SAL_WARN( "svtools.misc", "no MessBox type");
pBox = NULL;
return ERRCODE_BUTTON_OK; return ERRCODE_BUTTON_OK;
} }
} }
...@@ -138,7 +137,6 @@ static sal_uInt16 aWndFunc( ...@@ -138,7 +137,6 @@ static sal_uInt16 aWndFunc(
SAL_WARN( "svtools.misc", "Unknown MessBox return value" ); SAL_WARN( "svtools.misc", "Unknown MessBox return value" );
break; break;
} }
delete pBox;
return nRet; return nRet;
} }
...@@ -278,7 +276,7 @@ bool SfxErrorHandler::GetClassString(sal_uLong lClassId, OUString &rStr) const ...@@ -278,7 +276,7 @@ bool SfxErrorHandler::GetClassString(sal_uLong lClassId, OUString &rStr) const
{ {
bool bRet = false; bool bRet = false;
ResMgr* pResMgr = ResMgr::CreateResMgr("ofa", Application::GetSettings().GetUILanguageTag() ); boost::scoped_ptr<ResMgr> pResMgr(ResMgr::CreateResMgr("ofa", Application::GetSettings().GetUILanguageTag() ));
if( pResMgr ) if( pResMgr )
{ {
ResId aId(RID_ERRHDL, *pResMgr ); ResId aId(RID_ERRHDL, *pResMgr );
...@@ -289,7 +287,6 @@ bool SfxErrorHandler::GetClassString(sal_uLong lClassId, OUString &rStr) const ...@@ -289,7 +287,6 @@ bool SfxErrorHandler::GetClassString(sal_uLong lClassId, OUString &rStr) const
bRet = true; bRet = true;
} }
} }
delete pResMgr;
return bRet; return bRet;
} }
...@@ -306,7 +303,7 @@ bool SfxErrorHandler::GetMessageString( ...@@ -306,7 +303,7 @@ bool SfxErrorHandler::GetMessageString(
{ {
bool bRet = false; bool bRet = false;
ResId *pResId= new ResId(nId, *pMgr); boost::scoped_ptr<ResId> pResId(new ResId(nId, *pMgr));
ErrorResource_Impl aEr(*pResId, (sal_uInt16)lErrId); ErrorResource_Impl aEr(*pResId, (sal_uInt16)lErrId);
if(aEr) if(aEr)
...@@ -319,7 +316,6 @@ bool SfxErrorHandler::GetMessageString( ...@@ -319,7 +316,6 @@ bool SfxErrorHandler::GetMessageString(
bRet = true; bRet = true;
} }
delete pResId;
return bRet; return bRet;
} }
......
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
#include <cppuhelper/implbase4.hxx> #include <cppuhelper/implbase4.hxx>
#include <vcl/svapp.hxx> #include <vcl/svapp.hxx>
#include <osl/mutex.hxx> #include <osl/mutex.hxx>
#include <boost/scoped_ptr.hpp>
using namespace com::sun::star; using namespace com::sun::star;
...@@ -432,14 +433,13 @@ void EmbeddedObjectRef::GetReplacement( bool bUpdate ) ...@@ -432,14 +433,13 @@ void EmbeddedObjectRef::GetReplacement( bool bUpdate )
return; return;
} }
SvStream* pGraphicStream = GetGraphicStream( bUpdate ); boost::scoped_ptr<SvStream> pGraphicStream(GetGraphicStream( bUpdate ));
if ( pGraphicStream ) if ( pGraphicStream )
{ {
GraphicFilter& rGF = GraphicFilter::GetGraphicFilter(); GraphicFilter& rGF = GraphicFilter::GetGraphicFilter();
if( mpImpl->pGraphic ) if( mpImpl->pGraphic )
rGF.ImportGraphic( *mpImpl->pGraphic, OUString(), *pGraphicStream, GRFILTER_FORMAT_DONTKNOW ); rGF.ImportGraphic( *mpImpl->pGraphic, OUString(), *pGraphicStream, GRFILTER_FORMAT_DONTKNOW );
mpImpl->mnGraphicVersion++; mpImpl->mnGraphicVersion++;
delete pGraphicStream;
} }
} }
...@@ -531,7 +531,7 @@ void EmbeddedObjectRef::SetGraphicStream( const uno::Reference< io::XInputStream ...@@ -531,7 +531,7 @@ void EmbeddedObjectRef::SetGraphicStream( const uno::Reference< io::XInputStream
mpImpl->aMediaType = rMediaType; mpImpl->aMediaType = rMediaType;
mpImpl->mnGraphicVersion++; mpImpl->mnGraphicVersion++;
SvStream* pGraphicStream = ::utl::UcbStreamHelper::CreateStream( xInGrStream ); boost::scoped_ptr<SvStream> pGraphicStream(::utl::UcbStreamHelper::CreateStream( xInGrStream ));
if ( pGraphicStream ) if ( pGraphicStream )
{ {
...@@ -542,12 +542,10 @@ void EmbeddedObjectRef::SetGraphicStream( const uno::Reference< io::XInputStream ...@@ -542,12 +542,10 @@ void EmbeddedObjectRef::SetGraphicStream( const uno::Reference< io::XInputStream
if ( mpImpl->pContainer ) if ( mpImpl->pContainer )
{ {
pGraphicStream->Seek( 0 ); pGraphicStream->Seek( 0 );
uno::Reference< io::XInputStream > xInSeekGrStream = new ::utl::OSeekableInputStreamWrapper( pGraphicStream ); uno::Reference< io::XInputStream > xInSeekGrStream = new ::utl::OSeekableInputStreamWrapper( pGraphicStream.get() );
mpImpl->pContainer->InsertGraphicStream( xInSeekGrStream, mpImpl->aPersistName, rMediaType ); mpImpl->pContainer->InsertGraphicStream( xInSeekGrStream, mpImpl->aPersistName, rMediaType );
} }
delete pGraphicStream;
} }
mpImpl->bNeedUpdate = false; mpImpl->bNeedUpdate = false;
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
#include <boost/scoped_ptr.hpp>
#define SCALEPOINT(aPT,aFracX,aFracY) (aPT).X()=((aPT).X()*(aFracX).GetNumerator())/(aFracX).GetDenominator(); \ #define SCALEPOINT(aPT,aFracX,aFracY) (aPT).X()=((aPT).X()*(aFracX).GetNumerator())/(aFracX).GetDenominator(); \
...@@ -78,7 +78,6 @@ sal_uInt16 IMapObject::GetVersion() const ...@@ -78,7 +78,6 @@ sal_uInt16 IMapObject::GetVersion() const
void IMapObject::Write( SvStream& rOStm, const OUString& rBaseURL ) const void IMapObject::Write( SvStream& rOStm, const OUString& rBaseURL ) const
{ {
IMapCompat* pCompat;
const rtl_TextEncoding eEncoding = osl_getThreadTextEncoding(); const rtl_TextEncoding eEncoding = osl_getThreadTextEncoding();
rOStm.WriteUInt16( GetType() ); rOStm.WriteUInt16( GetType() );
...@@ -92,13 +91,11 @@ void IMapObject::Write( SvStream& rOStm, const OUString& rBaseURL ) const ...@@ -92,13 +91,11 @@ void IMapObject::Write( SvStream& rOStm, const OUString& rBaseURL ) const
rOStm.WriteUChar( bActive ); rOStm.WriteUChar( bActive );
write_uInt16_lenPrefixed_uInt8s_FromOUString(rOStm, aTarget, eEncoding); write_uInt16_lenPrefixed_uInt8s_FromOUString(rOStm, aTarget, eEncoding);
pCompat = new IMapCompat( rOStm, STREAM_WRITE ); boost::scoped_ptr<IMapCompat> pCompat(new IMapCompat( rOStm, STREAM_WRITE ));
WriteIMapObject( rOStm ); WriteIMapObject( rOStm );
aEventList.Write( rOStm ); // V4 aEventList.Write( rOStm ); // V4
write_uInt16_lenPrefixed_uInt8s_FromOUString(rOStm, aName, eEncoding); // V5 write_uInt16_lenPrefixed_uInt8s_FromOUString(rOStm, aName, eEncoding); // V5
delete pCompat;
} }
...@@ -110,7 +107,6 @@ void IMapObject::Write( SvStream& rOStm, const OUString& rBaseURL ) const ...@@ -110,7 +107,6 @@ void IMapObject::Write( SvStream& rOStm, const OUString& rBaseURL ) const
void IMapObject::Read( SvStream& rIStm, const OUString& rBaseURL ) void IMapObject::Read( SvStream& rIStm, const OUString& rBaseURL )
{ {
IMapCompat* pCompat;
rtl_TextEncoding nTextEncoding; rtl_TextEncoding nTextEncoding;
// read on type and version // read on type and version
...@@ -124,7 +120,7 @@ void IMapObject::Read( SvStream& rIStm, const OUString& rBaseURL ) ...@@ -124,7 +120,7 @@ void IMapObject::Read( SvStream& rIStm, const OUString& rBaseURL )
// make URL absolute // make URL absolute
aURL = URIHelper::SmartRel2Abs( INetURLObject(rBaseURL), aURL, URIHelper::GetMaybeFileHdl(), true, false, INetURLObject::WAS_ENCODED, INetURLObject::DECODE_UNAMBIGUOUS ); aURL = URIHelper::SmartRel2Abs( INetURLObject(rBaseURL), aURL, URIHelper::GetMaybeFileHdl(), true, false, INetURLObject::WAS_ENCODED, INetURLObject::DECODE_UNAMBIGUOUS );
pCompat = new IMapCompat( rIStm, STREAM_READ ); boost::scoped_ptr<IMapCompat> pCompat(new IMapCompat( rIStm, STREAM_READ ));
ReadIMapObject( rIStm ); ReadIMapObject( rIStm );
...@@ -137,8 +133,6 @@ void IMapObject::Read( SvStream& rIStm, const OUString& rBaseURL ) ...@@ -137,8 +133,6 @@ void IMapObject::Read( SvStream& rIStm, const OUString& rBaseURL )
if ( nReadVersion >= 0x0005 ) if ( nReadVersion >= 0x0005 )
aName = read_uInt16_lenPrefixed_uInt8s_ToOUString(rIStm, nTextEncoding); aName = read_uInt16_lenPrefixed_uInt8s_ToOUString(rIStm, nTextEncoding);
} }
delete pCompat;
} }
bool IMapObject::IsEqual( const IMapObject& rEqObj ) bool IMapObject::IsEqual( const IMapObject& rEqObj )
......
...@@ -59,7 +59,7 @@ ...@@ -59,7 +59,7 @@
#include <vcl/dibtools.hxx> #include <vcl/dibtools.hxx>
#include <vcl/pngread.hxx> #include <vcl/pngread.hxx>
#include <vcl/pngwrite.hxx> #include <vcl/pngwrite.hxx>
#include <boost/scoped_ptr.hpp>
// - Namespaces - // - Namespaces -
...@@ -351,11 +351,11 @@ Any SAL_CALL TransferableHelper::getTransferData2( const DataFlavor& rFlavor, co ...@@ -351,11 +351,11 @@ Any SAL_CALL TransferableHelper::getTransferData2( const DataFlavor& rFlavor, co
if( maAny >>= aSeq ) if( maAny >>= aSeq )
{ {
SvMemoryStream* pSrcStm = new SvMemoryStream( (char*) aSeq.getConstArray(), aSeq.getLength(), STREAM_WRITE | STREAM_TRUNC ); boost::scoped_ptr<SvMemoryStream> pSrcStm(new SvMemoryStream( (char*) aSeq.getConstArray(), aSeq.getLength(), STREAM_WRITE | STREAM_TRUNC ));
GDIMetaFile aMtf; GDIMetaFile aMtf;
ReadGDIMetaFile( *pSrcStm, aMtf ); ReadGDIMetaFile( *pSrcStm, aMtf );
delete pSrcStm; pSrcStm.reset();
Graphic aGraphic( aMtf ); Graphic aGraphic( aMtf );
SvMemoryStream aDstStm( 65535, 65535 ); SvMemoryStream aDstStm( 65535, 65535 );
...@@ -381,11 +381,11 @@ Any SAL_CALL TransferableHelper::getTransferData2( const DataFlavor& rFlavor, co ...@@ -381,11 +381,11 @@ Any SAL_CALL TransferableHelper::getTransferData2( const DataFlavor& rFlavor, co
if( maAny >>= aSeq ) if( maAny >>= aSeq )
{ {
SvMemoryStream* pSrcStm = new SvMemoryStream( (char*) aSeq.getConstArray(), aSeq.getLength(), STREAM_WRITE | STREAM_TRUNC ); boost::scoped_ptr<SvMemoryStream> pSrcStm(new SvMemoryStream( (char*) aSeq.getConstArray(), aSeq.getLength(), STREAM_WRITE | STREAM_TRUNC ));
GDIMetaFile aMtf; GDIMetaFile aMtf;
ReadGDIMetaFile( *pSrcStm, aMtf ); ReadGDIMetaFile( *pSrcStm, aMtf );
delete pSrcStm; pSrcStm.reset();
SvMemoryStream aDstStm( 65535, 65535 ); SvMemoryStream aDstStm( 65535, 65535 );
...@@ -2017,22 +2017,21 @@ bool TransferableDataHelper::GetINetBookmark( const ::com::sun::star::datatransf ...@@ -2017,22 +2017,21 @@ bool TransferableDataHelper::GetINetBookmark( const ::com::sun::star::datatransf
if( ( aDesc.getLength() > 4 ) && aDesc.copy(aDesc.getLength() - 4).equalsIgnoreAsciiCase(".URL") ) if( ( aDesc.getLength() > 4 ) && aDesc.copy(aDesc.getLength() - 4).equalsIgnoreAsciiCase(".URL") )
{ {
SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( INetURLObject( OStringToOUString(aDesc, eTextEncoding) ).GetMainURL( INetURLObject::NO_DECODE ), boost::scoped_ptr<SvStream> pStream(::utl::UcbStreamHelper::CreateStream( INetURLObject( OStringToOUString(aDesc, eTextEncoding) ).GetMainURL( INetURLObject::NO_DECODE ),
STREAM_STD_READ ); STREAM_STD_READ ));
if( !pStream || pStream->GetError() ) if( !pStream || pStream->GetError() )
{ {
DataFlavor aFileContentFlavor; DataFlavor aFileContentFlavor;
aSeq.realloc( 0 ); aSeq.realloc( 0 );
delete pStream; pStream.reset();
pStream = NULL;
if (SotExchange::GetFormatDataFlavor(SOT_FORMATSTR_ID_FILECONTENT, aFileContentFlavor)) if (SotExchange::GetFormatDataFlavor(SOT_FORMATSTR_ID_FILECONTENT, aFileContentFlavor))
{ {
aSeq = GetSequence(aFileContentFlavor, OUString()); aSeq = GetSequence(aFileContentFlavor, OUString());
if (aSeq.getLength()) if (aSeq.getLength())
pStream = new SvMemoryStream( (sal_Char*) aSeq.getConstArray(), aSeq.getLength(), STREAM_STD_READ ); pStream.reset(new SvMemoryStream( (sal_Char*) aSeq.getConstArray(), aSeq.getLength(), STREAM_STD_READ ));
} }
} }
...@@ -2053,8 +2052,6 @@ bool TransferableDataHelper::GetINetBookmark( const ::com::sun::star::datatransf ...@@ -2053,8 +2052,6 @@ bool TransferableDataHelper::GetINetBookmark( const ::com::sun::star::datatransf
break; break;
} }
} }
delete pStream;
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment