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 /svx | |
parent | c061cb94c07dff1d1eac126307e17295460b805b (diff) |
Avoid possible memory leaks in case of exceptions
Change-Id: I04a0a2c296206f155ee4916b15b853a7f10c2c2a
Diffstat (limited to 'svx')
-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 |
4 files changed, 18 insertions, 19 deletions
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; } |