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

Takeshi Abe tabe at fixedpoint.jp
Sat Jul 5 04:20:31 PDT 2014


 svtools/source/filter/SvFilterOptionsDialog.cxx |    7 ++--
 svtools/source/graphic/descriptor.cxx           |   11 ++-----
 svtools/source/graphic/grfmgr.cxx               |    9 ++----
 svtools/source/graphic/grfmgr2.cxx              |   36 ++++++++----------------
 svtools/source/graphic/provider.cxx             |   20 +++++--------
 5 files changed, 31 insertions(+), 52 deletions(-)

New commits:
commit 1edd3679288c7582e85c5c033d6c7088651166a0
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date:   Fri Jul 4 23:05:30 2014 +0900

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

diff --git a/svtools/source/filter/SvFilterOptionsDialog.cxx b/svtools/source/filter/SvFilterOptionsDialog.cxx
index c8267cc..f3321aa 100644
--- a/svtools/source/filter/SvFilterOptionsDialog.cxx
+++ b/svtools/source/filter/SvFilterOptionsDialog.cxx
@@ -46,6 +46,7 @@
 #include <comphelper/processfactory.hxx>
 #include <cppuhelper/implbase5.hxx>
 #include <cppuhelper/supportsservice.hxx>
+#include <boost/scoped_ptr.hpp>
 
 using namespace ::com::sun::star;
 
@@ -249,15 +250,15 @@ sal_Int16 SvFilterOptionsDialog::execute()
             FltCallDialogParameter aFltCallDlgPara( Application::GetDefDialogParent(), NULL, meFieldUnit );
             aFltCallDlgPara.aFilterData = maFilterDataSequence;
 
-            ResMgr* pResMgr = ResMgr::CreateResMgr( "svt", Application::GetSettings().GetUILanguageTag() );
-            aFltCallDlgPara.pResMgr = pResMgr;
+            boost::scoped_ptr<ResMgr> pResMgr(ResMgr::CreateResMgr( "svt", Application::GetSettings().GetUILanguageTag() ));
+            aFltCallDlgPara.pResMgr = pResMgr.get();
 
             aFltCallDlgPara.aFilterExt = aGraphicFilter.GetExportFormatShortName( nFormat );
             bool bIsPixelFormat( aGraphicFilter.IsExportPixelFormat( nFormat ) );
             if ( ExportDialog( aFltCallDlgPara, mxContext, mxSourceDocument, mbExportSelection, bIsPixelFormat ).Execute() == RET_OK )
                 nRet = ui::dialogs::ExecutableDialogResults::OK;
 
-            delete pResMgr;
+            pResMgr.reset();
 
             // taking the out parameter from the dialog
             maFilterDataSequence = aFltCallDlgPara.aFilterData;
diff --git a/svtools/source/graphic/descriptor.cxx b/svtools/source/graphic/descriptor.cxx
index d24911d..1114923 100644
--- a/svtools/source/graphic/descriptor.cxx
+++ b/svtools/source/graphic/descriptor.cxx
@@ -33,6 +33,7 @@
 
 #include <vcl/graph.hxx>
 #include <vcl/svapp.hxx>
+#include <boost/scoped_ptr.hpp>
 
 #define UNOGRAPHIC_GRAPHICTYPE  1
 #define UNOGRAPHIC_MIMETYPE     2
@@ -82,13 +83,10 @@ void GraphicDescriptor::init( const ::Graphic& rGraphic )
 void GraphicDescriptor::init( const OUString& rURL )
     throw()
 {
-    SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( rURL, STREAM_READ );
+    boost::scoped_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream( rURL, STREAM_READ ));
 
     if( pIStm )
-    {
         implCreate( *pIStm, &rURL );
-        delete pIStm;
-    }
 }
 
 
@@ -96,13 +94,10 @@ void GraphicDescriptor::init( const OUString& rURL )
 void GraphicDescriptor::init( const uno::Reference< io::XInputStream >& rxIStm, const OUString& rURL )
     throw()
 {
-    SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( rxIStm );
+    boost::scoped_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream( rxIStm ));
 
     if( pIStm )
-    {
         implCreate( *pIStm, &rURL );
-        delete pIStm;
-    }
 }
 
 
diff --git a/svtools/source/graphic/grfmgr.cxx b/svtools/source/graphic/grfmgr.cxx
index 10130cd..408081e 100644
--- a/svtools/source/graphic/grfmgr.cxx
+++ b/svtools/source/graphic/grfmgr.cxx
@@ -37,6 +37,7 @@
 
 #include <com/sun/star/container/XNameContainer.hpp>
 #include <com/sun/star/beans/XPropertySet.hpp>
+#include <boost/scoped_ptr.hpp>
 
 using com::sun::star::uno::Reference;
 using com::sun::star::uno::XInterface;
@@ -210,13 +211,12 @@ void GraphicObject::ImplAutoSwapIn()
 
                             if( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( GetLink(), aURLStr ) )
                             {
-                                SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aURLStr, STREAM_READ );
+                                boost::scoped_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream( aURLStr, STREAM_READ ));
 
                                 if( pIStm )
                                 {
                                     ReadGraphic( *pIStm, maGraphic );
                                     mbAutoSwapped = ( maGraphic.GetType() != GRAPHIC_NONE );
-                                    delete pIStm;
                                 }
                             }
                         }
@@ -1218,12 +1218,9 @@ GraphicObject GraphicObject::CreateGraphicObjectFromURL( const OUString &rURL )
         Graphic     aGraphic;
         if ( !aURL.isEmpty() )
         {
-            SvStream*   pStream = utl::UcbStreamHelper::CreateStream( aURL, STREAM_READ );
+            boost::scoped_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream( aURL, STREAM_READ ));
             if( pStream )
-            {
                 GraphicConverter::Import( *pStream, aGraphic );
-                delete pStream;
-            }
         }
 
         return GraphicObject( aGraphic );
diff --git a/svtools/source/graphic/grfmgr2.cxx b/svtools/source/graphic/grfmgr2.cxx
index 295b4e0..117a4d0 100644
--- a/svtools/source/graphic/grfmgr2.cxx
+++ b/svtools/source/graphic/grfmgr2.cxx
@@ -33,7 +33,7 @@
 #include <vcl/virdev.hxx>
 #include "grfcache.hxx"
 #include <svtools/grfmgr.hxx>
-
+#include <boost/scoped_array.hpp>
 
 // - defines -
 
@@ -275,10 +275,10 @@ bool ImplCreateRotatedScaled( const BitmapEx& rBmpEx, const GraphicAttr& rAttrib
     bool    bHMirr = ( rAttributes.GetMirrorFlags() & BMP_MIRROR_HORZ ) != 0;
     bool    bVMirr = ( rAttributes.GetMirrorFlags() & BMP_MIRROR_VERT ) != 0;
 
-    long*   pMapIX = new long[ aUnrotatedWidth ];
-    long*   pMapFX = new long[ aUnrotatedWidth ];
-    long*   pMapIY = new long[ aUnrotatedHeight ];
-    long*   pMapFY = new long[ aUnrotatedHeight ];
+    boost::scoped_array<long> pMapIX(new long[ aUnrotatedWidth ]);
+    boost::scoped_array<long> pMapFX(new long[ aUnrotatedWidth ]);
+    boost::scoped_array<long> pMapIY(new long[ aUnrotatedHeight ]);
+    boost::scoped_array<long> pMapFY(new long[ aUnrotatedHeight ]);
 
     double fRevScaleX;
     double fRevScaleY;
@@ -372,10 +372,10 @@ bool ImplCreateRotatedScaled( const BitmapEx& rBmpEx, const GraphicAttr& rAttrib
     const double        fSinAngle = sin( nRot10 * F_PI1800 );
     const long          aTargetWidth  = nEndX - nStartX + 1L;
     const long          aTargetHeight = nEndY - nStartY + 1L;
-    long*               pCosX = new long[ aTargetWidth ];
-    long*               pSinX = new long[ aTargetWidth ];
-    long*               pCosY = new long[ aTargetHeight ];
-    long*               pSinY = new long[ aTargetHeight ];
+    boost::scoped_array<long> pCosX(new long[ aTargetWidth ]);
+    boost::scoped_array<long> pSinX(new long[ aTargetWidth ]);
+    boost::scoped_array<long> pCosY(new long[ aTargetHeight ]);
+    boost::scoped_array<long> pSinY(new long[ aTargetHeight ]);
     long                nUnRotX, nUnRotY, nSinY, nCosY;
     sal_uInt8           cR0, cG0, cB0, cR1, cG1, cB1;
     bool                bRet = false;
@@ -739,8 +739,8 @@ bool ImplCreateRotatedScaled( const BitmapEx& rBmpEx, const GraphicAttr& rAttrib
 
                 if( !aMsk || ( ( pMAcc = aMsk.AcquireReadAccess() ) != NULL ) )
                 {
-                    long*       pMapLX = new long[ aUnrotatedWidth ];
-                    long*       pMapLY = new long[ aUnrotatedHeight ];
+                    boost::scoped_array<long> pMapLX(new long[ aUnrotatedWidth ]);
+                    boost::scoped_array<long> pMapLY(new long[ aUnrotatedHeight ]);
                     BitmapColor aTestB;
 
                     if( pMAcc )
@@ -783,8 +783,8 @@ bool ImplCreateRotatedScaled( const BitmapEx& rBmpEx, const GraphicAttr& rAttrib
                         }
                     }
 
-                    delete[] pMapLX;
-                    delete[] pMapLY;
+                    pMapLX.reset();
+                    pMapLY.reset();
 
                     if( pMAcc )
                         aMsk.ReleaseAccess( pMAcc );
@@ -805,16 +805,6 @@ bool ImplCreateRotatedScaled( const BitmapEx& rBmpEx, const GraphicAttr& rAttrib
     else
         rOutBmpEx = aOutBmp;
 
-    delete[] pSinX;
-    delete[] pCosX;
-    delete[] pSinY;
-    delete[] pCosY;
-
-    delete[] pMapIX;
-    delete[] pMapFX;
-    delete[] pMapIY;
-    delete[] pMapFY;
-
     return bRet;
 }
 
diff --git a/svtools/source/graphic/provider.cxx b/svtools/source/graphic/provider.cxx
index 8a1295b..1cf6620 100644
--- a/svtools/source/graphic/provider.cxx
+++ b/svtools/source/graphic/provider.cxx
@@ -43,6 +43,7 @@
 #include <svtools/grfmgr.hxx>
 #include "provider.hxx"
 #include <vcl/dibtools.hxx>
+#include <boost/scoped_ptr.hpp>
 
 using namespace com::sun::star;
 
@@ -236,7 +237,7 @@ uno::Reference< ::graphic::XGraphic > GraphicProvider::implLoadResource( const O
         OString aResMgrName(OUStringToOString(
             rResourceURL.getToken(0, '/', nIndex), RTL_TEXTENCODING_ASCII_US));
 
-        ResMgr* pResMgr = ResMgr::CreateResMgr( aResMgrName.getStr(), Application::GetSettings().GetUILanguageTag() );
+        boost::scoped_ptr<ResMgr> pResMgr(ResMgr::CreateResMgr( aResMgrName.getStr(), Application::GetSettings().GetUILanguageTag() ));
 
         if( pResMgr )
         {
@@ -296,8 +297,6 @@ uno::Reference< ::graphic::XGraphic > GraphicProvider::implLoadResource( const O
                     xRet = pUnoGraphic;
                 }
             }
-
-            delete pResMgr;
         }
     }
 
@@ -384,7 +383,7 @@ uno::Reference< ::graphic::XGraphic > SAL_CALL GraphicProvider::queryGraphic( co
 {
     uno::Reference< ::graphic::XGraphic >   xRet;
     OUString                                aPath;
-    SvStream*                               pIStm = NULL;
+    boost::scoped_ptr<SvStream>             pIStm;
 
     uno::Reference< io::XInputStream > xIStm;
     uno::Reference< awt::XBitmap >xBtm;
@@ -443,7 +442,7 @@ uno::Reference< ::graphic::XGraphic > SAL_CALL GraphicProvider::queryGraphic( co
 
     if( xIStm.is() )
     {
-        pIStm = ::utl::UcbStreamHelper::CreateStream( xIStm );
+        pIStm.reset(::utl::UcbStreamHelper::CreateStream( xIStm ));
     }
     else if( !aPath.isEmpty() )
     {
@@ -462,7 +461,7 @@ uno::Reference< ::graphic::XGraphic > SAL_CALL GraphicProvider::queryGraphic( co
             xRet = implLoadStandardImage( aPath );
 
         if( !xRet.is() )
-            pIStm = ::utl::UcbStreamHelper::CreateStream( aPath, STREAM_READ );
+            pIStm.reset(::utl::UcbStreamHelper::CreateStream( aPath, STREAM_READ ));
     }
     else if( xBtm.is() )
     {
@@ -495,8 +494,6 @@ uno::Reference< ::graphic::XGraphic > SAL_CALL GraphicProvider::queryGraphic( co
                 xRet = pUnoGraphic;
             }
         }
-
-        delete pIStm;
     }
 
     return xRet;
@@ -729,7 +726,7 @@ void SAL_CALL GraphicProvider::storeGraphic( const uno::Reference< ::graphic::XG
 {
     SolarMutexGuard g;
 
-    SvStream*   pOStm = NULL;
+    boost::scoped_ptr<SvStream> pOStm;
     OUString    aPath;
     sal_Int32   i;
 
@@ -743,7 +740,7 @@ void SAL_CALL GraphicProvider::storeGraphic( const uno::Reference< ::graphic::XG
             OUString aURL;
 
             aValue >>= aURL;
-            pOStm = ::utl::UcbStreamHelper::CreateStream( aURL, STREAM_WRITE | STREAM_TRUNC );
+            pOStm.reset(::utl::UcbStreamHelper::CreateStream( aURL, STREAM_WRITE | STREAM_TRUNC ));
             aPath = aURL;
         }
         else if (aName == "OutputStream")
@@ -753,7 +750,7 @@ void SAL_CALL GraphicProvider::storeGraphic( const uno::Reference< ::graphic::XG
             aValue >>= xOStm;
 
             if( xOStm.is() )
-                pOStm = ::utl::UcbStreamHelper::CreateStream( xOStm );
+                pOStm.reset(::utl::UcbStreamHelper::CreateStream( xOStm ));
         }
     }
 
@@ -846,7 +843,6 @@ void SAL_CALL GraphicProvider::storeGraphic( const uno::Reference< ::graphic::XG
                 }
             }
         }
-        delete pOStm;
     }
 }
 


More information about the Libreoffice-commits mailing list