summaryrefslogtreecommitdiff
path: root/unotools
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-07-09 17:10:49 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-07-10 08:30:21 +0200
commit65e41592a650887c8d00586385119effa54de5fa (patch)
tree4b0f6c7f52159d9cf70c561c815f623d3b57198d /unotools
parentacb7c06ab171d4201842d8183eefeeca2d28c3f5 (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 'unotools')
-rw-r--r--unotools/source/streaming/streamwrap.cxx11
-rw-r--r--unotools/source/ucbhelper/ucbstreamhelper.cxx34
2 files changed, 28 insertions, 17 deletions
diff --git a/unotools/source/streaming/streamwrap.cxx b/unotools/source/streaming/streamwrap.cxx
index dec5f38f8bc4..fc68b8df300d 100644
--- a/unotools/source/streaming/streamwrap.cxx
+++ b/unotools/source/streaming/streamwrap.cxx
@@ -43,6 +43,12 @@ OInputStreamWrapper::OInputStreamWrapper( SvStream* pStream, bool bOwner )
{
}
+OInputStreamWrapper::OInputStreamWrapper( std::unique_ptr<SvStream> pStream )
+ :m_pSvStream( pStream.release() )
+ ,m_bSvStreamOwner( true )
+{
+}
+
OInputStreamWrapper::~OInputStreamWrapper()
{
if( m_bSvStreamOwner )
@@ -288,6 +294,11 @@ OStreamWrapper::OStreamWrapper(SvStream& _rStream)
SetStream( &_rStream, false );
}
+OStreamWrapper::OStreamWrapper(std::unique_ptr<SvStream> pStream)
+{
+ SetStream( pStream.release(), true );
+}
+
css::uno::Reference< css::io::XInputStream > SAL_CALL OStreamWrapper::getInputStream( )
{
return this;
diff --git a/unotools/source/ucbhelper/ucbstreamhelper.cxx b/unotools/source/ucbhelper/ucbstreamhelper.cxx
index 63260f632b91..7ded3ca9ad47 100644
--- a/unotools/source/ucbhelper/ucbstreamhelper.cxx
+++ b/unotools/source/ucbhelper/ucbstreamhelper.cxx
@@ -42,11 +42,11 @@ using namespace ::com::sun::star::beans;
namespace utl
{
-static SvStream* lcl_CreateStream( const OUString& rFileName, StreamMode eOpenMode,
+static std::unique_ptr<SvStream> lcl_CreateStream( const OUString& rFileName, StreamMode eOpenMode,
const Reference < XInteractionHandler >& xInteractionHandler,
bool bEnsureFileExists )
{
- SvStream* pStream = nullptr;
+ std::unique_ptr<SvStream> pStream;
UcbLockBytesRef xLockBytes;
if ( eOpenMode & StreamMode::WRITE )
{
@@ -119,7 +119,7 @@ static SvStream* lcl_CreateStream( const OUString& rFileName, StreamMode eOpenMo
eOpenMode, xInteractionHandler );
if ( xLockBytes.is() )
{
- pStream = new SvStream( xLockBytes.get() );
+ pStream.reset( new SvStream( xLockBytes.get() ) );
pStream->SetBufferSize( 4096 );
pStream->SetError( xLockBytes->GetError() );
}
@@ -137,7 +137,7 @@ static SvStream* lcl_CreateStream( const OUString& rFileName, StreamMode eOpenMo
return pStream;
}
-SvStream* UcbStreamHelper::CreateStream( const OUString& rFileName, StreamMode eOpenMode )
+std::unique_ptr<SvStream> UcbStreamHelper::CreateStream( const OUString& rFileName, StreamMode eOpenMode )
{
// related tdf#99312
// create a specialized interaction handler to manages Web certificates and Web credentials when needed
@@ -149,7 +149,7 @@ SvStream* UcbStreamHelper::CreateStream( const OUString& rFileName, StreamMode e
return lcl_CreateStream( rFileName, eOpenMode, xIHScoped, true /* bEnsureFileExists */ );
}
-SvStream* UcbStreamHelper::CreateStream( const OUString& rFileName, StreamMode eOpenMode,
+std::unique_ptr<SvStream> UcbStreamHelper::CreateStream( const OUString& rFileName, StreamMode eOpenMode,
bool bFileExists )
{
// related tdf#99312
@@ -162,13 +162,13 @@ SvStream* UcbStreamHelper::CreateStream( const OUString& rFileName, StreamMode e
}
-SvStream* UcbStreamHelper::CreateStream( const Reference < XInputStream >& xStream )
+std::unique_ptr<SvStream> UcbStreamHelper::CreateStream( const Reference < XInputStream >& xStream )
{
- SvStream* pStream = nullptr;
+ std::unique_ptr<SvStream> pStream;
UcbLockBytesRef xLockBytes = UcbLockBytes::CreateInputLockBytes( xStream );
if ( xLockBytes.is() )
{
- pStream = new SvStream( xLockBytes.get() );
+ pStream.reset( new SvStream( xLockBytes.get() ) );
pStream->SetBufferSize( 4096 );
pStream->SetError( xLockBytes->GetError() );
}
@@ -176,15 +176,15 @@ SvStream* UcbStreamHelper::CreateStream( const Reference < XInputStream >& xStre
return pStream;
}
-SvStream* UcbStreamHelper::CreateStream( const Reference < XStream >& xStream )
+std::unique_ptr<SvStream> UcbStreamHelper::CreateStream( const Reference < XStream >& xStream )
{
- SvStream* pStream = nullptr;
+ std::unique_ptr<SvStream> pStream;
if ( xStream->getOutputStream().is() )
{
UcbLockBytesRef xLockBytes = UcbLockBytes::CreateLockBytes( xStream );
if ( xLockBytes.is() )
{
- pStream = new SvStream( xLockBytes.get() );
+ pStream.reset( new SvStream( xLockBytes.get() ) );
pStream->SetBufferSize( 4096 );
pStream->SetError( xLockBytes->GetError() );
}
@@ -195,16 +195,16 @@ SvStream* UcbStreamHelper::CreateStream( const Reference < XStream >& xStream )
return pStream;
}
-SvStream* UcbStreamHelper::CreateStream( const Reference < XInputStream >& xStream, bool bCloseStream )
+std::unique_ptr<SvStream> UcbStreamHelper::CreateStream( const Reference < XInputStream >& xStream, bool bCloseStream )
{
- SvStream* pStream = nullptr;
+ std::unique_ptr<SvStream> pStream;
UcbLockBytesRef xLockBytes = UcbLockBytes::CreateInputLockBytes( xStream );
if ( xLockBytes.is() )
{
if ( !bCloseStream )
xLockBytes->setDontClose_Impl();
- pStream = new SvStream( xLockBytes.get() );
+ pStream.reset( new SvStream( xLockBytes.get() ) );
pStream->SetBufferSize( 4096 );
pStream->SetError( xLockBytes->GetError() );
}
@@ -212,9 +212,9 @@ SvStream* UcbStreamHelper::CreateStream( const Reference < XInputStream >& xStre
return pStream;
};
-SvStream* UcbStreamHelper::CreateStream( const Reference < XStream >& xStream, bool bCloseStream )
+std::unique_ptr<SvStream> UcbStreamHelper::CreateStream( const Reference < XStream >& xStream, bool bCloseStream )
{
- SvStream* pStream = nullptr;
+ std::unique_ptr<SvStream> pStream;
if ( xStream->getOutputStream().is() )
{
UcbLockBytesRef xLockBytes = UcbLockBytes::CreateLockBytes( xStream );
@@ -223,7 +223,7 @@ SvStream* UcbStreamHelper::CreateStream( const Reference < XStream >& xStream, b
if ( !bCloseStream )
xLockBytes->setDontClose_Impl();
- pStream = new SvStream( xLockBytes.get() );
+ pStream.reset( new SvStream( xLockBytes.get() ) );
pStream->SetBufferSize( 4096 );
pStream->SetError( xLockBytes->GetError() );
}