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

Takeshi Abe tabe at fixedpoint.jp
Thu Jul 3 19:13:55 PDT 2014


 svtools/source/contnr/contentenumeration.cxx |    3 --
 svtools/source/contnr/imivctl1.cxx           |    4 +-
 svtools/source/control/calendar.cxx          |   39 +++++++++------------------
 svx/source/svdraw/svdouno.cxx                |    1 
 svx/source/unogallery/unogalitem.cxx         |    5 +--
 svx/source/xml/xmleohlp.cxx                  |    5 ++-
 svx/source/xml/xmlgrhlp.cxx                  |   11 +++----
 svx/source/xml/xmlxtexp.cxx                  |   16 +++++------
 8 files changed, 33 insertions(+), 51 deletions(-)

New commits:
commit f38bf4c6c29d685ec4f1015be09f64c7ae2eb172
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date:   Fri Jul 4 00:55:08 2014 +0900

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

diff --git a/svtools/source/contnr/imivctl1.cxx b/svtools/source/contnr/imivctl1.cxx
index 1335693..d7ccee1 100644
--- a/svtools/source/contnr/imivctl1.cxx
+++ b/svtools/source/contnr/imivctl1.cxx
@@ -690,7 +690,7 @@ void SvxIconChoiceCtrl_Impl::Paint( const Rectangle& rRect )
     }
 
     SvxIconChoiceCtrlEntryList_impl* pNewZOrderList = new SvxIconChoiceCtrlEntryList_impl();
-    SvxIconChoiceCtrlEntryList_impl* pPaintedEntries = new SvxIconChoiceCtrlEntryList_impl();
+    boost::scoped_ptr<SvxIconChoiceCtrlEntryList_impl> pPaintedEntries(new SvxIconChoiceCtrlEntryList_impl());
 
     size_t nPos = 0;
     while( nCount )
@@ -717,7 +717,7 @@ void SvxIconChoiceCtrl_Impl::Paint( const Rectangle& rRect )
         for( size_t nCur = 0; nCur < nCount; nCur++ )
             pZOrderList->push_back( (*pPaintedEntries)[ nCur ] );
     }
-    delete pPaintedEntries;
+    pPaintedEntries.reset();
 
     if( bResetClipRegion )
         pView->SetClipRegion();
diff --git a/svtools/source/control/calendar.cxx b/svtools/source/control/calendar.cxx
index 26427a4..b380baf8 100644
--- a/svtools/source/control/calendar.cxx
+++ b/svtools/source/control/calendar.cxx
@@ -37,7 +37,7 @@
 #include <svtools/svtools.hrc>
 #include <svtools/svtresid.hxx>
 #include <svtools/calendar.hxx>
-
+#include <boost/scoped_ptr.hpp>
 
 
 #define DAY_OFFX                        4
@@ -1084,7 +1084,7 @@ void Calendar::ImplUpdateSelection( IntDateSet* pOld )
 void Calendar::ImplMouseSelect( const Date& rDate, sal_uInt16 nHitTest,
                                 bool bMove, bool bExpand, bool bExtended )
 {
-    IntDateSet*  pOldSel = new IntDateSet( *mpSelectTable );
+    boost::scoped_ptr<IntDateSet> pOldSel(new IntDateSet( *mpSelectTable ));
     Date    aOldDate = maCurDate;
     Date    aTempDate = rDate;
 
@@ -1181,7 +1181,7 @@ void Calendar::ImplMouseSelect( const Date& rDate, sal_uInt16 nHitTest,
         }
         HideFocus();
         if ( bNewSel )
-            ImplUpdateSelection( pOldSel );
+            ImplUpdateSelection( pOldSel.get() );
         if ( !bNewSel || pOldSel->find( aOldDate.GetDate() ) == pOldSel->end() )
             ImplUpdateDate( aOldDate );
         // assure focus rectangle is displayed again
@@ -1189,7 +1189,6 @@ void Calendar::ImplMouseSelect( const Date& rDate, sal_uInt16 nHitTest,
              || mpSelectTable->find( maCurDate.GetDate() ) == mpSelectTable->end() )
             ImplUpdateDate( maCurDate );
     }
-    delete pOldSel;
 }
 
 
@@ -1355,18 +1354,17 @@ void Calendar::ImplEndTracking( bool bCancel )
 
         if ( !bSpinDown )
         {
-            IntDateSet* pOldSel = new IntDateSet( *mpSelectTable );
+            boost::scoped_ptr<IntDateSet> pOldSel(new IntDateSet( *mpSelectTable ));
             Date    aOldDate = maCurDate;
             maCurDate       = maOldCurDate;
             *mpSelectTable  = *mpOldSelectTable;
             HideFocus();
-            ImplUpdateSelection( pOldSel );
+            ImplUpdateSelection( pOldSel.get() );
             if ( pOldSel->find( aOldDate.GetDate() ) == pOldSel->end() )
                 ImplUpdateDate( aOldDate );
             //  assure focus rectangle is displayed again
             if ( HasFocus() || mpSelectTable->find( maCurDate.GetDate() ) == mpSelectTable->end() )
                 ImplUpdateDate( maCurDate );
-            delete pOldSel;
         }
     }
 
@@ -1585,7 +1583,7 @@ void Calendar::KeyInput( const KeyEvent& rKEvt )
     {
         if ( bMultiSel && bExpand )
         {
-            IntDateSet* pOldSel = new IntDateSet( *mpSelectTable );
+            boost::scoped_ptr<IntDateSet> pOldSel(new IntDateSet( *mpSelectTable ));
             Date aOldAnchorDate = maAnchorDate;
             mbSelLeft = aNewDate < maAnchorDate;
             if ( !bExtended )
@@ -1609,8 +1607,7 @@ void Calendar::KeyInput( const KeyEvent& rKEvt )
             mbInSelChange = true;
             SelectionChanging();
             mbInSelChange = false;
-            ImplUpdateSelection( pOldSel );
-            delete pOldSel;
+            ImplUpdateSelection( pOldSel.get() );
         }
         else
         {
@@ -1824,40 +1821,30 @@ void Calendar::SelectDate( const Date& rDate, bool bSelect )
     if ( !rDate.IsValidAndGregorian() )
         return;
 
-    IntDateSet* pOldSel;
+    boost::scoped_ptr<IntDateSet> pOldSel;
 
     if ( !mbInSelChange )
-        pOldSel = new IntDateSet( *mpSelectTable );
-    else
-        pOldSel = NULL;
+        pOldSel.reset(new IntDateSet( *mpSelectTable ));
 
     ImplCalendarSelectDate( mpSelectTable, rDate, bSelect );
 
     if ( pOldSel )
-    {
-        ImplUpdateSelection( pOldSel );
-        delete pOldSel;
-    }
+        ImplUpdateSelection( pOldSel.get() );
 }
 
 
 
 void Calendar::SetNoSelection()
 {
-    IntDateSet* pOldSel;
+    boost::scoped_ptr<IntDateSet> pOldSel;
 
     if ( !mbInSelChange )
-        pOldSel = new IntDateSet( *mpSelectTable );
-    else
-        pOldSel = NULL;
+        pOldSel.reset(new IntDateSet( *mpSelectTable ));
 
     ImplCalendarClearSelectDate( mpSelectTable );
 
     if ( pOldSel )
-    {
-        ImplUpdateSelection( pOldSel );
-        delete pOldSel;
-    }
+        ImplUpdateSelection( pOldSel.get() );
 }
 
 
diff --git a/svx/source/unogallery/unogalitem.cxx b/svx/source/unogallery/unogalitem.cxx
index f469953..adda224 100644
--- a/svx/source/unogallery/unogalitem.cxx
+++ b/svx/source/unogallery/unogalitem.cxx
@@ -35,6 +35,7 @@
 #include <com/sun/star/beans/PropertyState.hpp>
 #include <com/sun/star/beans/PropertyAttribute.hpp>
 #include <com/sun/star/gallery/GalleryItemType.hpp>
+#include <boost/scoped_ptr.hpp>
 
 #define UNOGALLERY_GALLERYITEMTYPE  1
 #define UNOGALLERY_URL              2
@@ -271,7 +272,7 @@ void GalleryItem::_setPropertyValues( const comphelper::PropertyMapEntry** ppEnt
 
                 if( pGalTheme )
                 {
-                    SgaObject* pObj = pGalTheme->ImplReadSgaObject( const_cast< GalleryObject* >( implGetObject() ) );
+                    boost::scoped_ptr<SgaObject> pObj(pGalTheme->ImplReadSgaObject( const_cast< GalleryObject* >( implGetObject() ) ));
 
                     if( pObj )
                     {
@@ -280,8 +281,6 @@ void GalleryItem::_setPropertyValues( const comphelper::PropertyMapEntry** ppEnt
                             pObj->SetTitle( aNewTitle );
                             pGalTheme->InsertObject( *pObj );
                         }
-
-                        delete pObj;
                     }
                 }
             }
diff --git a/svx/source/xml/xmleohlp.cxx b/svx/source/xml/xmleohlp.cxx
index a577779..ac2ab71 100644
--- a/svx/source/xml/xmleohlp.cxx
+++ b/svx/source/xml/xmleohlp.cxx
@@ -43,6 +43,7 @@
 #include <comphelper/classids.hxx>
 #include <map>
 #include "svx/xmleohlp.hxx"
+#include <boost/scoped_ptr.hpp>
 
 using namespace ::osl;
 using namespace ::cppu;
@@ -402,9 +403,9 @@ bool SvXMLEmbeddedObjectHelper::ImplReadObject(
                 pTemp->Seek( 0 );
                 uno::Reference < io::XStream > xStm = xDocStor->openStreamElement( rObjName,
                         embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE );
-                SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( xStm );
+                boost::scoped_ptr<SvStream> pStream(::utl::UcbStreamHelper::CreateStream( xStm ));
                 pTemp->ReadStream( *pStream );
-                delete pStream;
+                pStream.reset();
 
                 // TODO/LATER: what to do when other types of objects are based on substream persistence?
                 // This is an ole object
diff --git a/svx/source/xml/xmlgrhlp.cxx b/svx/source/xml/xmlgrhlp.cxx
index 27cc02f..7542637 100644
--- a/svx/source/xml/xmlgrhlp.cxx
+++ b/svx/source/xml/xmlgrhlp.cxx
@@ -47,6 +47,7 @@
 #include "svx/xmleohlp.hxx"
 
 #include <algorithm>
+#include <boost/scoped_ptr.hpp>
 
 using namespace com::sun::star;
 using namespace com::sun::star::uno;
@@ -312,7 +313,7 @@ const GraphicObject& SvXMLGraphicOutputStream::GetGraphicObject()
 
                 if( sFirstBytes[0] == 0x1f && sFirstBytes[1] == 0x8b )
                 {
-                    SvMemoryStream* pDest = new SvMemoryStream;
+                    boost::scoped_ptr<SvMemoryStream> pDest(new SvMemoryStream);
                     ZCodec aZCodec( 0x8000, 0x8000 );
                     aZCodec.BeginCompression(ZCODEC_DEFAULT_COMPRESSION, false, true);
                     mpOStm->Seek( 0 );
@@ -328,7 +329,6 @@ const GraphicObject& SvXMLGraphicOutputStream::GetGraphicObject()
                             GraphicFilter::GetGraphicFilter().ImportGraphic( aGraphic, "", *pDest ,nFormat,&pDeterminedFormat );
                         }
                     }
-                    delete pDest;
                 }
             }
         }
@@ -497,9 +497,8 @@ Graphic SvXMLGraphicHelper::ImplReadGraphic( const OUString& rPictureStorageName
     SvxGraphicHelperStream_Impl aStream( ImplGetGraphicStream( rPictureStorageName, rPictureStreamName, false ) );
     if( aStream.xStream.is() )
     {
-        SvStream* pStream = utl::UcbStreamHelper::CreateStream( aStream.xStream );
+        boost::scoped_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream( aStream.xStream ));
         GraphicFilter::GetGraphicFilter().ImportGraphic( aGraphic, "", *pStream );
-        delete pStream;
     }
 
     return aGraphic;
@@ -535,7 +534,7 @@ bool SvXMLGraphicHelper::ImplWriteGraphic( const OUString& rPictureStorageName,
             aAny <<= bCompressed;
             xProps->setPropertyValue( "Compressed", aAny );
 
-            SvStream* pStream = utl::UcbStreamHelper::CreateStream( aStream.xStream );
+            boost::scoped_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream( aStream.xStream ));
             if( bUseGfxLink && aGfxLink.GetDataSize() && aGfxLink.GetData() )
                 pStream->Write( aGfxLink.GetData(), aGfxLink.GetDataSize() );
             else
@@ -581,7 +580,7 @@ bool SvXMLGraphicHelper::ImplWriteGraphic( const OUString& rPictureStorageName,
             }
             uno::Reference < embed::XTransactedObject > xStorage(
                                     aStream.xStorage, uno::UNO_QUERY);
-            delete pStream;
+            pStream.reset();
             aStream.xStream->getOutputStream()->closeOutput();
             if( xStorage.is() )
                 xStorage->commit();
diff --git a/svx/source/xml/xmlxtexp.cxx b/svx/source/xml/xmlxtexp.cxx
index 85bf42a..511d8ec 100644
--- a/svx/source/xml/xmlxtexp.cxx
+++ b/svx/source/xml/xmlxtexp.cxx
@@ -49,6 +49,7 @@
 #include "xmlxtexp.hxx"
 
 #include <comphelper/storagehelper.hxx>
+#include <boost/scoped_ptr.hpp>
 
 using namespace com::sun::star;
 using namespace com::sun::star::container;
@@ -356,36 +357,36 @@ bool SvxXMLXTableExportComponent::exportTable() throw()
 
             char const* pEleName;
             Type aExportType = mxTable->getElementType();
-            SvxXMLTableEntryExporter* pExporter = NULL;
+            boost::scoped_ptr<SvxXMLTableEntryExporter> pExporter;
 
             if( aExportType == cppu::UnoType<sal_Int32>::get() )
             {
-                pExporter = new SvxXMLColorEntryExporter(*this);
+                pExporter.reset(new SvxXMLColorEntryExporter(*this));
                 pEleName = "color-table";
             }
             else if( aExportType == cppu::UnoType< drawing::PolyPolygonBezierCoords >::get() )
             {
-                pExporter = new SvxXMLLineEndEntryExporter(*this);
+                pExporter.reset(new SvxXMLLineEndEntryExporter(*this));
                 pEleName = "marker-table";
             }
             else if( aExportType == cppu::UnoType< drawing::LineDash >::get() )
             {
-                pExporter = new SvxXMLDashEntryExporter(*this);
+                pExporter.reset(new SvxXMLDashEntryExporter(*this));
                 pEleName = "dash-table";
             }
             else if( aExportType == cppu::UnoType< drawing::Hatch >::get() )
             {
-                pExporter = new SvxXMLHatchEntryExporter(*this);
+                pExporter.reset(new SvxXMLHatchEntryExporter(*this));
                 pEleName = "hatch-table";
             }
             else if( aExportType == cppu::UnoType< awt::Gradient >::get() )
             {
-                pExporter = new SvxXMLGradientEntryExporter(*this);
+                pExporter.reset(new SvxXMLGradientEntryExporter(*this));
                 pEleName = "gradient-table";
             }
             else if( aExportType == cppu::UnoType<OUString>::get())
             {
-                pExporter = new SvxXMLBitmapEntryExporter(*this);
+                pExporter.reset(new SvxXMLBitmapEntryExporter(*this));
                 pEleName = "bitmap-table";
             }
             else
@@ -407,7 +408,6 @@ bool SvxXMLXTableExportComponent::exportTable() throw()
                 aAny = mxTable->getByName( *pNames );
                 pExporter->exportEntry( *pNames, aAny );
             }
-            delete pExporter;
 
             bRet = true;
         }
commit c061cb94c07dff1d1eac126307e17295460b805b
Author: Takeshi Abe <tabe at fixedpoint.jp>
Date:   Fri Jul 4 00:50:34 2014 +0900

    Drop unused #includes
    
    Change-Id: Ief545db58a0dbb26ba293aa71debc816a8925b6c

diff --git a/svtools/source/contnr/contentenumeration.cxx b/svtools/source/contnr/contentenumeration.cxx
index ce17a5e..a78377e 100644
--- a/svtools/source/contnr/contentenumeration.cxx
+++ b/svtools/source/contnr/contentenumeration.cxx
@@ -34,9 +34,6 @@
 #include <vcl/svapp.hxx>
 #include <osl/mutex.hxx>
 
-#include <memory>
-
-
 namespace svt
 {
 
diff --git a/svx/source/svdraw/svdouno.cxx b/svx/source/svdraw/svdouno.cxx
index cb6e1ad..ed4ceda 100644
--- a/svx/source/svdraw/svdouno.cxx
+++ b/svx/source/svdraw/svdouno.cxx
@@ -45,7 +45,6 @@
 #include "svx/svdviter.hxx"
 #include <rtl/ref.hxx>
 #include <set>
-#include <memory>
 #include <svx/sdrpagewindow.hxx>
 #include <svx/sdrpaintwindow.hxx>
 #include <tools/diagnose_ex.h>


More information about the Libreoffice-commits mailing list