Avoid possible memory leaks in case of exceptions

Change-Id: I4f1e00dd275976cdba8490f35ccbb491914829b7
This commit is contained in:
Takeshi Abe
2014-04-12 01:28:10 +09:00
parent 0ffe4358c7
commit 4e939b9599
6 changed files with 22 additions and 33 deletions

View File

@@ -120,6 +120,7 @@
#include <rtl/strbuf.hxx> #include <rtl/strbuf.hxx>
#include <tools/time.hxx> #include <tools/time.hxx>
#include <boost/scoped_array.hpp> #include <boost/scoped_array.hpp>
#include <boost/scoped_ptr.hpp>
// PPT ColorScheme Slots // PPT ColorScheme Slots
#define PPT_COLSCHEME (0x08000000) #define PPT_COLSCHEME (0x08000000)
@@ -1802,14 +1803,13 @@ SdrObject* SdrPowerPointImport::ImportOLE( long nOLEId,
if ( aTmpFile.IsValid() ) if ( aTmpFile.IsValid() )
{ {
SvStream* pDest = ::utl::UcbStreamHelper::CreateStream( aTmpFile.GetURL(), STREAM_TRUNC | STREAM_WRITE ); boost::scoped_ptr<SvStream> pDest(::utl::UcbStreamHelper::CreateStream( aTmpFile.GetURL(), STREAM_TRUNC | STREAM_WRITE ));
if ( pDest ) if ( pDest )
bSuccess = SdrPowerPointOLEDecompress( *pDest, rStCtrl, nLen ); bSuccess = SdrPowerPointOLEDecompress( *pDest, rStCtrl, nLen );
delete pDest;
} }
if ( bSuccess ) if ( bSuccess )
{ {
SvStream* pDest = ::utl::UcbStreamHelper::CreateStream( aTmpFile.GetURL(), STREAM_READ ); boost::scoped_ptr<SvStream> pDest(::utl::UcbStreamHelper::CreateStream( aTmpFile.GetURL(), STREAM_READ ));
Storage* pObjStor = pDest ? new Storage( *pDest, true ) : NULL; Storage* pObjStor = pDest ? new Storage( *pDest, true ) : NULL;
if ( pObjStor ) if ( pObjStor )
{ {
@@ -1915,7 +1915,6 @@ SdrObject* SdrPowerPointImport::ImportOLE( long nOLEId,
} }
} }
} }
delete pDest;
} }
} }
} }
@@ -2056,11 +2055,10 @@ void SdrPowerPointImport::SeekOle( SfxObjectShell* pShell, sal_uInt32 nFilterOpt
pHd = aDocRecManager.GetRecordHeader( PPT_PST_ExObjList, SEEK_FROM_BEGINNING ); pHd = aDocRecManager.GetRecordHeader( PPT_PST_ExObjList, SEEK_FROM_BEGINNING );
if ( pHd ) if ( pHd )
{ {
DffRecordManager* pExObjListManager = NULL;
DffRecordHeader* pExEmbed = NULL; DffRecordHeader* pExEmbed = NULL;
pHd->SeekToBegOfRecord( rStCtrl ); pHd->SeekToBegOfRecord( rStCtrl );
pExObjListManager = new DffRecordManager( rStCtrl ); boost::scoped_ptr<DffRecordManager> pExObjListManager(new DffRecordManager( rStCtrl ));
sal_uInt16 i, nRecType(PPT_PST_ExEmbed); sal_uInt16 i, nRecType(PPT_PST_ExEmbed);
for ( i = 0; i < 2; i++ ) for ( i = 0; i < 2; i++ )
@@ -2097,7 +2095,6 @@ void SdrPowerPointImport::SeekOle( SfxObjectShell* pShell, sal_uInt32 nFilterOpt
} }
} }
} }
delete pExObjListManager;
} }
rStCtrl.Seek( nOldPos ); rStCtrl.Seek( nOldPos );
} }
@@ -2254,12 +2251,11 @@ SdrObject* SdrPowerPointImport::ApplyTextObj( PPTTextObj* pTextObj, SdrTextObj*
for ( pPortion = pPara->First(); pPortion; pPortion = pPara->Next() ) for ( pPortion = pPara->First(); pPortion; pPortion = pPara->Next() )
{ {
SfxItemSet aPortionAttribs( rOutliner.GetEmptyItemSet() ); SfxItemSet aPortionAttribs( rOutliner.GetEmptyItemSet() );
SvxFieldItem* pFieldItem = pPortion->GetTextField(); boost::scoped_ptr<SvxFieldItem> pFieldItem(pPortion->GetTextField());
if ( pFieldItem ) if ( pFieldItem )
{ {
rOutliner.QuickInsertField( *pFieldItem, ESelection( nParaIndex, aSelection.nEndPos, nParaIndex, aSelection.nEndPos + 1 ) ); rOutliner.QuickInsertField( *pFieldItem, ESelection( nParaIndex, aSelection.nEndPos, nParaIndex, aSelection.nEndPos + 1 ) );
aSelection.nEndPos++; aSelection.nEndPos++;
delete pFieldItem;
} }
else else
{ {
@@ -2931,7 +2927,7 @@ SdrObject* SdrPowerPointImport::ImportPageBackgroundObject( const SdrPage& rPage
{ {
SdrObject* pRet = NULL; SdrObject* pRet = NULL;
sal_Bool bCreateObj = bForce; sal_Bool bCreateObj = bForce;
SfxItemSet* pSet = NULL; boost::scoped_ptr<SfxItemSet> pSet;
sal_uLong nFPosMerk = rStCtrl.Tell(); // remember FilePos for restoring it later sal_uLong nFPosMerk = rStCtrl.Tell(); // remember FilePos for restoring it later
DffRecordHeader aPageHd; DffRecordHeader aPageHd;
if ( SeekToAktPage( &aPageHd ) ) if ( SeekToAktPage( &aPageHd ) )
@@ -2956,7 +2952,7 @@ SdrObject* SdrPowerPointImport::ImportPageBackgroundObject( const SdrPage& rPage
ReadDffPropSet( rStCtrl, (DffPropertyReader&)*this ); ReadDffPropSet( rStCtrl, (DffPropertyReader&)*this );
mnFix16Angle = Fix16ToAngle( GetPropertyValue( DFF_Prop_Rotation, 0 ) ); mnFix16Angle = Fix16ToAngle( GetPropertyValue( DFF_Prop_Rotation, 0 ) );
sal_uInt32 nColor = GetPropertyValue( DFF_Prop_fillColor, 0xffffff ); sal_uInt32 nColor = GetPropertyValue( DFF_Prop_fillColor, 0xffffff );
pSet = new SfxItemSet( pSdrModel->GetItemPool() ); pSet.reset(new SfxItemSet( pSdrModel->GetItemPool() ));
DffObjData aObjData( aEscherObjectHd, Rectangle( 0, 0, 28000, 21000 ), 0 ); DffObjData aObjData( aEscherObjectHd, Rectangle( 0, 0, 28000, 21000 ), 0 );
ApplyAttributes( rStCtrl, *pSet, aObjData ); ApplyAttributes( rStCtrl, *pSet, aObjData );
Color aColor( MSO_CLR_ToColor( nColor ) ); Color aColor( MSO_CLR_ToColor( nColor ) );
@@ -2971,7 +2967,7 @@ SdrObject* SdrPowerPointImport::ImportPageBackgroundObject( const SdrPage& rPage
{ {
if ( !pSet ) if ( !pSet )
{ {
pSet = new SfxItemSet( pSdrModel->GetItemPool() ); pSet.reset(new SfxItemSet( pSdrModel->GetItemPool() ));
pSet->Put( XFillStyleItem( XFILL_NONE ) ); pSet->Put( XFillStyleItem( XFILL_NONE ) );
} }
pSet->Put( XLineStyleItem( XLINE_NONE ) ); pSet->Put( XLineStyleItem( XLINE_NONE ) );
@@ -2985,7 +2981,6 @@ SdrObject* SdrPowerPointImport::ImportPageBackgroundObject( const SdrPage& rPage
pRet->SetMoveProtect( true ); pRet->SetMoveProtect( true );
pRet->SetResizeProtect( true ); pRet->SetResizeProtect( true );
} }
delete pSet;
return pRet; return pRet;
} }

View File

@@ -13,6 +13,7 @@
#include <unotools/fontdefs.hxx> #include <unotools/fontdefs.hxx>
#include <vcl/svapp.hxx> #include <vcl/svapp.hxx>
#include <filter/msfilter/util.hxx> #include <filter/msfilter/util.hxx>
#include <boost/scoped_ptr.hpp>
#include <boost/unordered_map.hpp> #include <boost/unordered_map.hpp>
namespace msfilter { namespace msfilter {
@@ -83,9 +84,9 @@ DateTime DTTM2DateTime( long lDTTM )
sal_Unicode bestFitOpenSymbolToMSFont(sal_Unicode cChar, sal_Unicode bestFitOpenSymbolToMSFont(sal_Unicode cChar,
rtl_TextEncoding& rChrSet, OUString& rFontName, bool bDisableUnicodeSupport) rtl_TextEncoding& rChrSet, OUString& rFontName, bool bDisableUnicodeSupport)
{ {
StarSymbolToMSMultiFont *pConvert = CreateStarSymbolToMSMultiFont(); boost::scoped_ptr<StarSymbolToMSMultiFont> pConvert(CreateStarSymbolToMSMultiFont());
OUString sFont = pConvert->ConvertChar(cChar); OUString sFont = pConvert->ConvertChar(cChar);
delete pConvert; pConvert.reset();
if (!sFont.isEmpty()) if (!sFont.isEmpty())
{ {
cChar = static_cast< sal_Unicode >(cChar | 0xF000); cChar = static_cast< sal_Unicode >(cChar | 0xF000);

View File

@@ -74,6 +74,7 @@
#include "com/sun/star/lang/XServiceInfo.hpp" #include "com/sun/star/lang/XServiceInfo.hpp"
#include "com/sun/star/drawing/XShapes.hpp" #include "com/sun/star/drawing/XShapes.hpp"
#include "com/sun/star/graphic/XGraphicProvider.hpp" #include "com/sun/star/graphic/XGraphicProvider.hpp"
#include <boost/scoped_ptr.hpp>
using namespace ::rtl; using namespace ::rtl;
using namespace ::vcl; using namespace ::vcl;
@@ -789,9 +790,8 @@ sal_Bool PDFExport::Export( const OUString& rFile, const Sequence< PropertyValue
aContext.SignCertificate = maSignCertificate; aContext.SignCertificate = maSignCertificate;
// all context data set, time to create the printing device // all context data set, time to create the printing device
PDFWriter* pPDFWriter = new PDFWriter( aContext, xEnc ); boost::scoped_ptr<PDFWriter> pPDFWriter(new PDFWriter( aContext, xEnc ));
OutputDevice* pOut = pPDFWriter->GetReferenceDevice(); OutputDevice* pOut = pPDFWriter->GetReferenceDevice();
vcl::PDFExtOutDevData* pPDFExtOutDevData = NULL;
DBG_ASSERT( pOut, "PDFExport::Export: no reference device" ); DBG_ASSERT( pOut, "PDFExport::Export: no reference device" );
pXDevice->SetOutputDevice( pOut ); pXDevice->SetOutputDevice( pOut );
@@ -810,8 +810,8 @@ sal_Bool PDFExport::Export( const OUString& rFile, const Sequence< PropertyValue
if ( pOut ) if ( pOut )
{ {
DBG_ASSERT( pOut->GetExtOutDevData() == NULL, "PDFExport: ExtOutDevData already set!!!" ); DBG_ASSERT( pOut->GetExtOutDevData() == NULL, "PDFExport: ExtOutDevData already set!!!" );
pPDFExtOutDevData = new vcl::PDFExtOutDevData( *pOut ); boost::scoped_ptr<vcl::PDFExtOutDevData> pPDFExtOutDevData(new vcl::PDFExtOutDevData( *pOut ));
pOut->SetExtOutDevData( pPDFExtOutDevData ); pOut->SetExtOutDevData( pPDFExtOutDevData.get() );
pPDFExtOutDevData->SetIsExportNotes( mbExportNotes ); pPDFExtOutDevData->SetIsExportNotes( mbExportNotes );
pPDFExtOutDevData->SetIsExportTaggedPDF( mbUseTaggedPDF ); pPDFExtOutDevData->SetIsExportTaggedPDF( mbUseTaggedPDF );
pPDFExtOutDevData->SetIsExportTransitionEffects( mbUseTransitionEffects ); pPDFExtOutDevData->SetIsExportTransitionEffects( mbUseTransitionEffects );
@@ -884,14 +884,13 @@ sal_Bool PDFExport::Export( const OUString& rFile, const Sequence< PropertyValue
if ( mxStatusIndicator.is() ) if ( mxStatusIndicator.is() )
{ {
ResMgr* pResMgr = ResMgr::CreateResMgr( "pdffilter", Application::GetSettings().GetUILanguageTag() ); boost::scoped_ptr<ResMgr> pResMgr(ResMgr::CreateResMgr( "pdffilter", Application::GetSettings().GetUILanguageTag() ));
if ( pResMgr ) if ( pResMgr )
{ {
sal_Int32 nTotalPageCount = aRangeEnum.size(); sal_Int32 nTotalPageCount = aRangeEnum.size();
if ( bSecondPassForImpressNotes ) if ( bSecondPassForImpressNotes )
nTotalPageCount *= 2; nTotalPageCount *= 2;
mxStatusIndicator->start( OUString( ResId( PDF_PROGRESS_BAR, *pResMgr ) ), nTotalPageCount ); mxStatusIndicator->start( OUString( ResId( PDF_PROGRESS_BAR, *pResMgr ) ), nTotalPageCount );
delete pResMgr;
} }
} }
@@ -931,9 +930,6 @@ sal_Bool PDFExport::Export( const OUString& rFile, const Sequence< PropertyValue
} }
} }
} }
delete pPDFExtOutDevData;
delete pPDFWriter;
} }
} }

View File

@@ -24,6 +24,7 @@
#include <vcl/window.hxx> #include <vcl/window.hxx>
#include <svl/outstrm.hxx> #include <svl/outstrm.hxx>
#include <vcl/FilterConfigItem.hxx> #include <vcl/FilterConfigItem.hxx>
#include <boost/scoped_ptr.hpp>
// - PDFFilter - // - PDFFilter -
PDFFilter::PDFFilter( const Reference< XComponentContext > &rxContext ) : PDFFilter::PDFFilter( const Reference< XComponentContext > &rxContext ) :
@@ -112,7 +113,7 @@ sal_Bool PDFFilter::implExport( const Sequence< PropertyValue >& rDescriptor )
if( bRet ) if( bRet )
{ {
SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aTempFile.GetURL(), STREAM_READ ); boost::scoped_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream( aTempFile.GetURL(), STREAM_READ ));
if( pIStm ) if( pIStm )
{ {
@@ -120,8 +121,6 @@ sal_Bool PDFFilter::implExport( const Sequence< PropertyValue >& rDescriptor )
aOStm.WriteStream( *pIStm ); aOStm.WriteStream( *pIStm );
bRet = ( aOStm.Tell() && ( aOStm.GetError() == ERRCODE_NONE ) ); bRet = ( aOStm.Tell() && ( aOStm.GetError() == ERRCODE_NONE ) );
delete pIStm;
} }
} }
} }

View File

@@ -46,6 +46,7 @@
#include <xmloff/animationexport.hxx> #include <xmloff/animationexport.hxx>
#include <boost/preprocessor/repetition/repeat.hpp> #include <boost/preprocessor/repetition/repeat.hpp>
#include <boost/scoped_ptr.hpp>
using namespace ::com::sun::star::graphic; using namespace ::com::sun::star::graphic;
using namespace ::com::sun::star::geometry; using namespace ::com::sun::star::geometry;
@@ -543,7 +544,7 @@ sal_Bool SVGFilter::implExport( const Sequence< PropertyValue >& rDescriptor )
{ {
Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() ) ; Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() ) ;
Reference< XOutputStream > xOStm; Reference< XOutputStream > xOStm;
SvStream* pOStm = NULL; boost::scoped_ptr<SvStream> pOStm;
sal_Int32 nLength = rDescriptor.getLength(); sal_Int32 nLength = rDescriptor.getLength();
const PropertyValue* pValue = rDescriptor.getConstArray(); const PropertyValue* pValue = rDescriptor.getConstArray();
sal_Bool bRet = sal_False; sal_Bool bRet = sal_False;
@@ -559,7 +560,7 @@ sal_Bool SVGFilter::implExport( const Sequence< PropertyValue >& rDescriptor )
OUString aFileName; OUString aFileName;
pValue[ i ].Value >>= aFileName; pValue[ i ].Value >>= aFileName;
pOStm = ::utl::UcbStreamHelper::CreateStream( aFileName, STREAM_WRITE | STREAM_TRUNC ); pOStm.reset(::utl::UcbStreamHelper::CreateStream( aFileName, STREAM_WRITE | STREAM_TRUNC ));
if( pOStm ) if( pOStm )
xOStm = Reference< XOutputStream >( new ::utl::OOutputStreamWrapper ( *pOStm ) ); xOStm = Reference< XOutputStream >( new ::utl::OOutputStreamWrapper ( *pOStm ) );
@@ -642,8 +643,6 @@ sal_Bool SVGFilter::implExport( const Sequence< PropertyValue >& rDescriptor )
} }
} }
delete pOStm;
return bRet; return bRet;
} }

View File

@@ -3633,9 +3633,8 @@ void SAL_CALL SVGWriter::write( const Reference<XDocumentHandler>& rxDocHandler,
ReadGDIMetaFile( aMemStm, aMtf ); ReadGDIMetaFile( aMemStm, aMtf );
const Reference< XDocumentHandler > xDocumentHandler( rxDocHandler ); const Reference< XDocumentHandler > xDocumentHandler( rxDocHandler );
SVGExport* pWriter = new SVGExport( mxContext, xDocumentHandler, maFilterData ); boost::scoped_ptr<SVGExport> pWriter(new SVGExport( mxContext, xDocumentHandler, maFilterData ));
pWriter->writeMtf( aMtf ); pWriter->writeMtf( aMtf );
delete pWriter;
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */