Kaydet (Commit) 65e41592 authored tarafından Noel Grandin's avatar Noel Grandin

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: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst acb7c06a
......@@ -390,11 +390,11 @@ void SvxHyperlinkNewDocTp::DoApply ()
try
{
// check if file exists, warn before we overwrite it
SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::READ );
std::unique_ptr<SvStream> pIStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::READ );
bool bOk = pIStm && ( pIStm->GetError() == ERRCODE_NONE);
delete pIStm;
pIStm.reset();
if( bOk )
{
......
......@@ -140,7 +140,7 @@ HsqlRowInputStream::HsqlRowInputStream() {}
void HsqlRowInputStream::setInputStream(Reference<XInputStream> const& rStream)
{
m_pStream.reset(utl::UcbStreamHelper::CreateStream(rStream, true));
m_pStream = utl::UcbStreamHelper::CreateStream(rStream, true);
m_pStream->SetEndian(SvStreamEndian::BIG);
}
......
......@@ -107,7 +107,7 @@ namespace migration
bool IsUserWordbook( const OUString& rFile )
{
bool bRet = false;
SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( rFile, StreamMode::STD_READ );
std::unique_ptr<SvStream> pStream = ::utl::UcbStreamHelper::CreateStream( rFile, StreamMode::STD_READ );
if ( pStream && !pStream->GetError() )
{
static const sal_Char* const pVerOOo7 = "OOoUserDict1";
......@@ -137,7 +137,6 @@ bool IsUserWordbook( const OUString& rFile )
}
}
delete pStream;
return bRet;
}
......
......@@ -517,7 +517,7 @@ bool SVGFilter::implExport( const Sequence< PropertyValue >& rDescriptor )
OUString aFileName;
pValue[ i ].Value >>= aFileName;
pOStm.reset(::utl::UcbStreamHelper::CreateStream( aFileName, StreamMode::WRITE | StreamMode::TRUNC ));
pOStm = ::utl::UcbStreamHelper::CreateStream( aFileName, StreamMode::WRITE | StreamMode::TRUNC );
if( pOStm )
xOStm.set( new ::utl::OOutputStreamWrapper ( *pOStm ) );
......
......@@ -165,9 +165,9 @@ OUString SAL_CALL PlainTextFilterDetect::detect(uno::Sequence<beans::PropertyVal
ZCodec aCodecGZ;
std::unique_ptr<SvStream> pInStream;
if (xStream.is())
pInStream.reset(utl::UcbStreamHelper::CreateStream(xStream));
pInStream = utl::UcbStreamHelper::CreateStream(xStream);
else
pInStream.reset(utl::UcbStreamHelper::CreateStream(xInStream));
pInStream = utl::UcbStreamHelper::CreateStream(xInStream);
std::unique_ptr<SvMemoryStream> pDecompressedStream(new SvMemoryStream());
if (aCodecGZ.AttemptDecompression(*pInStream, *pDecompressedStream))
{
......
......@@ -963,7 +963,7 @@ bool ODatabaseForm::InsertFilePart( INetMIMEMessage& rParent, const OUString& rN
{
OUString aFileName(rFileName);
OUString aContentType(CONTENT_TYPE_STR_TEXT_PLAIN);
SvStream *pStream = nullptr;
std::unique_ptr<SvStream> pStream;
if (!aFileName.isEmpty())
{
......@@ -977,8 +977,7 @@ bool ODatabaseForm::InsertFilePart( INetMIMEMessage& rParent, const OUString& rN
pStream = ::utl::UcbStreamHelper::CreateStream(aFileName, StreamMode::READ);
if (!pStream || (pStream->GetError() != ERRCODE_NONE))
{
delete pStream;
pStream = nullptr;
pStream.reset();
}
sal_Int32 nSepInd = aFileName.lastIndexOf('.');
OUString aExtension = aFileName.copy( nSepInd + 1 );
......@@ -990,7 +989,7 @@ bool ODatabaseForm::InsertFilePart( INetMIMEMessage& rParent, const OUString& rN
// If something didn't work, we create an empty MemoryStream
if( !pStream )
pStream = new SvMemoryStream;
pStream.reset( new SvMemoryStream );
// Create part as MessageChild
......@@ -1013,7 +1012,7 @@ bool ODatabaseForm::InsertFilePart( INetMIMEMessage& rParent, const OUString& rN
// Body
pChild->SetDocumentLB( new SvLockBytes(pStream, true) );
pChild->SetDocumentLB( new SvLockBytes(pStream.release(), true) );
rParent.AttachChild( std::move(pChild) );
return true;
......
......@@ -400,7 +400,7 @@ bool OImageControlModel::impl_updateStreamForURL_lck( const OUString& _rURL, Val
}
else
{
pImageStream.reset( ::utl::UcbStreamHelper::CreateStream( _rURL, StreamMode::READ ) );
pImageStream = ::utl::UcbStreamHelper::CreateStream( _rURL, StreamMode::READ );
bool bSetNull = ( pImageStream.get() == nullptr ) || ( ERRCODE_NONE != pImageStream->GetErrorCode() );
if ( !bSetNull )
......
......@@ -209,9 +209,9 @@ void ImageProducer::SetImage( const OUString& rPath )
}
else if( !maURL.isEmpty() )
{
SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( maURL, StreamMode::STD_READ );
std::unique_ptr<SvStream> pIStm = ::utl::UcbStreamHelper::CreateStream( maURL, StreamMode::STD_READ );
if (pIStm)
mpStm.reset( new SvStream( new ImgProdLockBytes( pIStm, true ) ) );
mpStm.reset( new SvStream( new ImgProdLockBytes( pIStm.release(), true ) ) );
}
}
......
......@@ -246,7 +246,7 @@ namespace frm
if ( nResult == ERRCODE_NONE )
{
OUString sFileName = aFP.GetPath();
SvStream* pStream = ::utl::UcbStreamHelper::CreateStream(
std::unique_ptr<SvStream> pStream = ::utl::UcbStreamHelper::CreateStream(
sFileName, ( bLoad ? StreamMode::READ : StreamMode::WRITE | StreamMode::TRUNC ) | StreamMode::SHARE_DENYALL
);
if ( pStream )
......@@ -272,7 +272,6 @@ namespace frm
getEngine().Write( *pStream, eFormat );
}
}
DELETEZ( pStream );
}
return true; // handled
}
......
......@@ -1277,7 +1277,7 @@ Image AddonsOptions_Impl::ReadImageFromURL(const OUString& aImageURL)
{
Image aImage;
SvStream* pStream = UcbStreamHelper::CreateStream( aImageURL, StreamMode::STD_READ );
std::unique_ptr<SvStream> pStream = UcbStreamHelper::CreateStream( aImageURL, StreamMode::STD_READ );
if ( pStream && ( pStream->GetErrorCode() == ERRCODE_NONE ))
{
// Use graphic class to also support more graphic formats (bmp,png,...)
......@@ -1299,8 +1299,6 @@ Image AddonsOptions_Impl::ReadImageFromURL(const OUString& aImageURL)
}
}
delete pStream;
return aImage;
}
......
......@@ -48,7 +48,7 @@ class SVT_DLLPUBLIC EmbeddedObjectRef
{
std::unique_ptr<EmbeddedObjectRef_Impl> mpImpl;
SVT_DLLPRIVATE SvStream* GetGraphicStream( bool bUpdate ) const;
SVT_DLLPRIVATE std::unique_ptr<SvStream> GetGraphicStream( bool bUpdate ) const;
SVT_DLLPRIVATE void GetReplacement( bool bUpdate );
EmbeddedObjectRef& operator = ( const EmbeddedObjectRef& ) = delete;
......
......@@ -29,6 +29,7 @@
#include <com/sun/star/io/XStream.hpp>
#include <cppuhelper/implbase.hxx>
#include <cppuhelper/implbase1.hxx>
#include <memory>
class SvStream;
......@@ -53,6 +54,7 @@ protected:
public:
OInputStreamWrapper(SvStream& _rStream);
OInputStreamWrapper(SvStream* pStream, bool bOwner=false);
OInputStreamWrapper(std::unique_ptr<SvStream> pStream);
virtual ~OInputStreamWrapper() override;
// css::io::XInputStream
......@@ -152,6 +154,7 @@ protected:
public:
OStreamWrapper(SvStream& _rStream);
OStreamWrapper(std::unique_ptr<SvStream> _rStream);
// css::io::XStream
virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getInputStream( ) override;
......
......@@ -25,6 +25,7 @@
#include <unotools/unotoolsdllapi.h>
#include <tools/stream.hxx>
#include <memory>
namespace com
{
......@@ -52,13 +53,13 @@ namespace utl
class UNOTOOLS_DLLPUBLIC UcbStreamHelper
{
public:
static SvStream* CreateStream( const OUString& rFileName, StreamMode eOpenMode );
static SvStream* CreateStream( const OUString& rFileName, StreamMode eOpenMode,
bool bFileExists );
static SvStream* CreateStream( const css::uno::Reference < css::io::XInputStream >& xStream );
static SvStream* CreateStream( const css::uno::Reference < css::io::XStream >& xStream );
static SvStream* CreateStream( const css::uno::Reference < css::io::XInputStream >& xStream, bool bCloseStream );
static SvStream* CreateStream( const css::uno::Reference < css::io::XStream >& xStream, bool bCloseStream );
static std::unique_ptr<SvStream> CreateStream( const OUString& rFileName, StreamMode eOpenMode );
static std::unique_ptr<SvStream> CreateStream( const OUString& rFileName, StreamMode eOpenMode,
bool bFileExists );
static std::unique_ptr<SvStream> CreateStream( const css::uno::Reference < css::io::XInputStream >& xStream );
static std::unique_ptr<SvStream> CreateStream( const css::uno::Reference < css::io::XStream >& xStream );
static std::unique_ptr<SvStream> CreateStream( const css::uno::Reference < css::io::XInputStream >& xStream, bool bCloseStream );
static std::unique_ptr<SvStream> CreateStream( const css::uno::Reference < css::io::XStream >& xStream, bool bCloseStream );
};
}
......
......@@ -285,7 +285,7 @@ public:
/// Imports multiple graphics.
///
/// The resulting graphic is added to rGraphics on success, nullptr is added on failure.
void ImportGraphics(std::vector< std::shared_ptr<Graphic> >& rGraphics, const std::vector< std::shared_ptr<SvStream> >& rStreams);
void ImportGraphics(std::vector< std::shared_ptr<Graphic> >& rGraphics, std::vector< std::unique_ptr<SvStream> > vStreams);
ErrCode ImportGraphic( Graphic& rGraphic, const OUString& rPath,
SvStream& rStream,
......
......@@ -65,10 +65,10 @@ Reference< XInputStream > createStreamFromFile (
Reference< XInputStream > xInputStream;
OUString aInStr;
FileBase::getFileURLFromSystemPath(filePath, aInStr);
SvStream* pStream = utl::UcbStreamHelper::CreateStream(aInStr, StreamMode::READ);
std::unique_ptr<SvStream> pStream = utl::UcbStreamHelper::CreateStream(aInStr, StreamMode::READ);
if(pStream == nullptr)
CPPUNIT_ASSERT(false);
Reference< XStream > xStream(new utl::OStreamWrapper(*pStream));
Reference< XStream > xStream(new utl::OStreamWrapper(std::move(pStream)));
xInputStream.set(xStream, UNO_QUERY);
return xInputStream;
}
......
......@@ -1575,7 +1575,7 @@ void XclExpObjectManager::InitStream( bool bTempFile )
if( mxTempFile->IsValid() )
{
mxTempFile->EnableKillingFile();
mxDffStrm.reset( ::utl::UcbStreamHelper::CreateStream( mxTempFile->GetURL(), StreamMode::STD_READWRITE ) );
mxDffStrm = ::utl::UcbStreamHelper::CreateStream( mxTempFile->GetURL(), StreamMode::STD_READWRITE );
}
}
......
......@@ -85,7 +85,7 @@ SvStream* XclEscherExGlobal::ImplQueryPictureStream()
if( mxPicTempFile->IsValid() )
{
mxPicTempFile->EnableKillingFile();
mxPicStrm.reset( ::utl::UcbStreamHelper::CreateStream( mxPicTempFile->GetURL(), StreamMode::STD_READWRITE ) );
mxPicStrm = ::utl::UcbStreamHelper::CreateStream( mxPicTempFile->GetURL(), StreamMode::STD_READWRITE );
mxPicStrm->SetEndian( SvStreamEndian::LITTLE );
}
return mxPicStrm.get();
......
......@@ -565,12 +565,12 @@ bool ScDrawTransferObj::WriteObject( tools::SvRef<SotStorageStream>& rxOStm, voi
if ( xTransact.is() )
xTransact->commit();
SvStream* pSrcStm = ::utl::UcbStreamHelper::CreateStream( aTempFile.GetURL(), StreamMode::READ );
std::unique_ptr<SvStream> pSrcStm = ::utl::UcbStreamHelper::CreateStream( aTempFile.GetURL(), StreamMode::READ );
if( pSrcStm )
{
rxOStm->SetBufferSize( 0xff00 );
rxOStm->WriteStream( *pSrcStm );
delete pSrcStm;
pSrcStm.reset();
}
xWorkStore->dispose();
......
......@@ -496,12 +496,12 @@ bool ScTransferObj::WriteObject( tools::SvRef<SotStorageStream>& rxOStm, void* p
if ( xTransact.is() )
xTransact->commit();
SvStream* pSrcStm = ::utl::UcbStreamHelper::CreateStream( aTempFile.GetURL(), StreamMode::READ );
std::unique_ptr<SvStream> pSrcStm = ::utl::UcbStreamHelper::CreateStream( aTempFile.GetURL(), StreamMode::READ );
if( pSrcStm )
{
rxOStm->SetBufferSize( 0xff00 );
rxOStm->WriteStream( *pSrcStm );
delete pSrcStm;
pSrcStm.reset();
}
bRet = true;
......
......@@ -188,7 +188,7 @@ sal_Int16 SAL_CALL ScFilterOptionsObj::execute()
OUString aPrivDatName(aURL.getName());
std::unique_ptr<SvStream> pInStream;
if ( xInputStream.is() )
pInStream.reset(utl::UcbStreamHelper::CreateStream( xInputStream ));
pInStream = utl::UcbStreamHelper::CreateStream( xInputStream );
ScopedVclPtr<AbstractScImportAsciiDlg> pDlg(pFact->CreateScImportAsciiDlg(nullptr, aPrivDatName, pInStream.get(), SC_IMPORTFILE));
if ( pDlg->Execute() == RET_OK )
......@@ -272,7 +272,7 @@ sal_Int16 SAL_CALL ScFilterOptionsObj::execute()
std::unique_ptr<SvStream> pInStream;
if ( xInputStream.is() )
pInStream.reset(utl::UcbStreamHelper::CreateStream( xInputStream ));
pInStream = utl::UcbStreamHelper::CreateStream( xInputStream );
switch(load_CharSet( eEncoding, bExport, pInStream.get()))
{
case charsetSource::charset_from_file:
......
......@@ -244,8 +244,8 @@ Reference< XAnimationNode > implImportEffects( const Reference< XMultiServiceFac
try
{
// create stream
SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( rPath, StreamMode::READ );
Reference<XInputStream> xInputStream( new utl::OInputStreamWrapper( pIStm, true ) );
std::unique_ptr<SvStream> pIStm = ::utl::UcbStreamHelper::CreateStream( rPath, StreamMode::READ );
Reference<XInputStream> xInputStream( new utl::OInputStreamWrapper( std::move(pIStm) ) );
// prepare ParserInputSrouce
xml::sax::InputSource aParserInput;
......
......@@ -127,7 +127,7 @@ void ExSoundEntry::Write( SvStream& rSt, sal_uInt32 nId ) const
rSt.WriteUInt32( EPP_SoundData << 16 ).WriteUInt32( nFileSize );
sal_uInt32 nBytesLeft = nFileSize;
SvStream* pSourceFile = ::utl::UcbStreamHelper::CreateStream( aSoundURL, StreamMode::READ );
std::unique_ptr<SvStream> pSourceFile = ::utl::UcbStreamHelper::CreateStream( aSoundURL, StreamMode::READ );
if ( pSourceFile )
{
std::unique_ptr<sal_uInt8[]> pBuf( new sal_uInt8[ 0x10000 ] ); // 64 kB Buffer
......@@ -138,7 +138,6 @@ void ExSoundEntry::Write( SvStream& rSt, sal_uInt32 nId ) const
rSt.WriteBytes(pBuf.get(), nToDo);
nBytesLeft -= nToDo;
}
delete pSourceFile;
}
}
catch( css::uno::Exception& )
......
......@@ -2866,7 +2866,7 @@ bool HtmlExport::CopyScript( const OUString& rPath, const OUString& rSource, con
meEC.SetContext( STR_HTMLEXP_ERROR_OPEN_FILE, rSource );
ErrCode nErr = ERRCODE_NONE;
SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::READ );
std::unique_ptr<SvStream> pIStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::READ );
if( pIStm )
{
......@@ -2886,7 +2886,7 @@ bool HtmlExport::CopyScript( const OUString& rPath, const OUString& rSource, con
}
nErr = pIStm->GetError();
delete pIStm;
pIStm.reset();
}
if( nErr != ERRCODE_NONE )
......@@ -3141,7 +3141,7 @@ ErrCode EasyFile::createStream( const OUString& rUrl, SvStream* &rpStr )
createFileName( rUrl, aFileName );
ErrCode nErr = ERRCODE_NONE;
pOStm.reset( ::utl::UcbStreamHelper::CreateStream( aFileName, StreamMode::WRITE | StreamMode::TRUNC ) );
pOStm = ::utl::UcbStreamHelper::CreateStream( aFileName, StreamMode::WRITE | StreamMode::TRUNC );
if( pOStm )
{
bOpen = true;
......
......@@ -1514,12 +1514,10 @@ void SdPublishingDlg::Load()
// check if file exists, SfxMedium shows an errorbox else
{
SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::READ );
std::unique_ptr<SvStream> pIStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::READ );
bool bOk = pIStm && ( pIStm->GetError() == ERRCODE_NONE);
delete pIStm;
if( !bOk )
return;
}
......
......@@ -1961,7 +1961,7 @@ OUString ImplSdPPTImport::ReadSound(sal_uInt32 nSoundRef) const
std::vector<sal_uInt8> aBuf(nSoundDataLen);
rStCtrl.ReadBytes(aBuf.data(), nSoundDataLen);
SvStream* pOStm = ::utl::UcbStreamHelper::CreateStream( aGalleryUserSound.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::WRITE | StreamMode::TRUNC );
std::unique_ptr<SvStream> pOStm = ::utl::UcbStreamHelper::CreateStream( aGalleryUserSound.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::WRITE | StreamMode::TRUNC );
if( pOStm )
{
......@@ -1972,8 +1972,6 @@ OUString ImplSdPPTImport::ReadSound(sal_uInt32 nSoundRef) const
GalleryExplorer::InsertURL( GALLERY_THEME_USERSOUNDS, aGalleryUserSound.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
aRetval = aGalleryUserSound.GetMainURL( INetURLObject::DecodeMechanism::NONE );
}
delete pOStm;
}
}
}
......
......@@ -183,10 +183,10 @@ tools::SvRef<SotStorageStream> SdModule::GetOptionStream( const OUString& rOptio
aURL.Append( "drawing.cfg" );
SvStream* pStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::READWRITE );
std::unique_ptr<SvStream> pStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::READWRITE );
if( pStm )
xOptionStorage = new SotStorage( pStm, true );
xOptionStorage = new SotStorage( pStm.release(), true );
}
OUString aStmName;
......
......@@ -640,12 +640,12 @@ bool SdTransferable::WriteObject( tools::SvRef<SotStorageStream>& rxOStm, void*
if ( xTransact.is() )
xTransact->commit();
SvStream* pSrcStm = ::utl::UcbStreamHelper::CreateStream( aTempFile.GetURL(), StreamMode::READ );
std::unique_ptr<SvStream> pSrcStm = ::utl::UcbStreamHelper::CreateStream( aTempFile.GetURL(), StreamMode::READ );
if( pSrcStm )
{
rxOStm->SetBufferSize( 0xff00 );
rxOStm->WriteStream( *pSrcStm );
delete pSrcStm;
pSrcStm.reset();
}
bRet = true;
......
......@@ -610,13 +610,12 @@ IMPL_LINK_NOARG(SdPhotoAlbumDialog, SelectHdl, weld::TreeView&, void)
// remote?
if ( INetProtocol::File != aURLObj.GetProtocol() )
{
SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( sImgUrl, StreamMode::READ );
std::unique_ptr<SvStream> pStream = ::utl::UcbStreamHelper::CreateStream( sImgUrl, StreamMode::READ );
if( pStream )
m_pGraphicFilter->ImportGraphic( aGraphic, sImgUrl, *pStream, nFilter, nullptr, nFilterImportFlags );
else
m_pGraphicFilter->ImportGraphic( aGraphic, aURLObj, nFilter, nullptr, nFilterImportFlags );
delete pStream;
}
else
{
......
......@@ -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
{
......
......@@ -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;
}
......
......@@ -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()) );
......
......@@ -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;
......
......@@ -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 )
......
......@@ -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();