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 /sfx2 | |
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 'sfx2')
-rw-r--r-- | sfx2/source/dialog/filedlghelper.cxx | 3 | ||||
-rw-r--r-- | sfx2/source/doc/docfile.cxx | 28 | ||||
-rw-r--r-- | sfx2/source/doc/graphhelp.cxx | 4 | ||||
-rw-r--r-- | sfx2/source/view/classificationhelper.cxx | 4 |
4 files changed, 18 insertions, 21 deletions
diff --git a/sfx2/source/dialog/filedlghelper.cxx b/sfx2/source/dialog/filedlghelper.cxx index 5d20a0f5b0c8..040dd203dbb8 100644 --- a/sfx2/source/dialog/filedlghelper.cxx +++ b/sfx2/source/dialog/filedlghelper.cxx @@ -765,13 +765,12 @@ ErrCode FileDialogHelper_Impl::getGraphic( const OUString& rURL, // non-local? if ( INetProtocol::File != aURLObj.GetProtocol() ) { - SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( rURL, StreamMode::READ ); + std::unique_ptr<SvStream> pStream = ::utl::UcbStreamHelper::CreateStream( rURL, StreamMode::READ ); if( pStream ) nRet = mpGraphicFilter->ImportGraphic( rGraphic, rURL, *pStream, nFilter, nullptr, nFilterImportFlags ); else nRet = mpGraphicFilter->ImportGraphic( rGraphic, aURLObj, nFilter, nullptr, nFilterImportFlags ); - delete pStream; } else { diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx index d6ea0e8f6c54..56a976572e25 100644 --- a/sfx2/source/doc/docfile.cxx +++ b/sfx2/source/doc/docfile.cxx @@ -260,8 +260,8 @@ public: std::shared_ptr<const SfxFilter> m_pFilter; std::shared_ptr<const SfxFilter> m_pCustomFilter; - SvStream* m_pInStream; - SvStream* m_pOutStream; + std::unique_ptr<SvStream> m_pInStream; + std::unique_ptr<SvStream> m_pOutStream; std::shared_ptr<const SfxFilter> pOrigFilter; OUString aOrigURL; @@ -536,11 +536,11 @@ bool SfxMedium::IsSkipImages() SvStream* SfxMedium::GetInStream() { if ( pImpl->m_pInStream ) - return pImpl->m_pInStream; + return pImpl->m_pInStream.get(); if ( pImpl->pTempFile ) { - pImpl->m_pInStream = new SvFileStream(pImpl->m_aName, pImpl->m_nStorOpenMode); + pImpl->m_pInStream.reset( new SvFileStream(pImpl->m_aName, pImpl->m_nStorOpenMode) ); pImpl->m_eError = pImpl->m_pInStream->GetError(); @@ -548,11 +548,10 @@ SvStream* SfxMedium::GetInStream() && ! pImpl->m_pInStream->IsWritable() ) { pImpl->m_eError = ERRCODE_IO_ACCESSDENIED; - delete pImpl->m_pInStream; - pImpl->m_pInStream = nullptr; + pImpl->m_pInStream.reset(); } else - return pImpl->m_pInStream; + return pImpl->m_pInStream.get(); } GetMedium_Impl(); @@ -560,7 +559,7 @@ SvStream* SfxMedium::GetInStream() if ( GetError() ) return nullptr; - return pImpl->m_pInStream; + return pImpl->m_pInStream.get(); } @@ -586,7 +585,7 @@ void SfxMedium::CloseInStream_Impl() return; } - DELETEZ( pImpl->m_pInStream ); + pImpl->m_pInStream.reset(); if ( pImpl->m_pSet ) pImpl->m_pSet->ClearItem( SID_INPUTSTREAM ); @@ -628,14 +627,14 @@ SvStream* SfxMedium::GetOutStream() { // On Unix don't try to re-use XOutStream from xStream if that exists; // it causes fdo#59022 (fails opening files via SMB on Linux) - pImpl->m_pOutStream = new SvFileStream( - pImpl->m_aName, StreamMode::STD_READWRITE); + pImpl->m_pOutStream.reset( new SvFileStream( + pImpl->m_aName, StreamMode::STD_READWRITE) ); } CloseStorage(); } } - return pImpl->m_pOutStream; + return pImpl->m_pOutStream.get(); } @@ -659,8 +658,7 @@ void SfxMedium::CloseOutStream_Impl() CloseStorage(); } - delete pImpl->m_pOutStream; - pImpl->m_pOutStream = nullptr; + pImpl->m_pOutStream.reset(); } if ( !pImpl->m_pInStream ) @@ -752,7 +750,7 @@ bool SfxMedium::IsStorage() } else if ( GetInStream() ) { - pImpl->bIsStorage = SotStorage::IsStorageFile( pImpl->m_pInStream ) && !SotStorage::IsOLEStorage( pImpl->m_pInStream ); + pImpl->bIsStorage = SotStorage::IsStorageFile( pImpl->m_pInStream.get() ) && !SotStorage::IsOLEStorage( pImpl->m_pInStream.get() ); if ( !pImpl->m_pInStream->GetError() && !pImpl->bIsStorage ) pImpl->m_bTriedStorage = true; } diff --git a/sfx2/source/doc/graphhelp.cxx b/sfx2/source/doc/graphhelp.cxx index f9c9feb256be..c2bd23e05a76 100644 --- a/sfx2/source/doc/graphhelp.cxx +++ b/sfx2/source/doc/graphhelp.cxx @@ -87,13 +87,13 @@ void* GraphicHelper::getEnhMetaFileFromGDI_Impl( const GDIMetaFile* pGDIMeta ) OUString aMetaFile = aTempFile.GetFileName(); OUString aMetaURL = aTempFile.GetURL(); - SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( aMetaURL, StreamMode::STD_READWRITE ); + std::unique_ptr<SvStream> pStream = ::utl::UcbStreamHelper::CreateStream( aMetaURL, StreamMode::STD_READWRITE ); if ( pStream ) { Graphic aGraph( *pGDIMeta ); ErrCode nFailed = GraphicConverter::Export( *pStream, aGraph, ConvertDataFormat::EMF ); pStream->Flush(); - delete pStream; + pStream.reset(); if ( !nFailed ) pResult = GetEnhMetaFileW( o3tl::toW(aMetaFile.getStr()) ); diff --git a/sfx2/source/view/classificationhelper.cxx b/sfx2/source/view/classificationhelper.cxx index a642d19b65e8..49020b28e086 100644 --- a/sfx2/source/view/classificationhelper.cxx +++ b/sfx2/source/view/classificationhelper.cxx @@ -390,8 +390,8 @@ void SfxClassificationHelper::Impl::parsePolicy() aPath = aLocalized; } - SvStream* pStream = utl::UcbStreamHelper::CreateStream(aPath, StreamMode::READ); - uno::Reference<io::XInputStream> xInputStream(new utl::OStreamWrapper(*pStream)); + std::unique_ptr<SvStream> pStream = utl::UcbStreamHelper::CreateStream(aPath, StreamMode::READ); + uno::Reference<io::XInputStream> xInputStream(new utl::OStreamWrapper(std::move(pStream))); xml::sax::InputSource aParserInput; aParserInput.aInputStream = xInputStream; |