From 65e41592a650887c8d00586385119effa54de5fa Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Mon, 9 Jul 2018 17:10:49 +0200 Subject: pass SvStream around by std::unique_ptr and give utl::OStreamWrapper a new constructor so that it knows it is taking ownership of the SvStream, which appears to fix several leaks Change-Id: Idcbcca9b81a4f0345fd8b8c8a2f4e84213686a6b Reviewed-on: https://gerrit.libreoffice.org/57187 Tested-by: Jenkins Reviewed-by: Noel Grandin --- svtools/source/misc/embedhlp.cxx | 7 +++---- svtools/source/misc/embedtransfer.cxx | 2 +- svtools/source/misc/templatefoldercache.cxx | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) (limited to 'svtools') diff --git a/svtools/source/misc/embedhlp.cxx b/svtools/source/misc/embedhlp.cxx index 0d83432d15f9..b6ec9ae1576d 100644 --- a/svtools/source/misc/embedhlp.cxx +++ b/svtools/source/misc/embedhlp.cxx @@ -545,7 +545,7 @@ void EmbeddedObjectRef::SetGraphic( const Graphic& rGraphic, const OUString& rMe mpImpl->bNeedUpdate = false; } -SvStream* EmbeddedObjectRef::GetGraphicStream( bool bUpdate ) const +std::unique_ptr EmbeddedObjectRef::GetGraphicStream( bool bUpdate ) const { DBG_ASSERT( bUpdate || mpImpl->pContainer, "Can't retrieve current graphic!" ); uno::Reference < io::XInputStream > xStream; @@ -557,7 +557,7 @@ SvStream* EmbeddedObjectRef::GetGraphicStream( bool bUpdate ) const if ( xStream.is() ) { const sal_Int32 nConstBufferSize = 32000; - SvStream *pStream = new SvMemoryStream( 32000, 32000 ); + std::unique_ptr pStream(new SvMemoryStream( 32000, 32000 )); try { sal_Int32 nRead=0; @@ -574,7 +574,6 @@ SvStream* EmbeddedObjectRef::GetGraphicStream( bool bUpdate ) const catch (const uno::Exception&) { DBG_UNHANDLED_EXCEPTION("svtools.misc", "discarding broken embedded object preview"); - delete pStream; xStream.clear(); } } @@ -607,7 +606,7 @@ SvStream* EmbeddedObjectRef::GetGraphicStream( bool bUpdate ) const if (mpImpl->pContainer) mpImpl->pContainer->InsertGraphicStream(xStream,mpImpl->aPersistName,mpImpl->aMediaType); - SvStream* pResult = ::utl::UcbStreamHelper::CreateStream( xStream ); + std::unique_ptr pResult = ::utl::UcbStreamHelper::CreateStream( xStream ); if (pResult && bUpdate) mpImpl->bNeedUpdate = false; diff --git a/svtools/source/misc/embedtransfer.cxx b/svtools/source/misc/embedtransfer.cxx index 51c16627e338..29e894c56bd1 100644 --- a/svtools/source/misc/embedtransfer.cxx +++ b/svtools/source/misc/embedtransfer.cxx @@ -117,7 +117,7 @@ bool SvEmbedTransferHelper::GetData( const css::datatransfer::DataFlavor& rFlavo if ( xStg->isStreamElement( aName ) ) { uno::Reference < io::XStream > xStm = xStg->cloneStreamElement( aName ); - pStream = utl::UcbStreamHelper::CreateStream( xStm ); + pStream = utl::UcbStreamHelper::CreateStream( xStm ).release(); bDeleteStream = true; } else diff --git a/svtools/source/misc/templatefoldercache.cxx b/svtools/source/misc/templatefoldercache.cxx index 41141d1ba0c9..6fd4f6944ee7 100644 --- a/svtools/source/misc/templatefoldercache.cxx +++ b/svtools/source/misc/templatefoldercache.cxx @@ -702,8 +702,8 @@ namespace svt aStorageURL.Append( ".templdir.cache" ); // open the stream - m_pCacheStream.reset( UcbStreamHelper::CreateStream( aStorageURL.GetMainURL( INetURLObject::DecodeMechanism::ToIUri ), - _bForRead ? StreamMode::READ | StreamMode::NOCREATE : StreamMode::WRITE | StreamMode::TRUNC ) ); + m_pCacheStream = UcbStreamHelper::CreateStream( aStorageURL.GetMainURL( INetURLObject::DecodeMechanism::ToIUri ), + _bForRead ? StreamMode::READ | StreamMode::NOCREATE : StreamMode::WRITE | StreamMode::TRUNC ); DBG_ASSERT( m_pCacheStream, "TemplateFolderCacheImpl::openCacheStream: could not open/create the cache stream!" ); if ( m_pCacheStream && m_pCacheStream->GetErrorCode() ) { -- cgit v1.2.3