diff options
author | Takeshi Abe <tabe@fixedpoint.jp> | 2014-07-04 00:55:08 +0900 |
---|---|---|
committer | Takeshi Abe <tabe@fixedpoint.jp> | 2014-07-04 10:49:10 +0900 |
commit | f38bf4c6c29d685ec4f1015be09f64c7ae2eb172 (patch) | |
tree | 84894e4957abbda40a4fa2cc20b200aff3502200 | |
parent | c061cb94c07dff1d1eac126307e17295460b805b (diff) |
Avoid possible memory leaks in case of exceptions
Change-Id: I04a0a2c296206f155ee4916b15b853a7f10c2c2a
-rw-r--r-- | svtools/source/contnr/imivctl1.cxx | 4 | ||||
-rw-r--r-- | svtools/source/control/calendar.cxx | 39 | ||||
-rw-r--r-- | svx/source/unogallery/unogalitem.cxx | 5 | ||||
-rw-r--r-- | svx/source/xml/xmleohlp.cxx | 5 | ||||
-rw-r--r-- | svx/source/xml/xmlgrhlp.cxx | 11 | ||||
-rw-r--r-- | svx/source/xml/xmlxtexp.cxx | 16 |
6 files changed, 33 insertions, 47 deletions
diff --git a/svtools/source/contnr/imivctl1.cxx b/svtools/source/contnr/imivctl1.cxx index 13356932a709..d7ccee171e51 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 26427a42793f..b380baf87e48 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 f469953d5a32..adda2244cf57 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 a5777797e73f..ac2ab7139fa4 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 27cc02faa33b..7542637880ff 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 85bf42aea284..511d8ec79fd9 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; } |