[Libreoffice-commits] core.git: filter/source

Takeshi Abe tabe at fixedpoint.jp
Fri Apr 11 09:35:25 PDT 2014


 filter/source/msfilter/svdfppt.cxx |   21 ++++++++-------------
 filter/source/msfilter/util.cxx    |    5 +++--
 filter/source/pdf/pdfexport.cxx    |   14 +++++---------
 filter/source/pdf/pdffilter.cxx    |    5 ++---
 filter/source/svg/svgexport.cxx    |    7 +++----
 filter/source/svg/svgwriter.cxx    |    3 +--
 6 files changed, 22 insertions(+), 33 deletions(-)

New commits:
commit 4e939b959911b94cc3feea57fa6f3f4a63c8ddac
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date:   Sat Apr 12 01:28:10 2014 +0900

    Avoid possible memory leaks in case of exceptions
    
    Change-Id: I4f1e00dd275976cdba8490f35ccbb491914829b7

diff --git a/filter/source/msfilter/svdfppt.cxx b/filter/source/msfilter/svdfppt.cxx
index c176c6d..0a875ff 100644
--- a/filter/source/msfilter/svdfppt.cxx
+++ b/filter/source/msfilter/svdfppt.cxx
@@ -120,6 +120,7 @@
 #include <rtl/strbuf.hxx>
 #include <tools/time.hxx>
 #include <boost/scoped_array.hpp>
+#include <boost/scoped_ptr.hpp>
 
 // PPT ColorScheme Slots
 #define PPT_COLSCHEME                       (0x08000000)
@@ -1802,14 +1803,13 @@ SdrObject* SdrPowerPointImport::ImportOLE( long nOLEId,
 
             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 )
                     bSuccess = SdrPowerPointOLEDecompress( *pDest, rStCtrl, nLen );
-                delete pDest;
             }
             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;
                 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 );
         if ( pHd )
         {
-            DffRecordManager*   pExObjListManager = NULL;
             DffRecordHeader*    pExEmbed = NULL;
 
             pHd->SeekToBegOfRecord( rStCtrl );
-            pExObjListManager = new DffRecordManager( rStCtrl );
+            boost::scoped_ptr<DffRecordManager> pExObjListManager(new DffRecordManager( rStCtrl ));
             sal_uInt16 i, nRecType(PPT_PST_ExEmbed);
 
             for ( i = 0; i < 2; i++ )
@@ -2097,7 +2095,6 @@ void SdrPowerPointImport::SeekOle( SfxObjectShell* pShell, sal_uInt32 nFilterOpt
                     }
                 }
             }
-            delete pExObjListManager;
         }
         rStCtrl.Seek( nOldPos );
     }
@@ -2254,12 +2251,11 @@ SdrObject* SdrPowerPointImport::ApplyTextObj( PPTTextObj* pTextObj, SdrTextObj*
                 for ( pPortion = pPara->First(); pPortion; pPortion = pPara->Next() )
                 {
                     SfxItemSet aPortionAttribs( rOutliner.GetEmptyItemSet() );
-                    SvxFieldItem* pFieldItem = pPortion->GetTextField();
+                    boost::scoped_ptr<SvxFieldItem> pFieldItem(pPortion->GetTextField());
                     if ( pFieldItem )
                     {
                         rOutliner.QuickInsertField( *pFieldItem, ESelection( nParaIndex, aSelection.nEndPos, nParaIndex, aSelection.nEndPos + 1 ) );
                         aSelection.nEndPos++;
-                        delete pFieldItem;
                     }
                     else
                     {
@@ -2931,7 +2927,7 @@ SdrObject* SdrPowerPointImport::ImportPageBackgroundObject( const SdrPage& rPage
 {
     SdrObject* pRet = NULL;
     sal_Bool bCreateObj = bForce;
-    SfxItemSet* pSet = NULL;
+    boost::scoped_ptr<SfxItemSet> pSet;
     sal_uLong nFPosMerk = rStCtrl.Tell(); // remember FilePos for restoring it later
     DffRecordHeader aPageHd;
     if ( SeekToAktPage( &aPageHd ) )
@@ -2956,7 +2952,7 @@ SdrObject* SdrPowerPointImport::ImportPageBackgroundObject( const SdrPage& rPage
                         ReadDffPropSet( rStCtrl, (DffPropertyReader&)*this );
                         mnFix16Angle = Fix16ToAngle( GetPropertyValue( DFF_Prop_Rotation, 0 ) );
                         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 );
                         ApplyAttributes( rStCtrl, *pSet, aObjData );
                         Color aColor( MSO_CLR_ToColor( nColor ) );
@@ -2971,7 +2967,7 @@ SdrObject* SdrPowerPointImport::ImportPageBackgroundObject( const SdrPage& rPage
     {
         if ( !pSet )
         {
-            pSet = new SfxItemSet( pSdrModel->GetItemPool() );
+            pSet.reset(new SfxItemSet( pSdrModel->GetItemPool() ));
             pSet->Put( XFillStyleItem( XFILL_NONE ) );
         }
         pSet->Put( XLineStyleItem( XLINE_NONE ) );
@@ -2985,7 +2981,6 @@ SdrObject* SdrPowerPointImport::ImportPageBackgroundObject( const SdrPage& rPage
         pRet->SetMoveProtect( true );
         pRet->SetResizeProtect( true );
     }
-    delete pSet;
     return pRet;
 }
 
diff --git a/filter/source/msfilter/util.cxx b/filter/source/msfilter/util.cxx
index 36636ca..807061f 100644
--- a/filter/source/msfilter/util.cxx
+++ b/filter/source/msfilter/util.cxx
@@ -13,6 +13,7 @@
 #include <unotools/fontdefs.hxx>
 #include <vcl/svapp.hxx>
 #include <filter/msfilter/util.hxx>
+#include <boost/scoped_ptr.hpp>
 #include <boost/unordered_map.hpp>
 
 namespace msfilter {
@@ -83,9 +84,9 @@ DateTime DTTM2DateTime( long lDTTM )
 sal_Unicode bestFitOpenSymbolToMSFont(sal_Unicode cChar,
     rtl_TextEncoding& rChrSet, OUString& rFontName, bool bDisableUnicodeSupport)
 {
-    StarSymbolToMSMultiFont *pConvert = CreateStarSymbolToMSMultiFont();
+    boost::scoped_ptr<StarSymbolToMSMultiFont> pConvert(CreateStarSymbolToMSMultiFont());
     OUString sFont = pConvert->ConvertChar(cChar);
-    delete pConvert;
+    pConvert.reset();
     if (!sFont.isEmpty())
     {
         cChar = static_cast< sal_Unicode >(cChar | 0xF000);
diff --git a/filter/source/pdf/pdfexport.cxx b/filter/source/pdf/pdfexport.cxx
index 3c181e5..b4c415c 100644
--- a/filter/source/pdf/pdfexport.cxx
+++ b/filter/source/pdf/pdfexport.cxx
@@ -74,6 +74,7 @@
 #include "com/sun/star/lang/XServiceInfo.hpp"
 #include "com/sun/star/drawing/XShapes.hpp"
 #include "com/sun/star/graphic/XGraphicProvider.hpp"
+#include <boost/scoped_ptr.hpp>
 
 using namespace ::rtl;
 using namespace ::vcl;
@@ -789,9 +790,8 @@ sal_Bool PDFExport::Export( const OUString& rFile, const Sequence< PropertyValue
             aContext.SignCertificate = maSignCertificate;
 
 // 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();
-            vcl::PDFExtOutDevData* pPDFExtOutDevData = NULL;
 
             DBG_ASSERT( pOut, "PDFExport::Export: no reference device" );
             pXDevice->SetOutputDevice( pOut );
@@ -810,8 +810,8 @@ sal_Bool PDFExport::Export( const OUString& rFile, const Sequence< PropertyValue
             if ( pOut )
             {
                 DBG_ASSERT( pOut->GetExtOutDevData() == NULL, "PDFExport: ExtOutDevData already set!!!" );
-                pPDFExtOutDevData = new vcl::PDFExtOutDevData( *pOut );
-                pOut->SetExtOutDevData( pPDFExtOutDevData );
+                boost::scoped_ptr<vcl::PDFExtOutDevData> pPDFExtOutDevData(new vcl::PDFExtOutDevData( *pOut ));
+                pOut->SetExtOutDevData( pPDFExtOutDevData.get() );
                 pPDFExtOutDevData->SetIsExportNotes( mbExportNotes );
                 pPDFExtOutDevData->SetIsExportTaggedPDF( mbUseTaggedPDF );
                 pPDFExtOutDevData->SetIsExportTransitionEffects( mbUseTransitionEffects );
@@ -884,14 +884,13 @@ sal_Bool PDFExport::Export( const OUString& rFile, const Sequence< PropertyValue
 
                 if ( mxStatusIndicator.is() )
                 {
-                    ResMgr* pResMgr = ResMgr::CreateResMgr( "pdffilter", Application::GetSettings().GetUILanguageTag() );
+                    boost::scoped_ptr<ResMgr> pResMgr(ResMgr::CreateResMgr( "pdffilter", Application::GetSettings().GetUILanguageTag() ));
                     if ( pResMgr )
                     {
                         sal_Int32 nTotalPageCount = aRangeEnum.size();
                         if ( bSecondPassForImpressNotes )
                             nTotalPageCount *= 2;
                         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;
         }
     }
 
diff --git a/filter/source/pdf/pdffilter.cxx b/filter/source/pdf/pdffilter.cxx
index 8302a5e..fce746f 100644
--- a/filter/source/pdf/pdffilter.cxx
+++ b/filter/source/pdf/pdffilter.cxx
@@ -24,6 +24,7 @@
 #include <vcl/window.hxx>
 #include <svl/outstrm.hxx>
 #include <vcl/FilterConfigItem.hxx>
+#include <boost/scoped_ptr.hpp>
 
 // - PDFFilter -
 PDFFilter::PDFFilter( const Reference< XComponentContext > &rxContext ) :
@@ -112,7 +113,7 @@ sal_Bool PDFFilter::implExport( const Sequence< PropertyValue >& rDescriptor )
 
         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 )
             {
@@ -120,8 +121,6 @@ sal_Bool PDFFilter::implExport( const Sequence< PropertyValue >& rDescriptor )
 
                 aOStm.WriteStream( *pIStm );
                 bRet = ( aOStm.Tell() && ( aOStm.GetError() == ERRCODE_NONE ) );
-
-                delete pIStm;
             }
         }
     }
diff --git a/filter/source/svg/svgexport.cxx b/filter/source/svg/svgexport.cxx
index 0c1db7a..9b7e2c4 100644
--- a/filter/source/svg/svgexport.cxx
+++ b/filter/source/svg/svgexport.cxx
@@ -46,6 +46,7 @@
 #include <xmloff/animationexport.hxx>
 
 #include <boost/preprocessor/repetition/repeat.hpp>
+#include <boost/scoped_ptr.hpp>
 
 using namespace ::com::sun::star::graphic;
 using namespace ::com::sun::star::geometry;
@@ -543,7 +544,7 @@ sal_Bool SVGFilter::implExport( const Sequence< PropertyValue >& rDescriptor )
 {
     Reference< XComponentContext >      xContext( ::comphelper::getProcessComponentContext() ) ;
     Reference< XOutputStream >          xOStm;
-    SvStream*                           pOStm = NULL;
+    boost::scoped_ptr<SvStream>         pOStm;
     sal_Int32                            nLength = rDescriptor.getLength();
     const PropertyValue*                pValue = rDescriptor.getConstArray();
     sal_Bool                            bRet = sal_False;
@@ -559,7 +560,7 @@ sal_Bool SVGFilter::implExport( const Sequence< PropertyValue >& rDescriptor )
             OUString 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 )
                 xOStm = Reference< XOutputStream >( new ::utl::OOutputStreamWrapper ( *pOStm ) );
@@ -642,8 +643,6 @@ sal_Bool SVGFilter::implExport( const Sequence< PropertyValue >& rDescriptor )
         }
     }
 
-    delete pOStm;
-
     return bRet;
 }
 
diff --git a/filter/source/svg/svgwriter.cxx b/filter/source/svg/svgwriter.cxx
index c1430af..75ee522 100644
--- a/filter/source/svg/svgwriter.cxx
+++ b/filter/source/svg/svgwriter.cxx
@@ -3633,9 +3633,8 @@ void SAL_CALL SVGWriter::write( const Reference<XDocumentHandler>& rxDocHandler,
     ReadGDIMetaFile( aMemStm, aMtf );
 
     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 );
-    delete pWriter;
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list