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