[Libreoffice-commits] core.git: formula/source framework/source

Takeshi Abe tabe at fixedpoint.jp
Tue Apr 15 00:13:09 PDT 2014


 formula/source/core/api/token.cxx                     |    5 ++---
 framework/source/uiconfiguration/imagemanagerimpl.cxx |    8 +++-----
 framework/source/uielement/controlmenucontroller.cxx  |    9 +++------
 framework/source/uielement/fontsizemenucontroller.cxx |   16 +++++++---------
 framework/source/uielement/newmenucontroller.cxx      |    9 ++++-----
 5 files changed, 19 insertions(+), 28 deletions(-)

New commits:
commit eb4c43aa61c08f88acfe5dd1499de0f8dbda4b8b
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date:   Tue Apr 15 15:08:24 2014 +0900

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

diff --git a/formula/source/core/api/token.cxx b/formula/source/core/api/token.cxx
index 197d62f..c5d7da7 100644
--- a/formula/source/core/api/token.cxx
+++ b/formula/source/core/api/token.cxx
@@ -30,6 +30,7 @@
 #include "formula/FormulaCompiler.hxx"
 #include <formula/compiler.hrc>
 #include <svl/sharedstringpool.hxx>
+#include <boost/scoped_array.hpp>
 
 namespace formula
 {
@@ -861,7 +862,7 @@ bool FormulaTokenArray::HasMatrixDoubleRefOps()
     {
         // RPN-Interpreter Simulation
         // als Ergebnis jeder Funktion wird einfach ein Double angenommen
-        FormulaToken** pStack = new FormulaToken* [nRPN];
+        boost::scoped_array<FormulaToken*> pStack(new FormulaToken* [nRPN]);
         FormulaToken* pResult = new FormulaDoubleToken( 0.0 );
         short sp = 0;
         for ( sal_uInt16 j = 0; j < nRPN; j++ )
@@ -890,7 +891,6 @@ bool FormulaTokenArray::HasMatrixDoubleRefOps()
                         if ( sp >= k && pStack[sp-k]->GetType() == svDoubleRef )
                         {
                             pResult->Delete();
-                            delete [] pStack;
                             return true;
                         }
                     }
@@ -920,7 +920,6 @@ bool FormulaTokenArray::HasMatrixDoubleRefOps()
             }
         }
         pResult->Delete();
-        delete [] pStack;
     }
 
     return false;
diff --git a/framework/source/uiconfiguration/imagemanagerimpl.cxx b/framework/source/uiconfiguration/imagemanagerimpl.cxx
index 495da8d..9fe506b 100644
--- a/framework/source/uiconfiguration/imagemanagerimpl.cxx
+++ b/framework/source/uiconfiguration/imagemanagerimpl.cxx
@@ -44,6 +44,7 @@
 #include <vcl/pngwrite.hxx>
 #include <rtl/instance.hxx>
 #include <svtools/miscopt.hxx>
+#include <boost/scoped_ptr.hpp>
 
 using ::com::sun::star::uno::Sequence;
 using ::com::sun::star::uno::XInterface;
@@ -495,14 +496,12 @@ bool ImageManagerImpl::implts_loadUserImages(
 
                 if ( xBitmapStream.is() )
                 {
-                    SvStream* pSvStream( 0 );
                     BitmapEx aUserBitmap;
                     {
-                        pSvStream = utl::UcbStreamHelper::CreateStream( xBitmapStream );
+                        boost::scoped_ptr<SvStream> pSvStream(utl::UcbStreamHelper::CreateStream( xBitmapStream ));
                         vcl::PNGReader aPngReader( *pSvStream );
                         aUserBitmap = aPngReader.Read();
                     }
-                    delete pSvStream;
 
                     // Delete old image list and create a new one from the read bitmap
                     delete m_pUserImageList[nImageType];
@@ -578,12 +577,11 @@ bool ImageManagerImpl::implts_storeUserImages(
                                                             ElementModes::WRITE|ElementModes::TRUNCATE );
                 if ( xBitmapStream.is() )
                 {
-                    SvStream* pSvStream = utl::UcbStreamHelper::CreateStream( xBitmapStream );
                     {
+                        boost::scoped_ptr<SvStream> pSvStream(utl::UcbStreamHelper::CreateStream( xBitmapStream ));
                         vcl::PNGWriter aPngWriter( pImageList->GetAsHorizontalStrip() );
                         aPngWriter.Write( *pSvStream );
                     }
-                    delete pSvStream;
 
                     // Commit user bitmaps storage
                     xTransaction = uno::Reference< XTransactedObject >( xUserBitmapsStorage, UNO_QUERY );
diff --git a/framework/source/uielement/controlmenucontroller.cxx b/framework/source/uielement/controlmenucontroller.cxx
index 1c1840b..d7446a1 100644
--- a/framework/source/uielement/controlmenucontroller.cxx
+++ b/framework/source/uielement/controlmenucontroller.cxx
@@ -42,6 +42,7 @@
 #include <svtools/menuoptions.hxx>
 #include <svtools/popupmenucontrollerbase.hxx>
 #include <osl/mutex.hxx>
+#include <boost/scoped_ptr.hpp>
 
 // Copied from svx
 // Function-Id's
@@ -256,7 +257,7 @@ ControlMenuController::~ControlMenuController()
 // private function
 void ControlMenuController::updateImagesPopupMenu( PopupMenu* pPopupMenu )
 {
-    ResMgr* pResMgr = ResMgr::CreateResMgr("svx", Application::GetSettings().GetUILanguageTag());
+    boost::scoped_ptr<ResMgr> pResMgr(ResMgr::CreateResMgr("svx", Application::GetSettings().GetUILanguageTag()));
     ResId aResId( RID_SVXIMGLIST_FMEXPL, *pResMgr );
     aResId.SetRT( RSC_IMAGELIST );
 
@@ -272,8 +273,6 @@ void ControlMenuController::updateImagesPopupMenu( PopupMenu* pPopupMenu )
                 pPopupMenu->SetItemImage( nConvertSlots[i], Image() );
         }
     }
-
-    delete pResMgr;
 }
 
 // private function
@@ -404,7 +403,7 @@ void ControlMenuController::impl_setPopupMenu()
 {
     if ( m_pResPopupMenu == 0 )
     {
-        ResMgr* pResMgr = ResMgr::CreateResMgr("svx", Application::GetSettings().GetUILanguageTag());
+        boost::scoped_ptr<ResMgr> pResMgr(ResMgr::CreateResMgr("svx", Application::GetSettings().GetUILanguageTag()));
         if ( pResMgr )
         {
             ResId aResId( RID_FMSHELL_CONVERSIONMENU, *pResMgr );
@@ -414,8 +413,6 @@ void ControlMenuController::impl_setPopupMenu()
                 m_pResPopupMenu = new PopupMenu( aResId );
                 updateImagesPopupMenu( m_pResPopupMenu );
             }
-
-            delete pResMgr;
         }
     } // if ( m_pResPopupMenu == 0 )
 }
diff --git a/framework/source/uielement/fontsizemenucontroller.cxx b/framework/source/uielement/fontsizemenucontroller.cxx
index 674c47e..d530931 100644
--- a/framework/source/uielement/fontsizemenucontroller.cxx
+++ b/framework/source/uielement/fontsizemenucontroller.cxx
@@ -36,6 +36,7 @@
 #include <vcl/settings.hxx>
 #include <svtools/ctrltool.hxx>
 #include <osl/mutex.hxx>
+#include <boost/scoped_ptr.hpp>
 
 //  Defines
 
@@ -133,8 +134,8 @@ void FontSizeMenuController::fillPopupMenu( Reference< css::awt::XPopupMenu >& r
 
     if ( pVCLPopupMenu )
     {
-        FontList*       pFontList = 0;
-        Printer*        pInfoPrinter = 0;
+        boost::scoped_ptr<FontList> pFontList;
+        boost::scoped_ptr<Printer>  pInfoPrinter;
         OUString   aPrinterName;
 
         SolarMutexGuard aSolarMutexGuard;
@@ -143,13 +144,13 @@ void FontSizeMenuController::fillPopupMenu( Reference< css::awt::XPopupMenu >& r
         aPrinterName = retrievePrinterName( m_xFrame );
         if ( !aPrinterName.isEmpty() )
         {
-            pInfoPrinter = new Printer( aPrinterName );
+            pInfoPrinter.reset(new Printer( aPrinterName ));
             if ( pInfoPrinter && pInfoPrinter->GetDevFontCount() > 0 )
-                pFontList = new FontList( pInfoPrinter );
+                pFontList.reset(new FontList( pInfoPrinter.get() ));
         }
 
-        if ( pFontList == 0 )
-            pFontList   = new FontList( Application::GetDefaultDevice() );
+        if ( !pFontList )
+            pFontList.reset(new FontList( Application::GetDefaultDevice() ));
 
         FontInfo aFntInfo = pFontList->Get( m_aFontDescriptor.Name, m_aFontDescriptor.StyleName );
 
@@ -233,9 +234,6 @@ void FontSizeMenuController::fillPopupMenu( Reference< css::awt::XPopupMenu >& r
         }
 
         setCurHeight( long( m_aFontHeight.Height * 10), rPopupMenu );
-
-        delete pFontList;
-        delete pInfoPrinter;
     }
 }
 
diff --git a/framework/source/uielement/newmenucontroller.cxx b/framework/source/uielement/newmenucontroller.cxx
index d02ee31..cbe0873 100644
--- a/framework/source/uielement/newmenucontroller.cxx
+++ b/framework/source/uielement/newmenucontroller.cxx
@@ -44,6 +44,7 @@
 #include <svtools/acceleratorexecute.hxx>
 #include <unotools/moduleoptions.hxx>
 #include <osl/mutex.hxx>
+#include <boost/scoped_ptr.hpp>
 
 //  Defines
 
@@ -324,12 +325,12 @@ void NewMenuController::fillPopupMenu( Reference< css::awt::XPopupMenu >& rPopup
     if ( pVCLPopupMenu )
     {
         MenuConfiguration aMenuCfg( m_xContext );
-        BmkMenu* pSubMenu( 0 );
+        boost::scoped_ptr<BmkMenu> pSubMenu;
 
         if ( m_bNewMenu )
-            pSubMenu = (BmkMenu*)aMenuCfg.CreateBookmarkMenu( m_xFrame, BOOKMARK_NEWMENU );
+            pSubMenu.reset((BmkMenu*)aMenuCfg.CreateBookmarkMenu( m_xFrame, BOOKMARK_NEWMENU ));
         else
-            pSubMenu = (BmkMenu*)aMenuCfg.CreateBookmarkMenu( m_xFrame, BOOKMARK_WIZARDMENU );
+            pSubMenu.reset((BmkMenu*)aMenuCfg.CreateBookmarkMenu( m_xFrame, BOOKMARK_WIZARDMENU ));
 
         // copy entries as we have to use the provided popup menu
         *pVCLPopupMenu = *pSubMenu;
@@ -358,8 +359,6 @@ void NewMenuController::fillPopupMenu( Reference< css::awt::XPopupMenu >& rPopup
 
         if ( m_bShowImages )
             setMenuImages( pVCLPopupMenu, m_bShowImages );
-
-        delete pSubMenu;
     }
 }
 


More information about the Libreoffice-commits mailing list