diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-07-09 17:10:49 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-07-10 08:30:21 +0200 |
commit | 65e41592a650887c8d00586385119effa54de5fa (patch) | |
tree | 4b0f6c7f52159d9cf70c561c815f623d3b57198d /sot | |
parent | acb7c06ab171d4201842d8183eefeeca2d28c3f5 (diff) |
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 <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sot')
-rw-r--r-- | sot/source/sdstor/storage.cxx | 8 | ||||
-rw-r--r-- | sot/source/sdstor/ucbstorage.cxx | 15 | ||||
-rw-r--r-- | sot/source/unoolestorage/xolesimplestorage.cxx | 6 | ||||
-rw-r--r-- | sot/source/unoolestorage/xolesimplestorage.hxx | 2 |
4 files changed, 15 insertions, 16 deletions
diff --git a/sot/source/sdstor/storage.cxx b/sot/source/sdstor/storage.cxx index 65f9d8a54416..3848fd941585 100644 --- a/sot/source/sdstor/storage.cxx +++ b/sot/source/sdstor/storage.cxx @@ -304,7 +304,7 @@ void SotStorage::CreateStorage( bool bForceUCBStorage, StreamMode nMode ) } // check the stream - m_pStorStm = ::utl::UcbStreamHelper::CreateStream( m_aName, nMode ); + m_pStorStm = ::utl::UcbStreamHelper::CreateStream( m_aName, nMode ).release(); if ( m_pStorStm && m_pStorStm->GetError() ) DELETEZ( m_pStorStm ); @@ -730,7 +730,7 @@ SotStorage* SotStorage::OpenOLEStorage( const css::uno::Reference < css::embed:: if ( nMode & StreamMode::NOCREATE ) nEleMode |= embed::ElementModes::NOCREATE; - SvStream* pStream = nullptr; + std::unique_ptr<SvStream> pStream; try { uno::Reference < io::XStream > xStream = xStorage->openStreamElement( rEleName, nEleMode ); @@ -748,11 +748,11 @@ SotStorage* SotStorage::OpenOLEStorage( const css::uno::Reference < css::embed:: catch ( uno::Exception& ) { //TODO/LATER: ErrorHandling - pStream = new SvMemoryStream; + pStream.reset( new SvMemoryStream ); pStream->SetError( ERRCODE_IO_GENERAL ); } - return new SotStorage( pStream, true ); + return new SotStorage( pStream.release(), true ); } SotClipboardFormatId SotStorage::GetFormatID( const css::uno::Reference < css::embed::XStorage >& xStorage ) diff --git a/sot/source/sdstor/ucbstorage.cxx b/sot/source/sdstor/ucbstorage.cxx index 148c23fefaa5..d7ffbbf7a756 100644 --- a/sot/source/sdstor/ucbstorage.cxx +++ b/sot/source/sdstor/ucbstorage.cxx @@ -86,7 +86,7 @@ class FileStreamWrapper_Impl : public FileInputStreamWrapper_Base protected: ::osl::Mutex m_aMutex; OUString m_aURL; - SvStream* m_pSvStream; + std::unique_ptr<SvStream> m_pSvStream; public: explicit FileStreamWrapper_Impl(const OUString& rName); @@ -119,7 +119,7 @@ FileStreamWrapper_Impl::~FileStreamWrapper_Impl() { if ( m_pSvStream ) { - delete m_pSvStream; + m_pSvStream.reset(); #if OSL_DEBUG_LEVEL > 0 --nOpenFiles; #endif @@ -224,7 +224,7 @@ void SAL_CALL FileStreamWrapper_Impl::closeInput() ::osl::MutexGuard aGuard( m_aMutex ); checkConnected(); - DELETEZ( m_pSvStream ); + m_pSvStream.reset(); #if OSL_DEBUG_LEVEL > 0 --nOpenFiles; #endif @@ -414,7 +414,7 @@ public: OString m_aKey; ::ucbhelper::Content* m_pContent; // the content that provides the data Reference<XInputStream> m_rSource; // the stream covering the original data of the content - SvStream* m_pStream; // the stream worked on; for readonly streams it is the original stream of the content + std::unique_ptr<SvStream> m_pStream; // the stream worked on; for readonly streams it is the original stream of the content // for read/write streams it's a copy into a temporary file OUString m_aTempURL; // URL of this temporary stream ErrCode m_nError; @@ -672,7 +672,7 @@ UCBStorageStream_Impl::~UCBStorageStream_Impl() if( m_rSource.is() ) m_rSource.clear(); - delete m_pStream; + m_pStream.reset(); if (!m_aTempURL.isEmpty()) osl::File::remove(m_aTempURL); @@ -1175,7 +1175,7 @@ void UCBStorageStream_Impl::Free() #endif m_rSource.clear(); - DELETEZ( m_pStream ); + m_pStream.reset(); } void UCBStorageStream_Impl::PrepareCachedForReopen( StreamMode nMode ) @@ -1520,8 +1520,7 @@ UCBStorage_Impl::UCBStorage_Impl( const OUString& rName, StreamMode nMode, UCBSt if ( m_nMode & StreamMode::WRITE ) { // the root storage opens the package, so make sure that there is any - SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( aName, StreamMode::STD_READWRITE, m_pTempFile != nullptr /* bFileExists */ ); - delete pStream; + ::utl::UcbStreamHelper::CreateStream( aName, StreamMode::STD_READWRITE, m_pTempFile != nullptr /* bFileExists */ ); } } else diff --git a/sot/source/unoolestorage/xolesimplestorage.cxx b/sot/source/unoolestorage/xolesimplestorage.cxx index f8b554cb04bb..a3c95d52334e 100644 --- a/sot/source/unoolestorage/xolesimplestorage.cxx +++ b/sot/source/unoolestorage/xolesimplestorage.cxx @@ -397,7 +397,7 @@ uno::Any SAL_CALL OLESimpleStorage::getByName( const OUString& aName ) if ( !pStrg ) throw lang::WrappedTargetException(); // io::IOException(); // TODO - SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( xTempFile, false ); // do not close the original stream + std::unique_ptr<SvStream> pStream = ::utl::UcbStreamHelper::CreateStream( xTempFile, false ); // do not close the original stream if ( !pStream ) throw uno::RuntimeException(); @@ -407,7 +407,7 @@ uno::Any SAL_CALL OLESimpleStorage::getByName( const OUString& aName ) DELETEZ( pNewStor ); DELETEZ( pStrg ); - DELETEZ( pStream ); + pStream.reset(); if ( !bSuccess ) throw uno::RuntimeException(); @@ -572,7 +572,7 @@ void SAL_CALL OLESimpleStorage::dispose() } DELETEZ( m_pStorage ); - DELETEZ( m_pStream ); + m_pStream.reset(); m_xStream.clear(); m_xTempStream.clear(); diff --git a/sot/source/unoolestorage/xolesimplestorage.hxx b/sot/source/unoolestorage/xolesimplestorage.hxx index 1b5216998d19..13ba9d01e5d8 100644 --- a/sot/source/unoolestorage/xolesimplestorage.hxx +++ b/sot/source/unoolestorage/xolesimplestorage.hxx @@ -44,7 +44,7 @@ class OLESimpleStorage : public cppu::WeakImplHelper<css::embed::XOLESimpleStora css::uno::Reference< css::io::XStream > m_xStream; css::uno::Reference< css::io::XStream > m_xTempStream; - SvStream* m_pStream; + std::unique_ptr<SvStream> m_pStream; BaseStorage* m_pStorage; ::comphelper::OInterfaceContainerHelper2* m_pListenersContainer; // list of listeners |