summaryrefslogtreecommitdiff
path: root/vcl/source
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 /vcl/source
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 'vcl/source')
-rw-r--r--vcl/source/filter/graphicfilter.cxx24
-rw-r--r--vcl/source/filter/graphicfilter2.cxx2
-rw-r--r--vcl/source/gdi/impgraph.cxx4
-rw-r--r--vcl/source/graphic/GraphicLoader.cxx4
-rw-r--r--vcl/source/graphic/UnoGraphicProvider.cxx17
5 files changed, 25 insertions, 26 deletions
diff --git a/vcl/source/filter/graphicfilter.cxx b/vcl/source/filter/graphicfilter.cxx
index fea987a63520..fbf495aec3af 100644
--- a/vcl/source/filter/graphicfilter.cxx
+++ b/vcl/source/filter/graphicfilter.cxx
@@ -1297,7 +1297,7 @@ ErrCode GraphicFilter::ImportGraphic(
struct GraphicImportContext
{
/// Pixel data is read from this stream.
- std::shared_ptr<SvStream> m_pStream;
+ std::unique_ptr<SvStream> m_pStream;
/// The Graphic the import filter gets.
std::shared_ptr<Graphic> m_pGraphic;
/// Write pixel data using this access.
@@ -1342,34 +1342,34 @@ void GraphicImportTask::doImport(GraphicImportContext& rContext)
rContext.m_eLinkType = GfxLinkType::NativeJpg;
}
-void GraphicFilter::ImportGraphics(std::vector< std::shared_ptr<Graphic> >& rGraphics, const std::vector< std::shared_ptr<SvStream> >& rStreams)
+void GraphicFilter::ImportGraphics(std::vector< std::shared_ptr<Graphic> >& rGraphics, std::vector< std::unique_ptr<SvStream> > vStreams)
{
static bool bThreads = !getenv("VCL_NO_THREAD_IMPORT");
std::vector<GraphicImportContext> aContexts;
- aContexts.reserve(rStreams.size());
+ aContexts.reserve(vStreams.size());
comphelper::ThreadPool& rSharedPool = comphelper::ThreadPool::getSharedOptimalPool();
std::shared_ptr<comphelper::ThreadTaskTag> pTag = comphelper::ThreadPool::createThreadTaskTag();
- for (const auto& pStream : rStreams)
+ for (auto& pStream : vStreams)
{
aContexts.emplace_back();
GraphicImportContext& rContext = aContexts.back();
if (pStream)
{
- rContext.m_pStream = pStream;
+ rContext.m_pStream = std::move(pStream);
rContext.m_pGraphic = std::make_shared<Graphic>();
rContext.m_nStatus = ERRCODE_NONE;
// Detect the format.
ResetLastError();
- rContext.m_nStreamBegin = pStream->Tell();
+ rContext.m_nStreamBegin = rContext.m_pStream->Tell();
sal_uInt16 nFormat = GRFILTER_FORMAT_DONTKNOW;
- rContext.m_nStatus = ImpTestOrFindFormat(OUString(), *pStream, nFormat);
- pStream->Seek(rContext.m_nStreamBegin);
+ rContext.m_nStatus = ImpTestOrFindFormat(OUString(), *rContext.m_pStream, nFormat);
+ rContext.m_pStream->Seek(rContext.m_nStreamBegin);
// Import the graphic.
- if (rContext.m_nStatus == ERRCODE_NONE && !pStream->GetError())
+ if (rContext.m_nStatus == ERRCODE_NONE && !rContext.m_pStream->GetError())
{
OUString aFilterName = pConfig->GetImportFilterName(nFormat);
@@ -1377,13 +1377,13 @@ void GraphicFilter::ImportGraphics(std::vector< std::shared_ptr<Graphic> >& rGra
{
rContext.m_nImportFlags = GraphicFilterImportFlags::SetLogsizeForJpeg;
- if (!ImportJPEG( *pStream, *rContext.m_pGraphic, rContext.m_nImportFlags | GraphicFilterImportFlags::OnlyCreateBitmap, nullptr))
+ if (!ImportJPEG( *rContext.m_pStream, *rContext.m_pGraphic, rContext.m_nImportFlags | GraphicFilterImportFlags::OnlyCreateBitmap, nullptr))
rContext.m_nStatus = ERRCODE_GRFILTER_FILTERERROR;
else
{
Bitmap& rBitmap = const_cast<Bitmap&>(rContext.m_pGraphic->GetBitmapExRef().GetBitmapRef());
rContext.m_pAccess = o3tl::make_unique<BitmapScopedWriteAccess>(rBitmap);
- pStream->Seek(rContext.m_nStreamBegin);
+ rContext.m_pStream->Seek(rContext.m_nStreamBegin);
if (bThreads)
rSharedPool.pushTask(o3tl::make_unique<GraphicImportTask>(pTag, rContext));
else
@@ -2574,7 +2574,7 @@ ErrCode GraphicFilter::LoadGraphic( const OUString &rPath, const OUString &rFilt
std::unique_ptr<SvStream> pStream;
if ( INetProtocol::File != aURL.GetProtocol() )
- pStream.reset(::utl::UcbStreamHelper::CreateStream( rPath, StreamMode::READ ));
+ pStream = ::utl::UcbStreamHelper::CreateStream( rPath, StreamMode::READ );
ErrCode nRes = ERRCODE_NONE;
if ( !pStream )
diff --git a/vcl/source/filter/graphicfilter2.cxx b/vcl/source/filter/graphicfilter2.cxx
index d0bf0517cd8c..f9b5ae775c7f 100644
--- a/vcl/source/filter/graphicfilter2.cxx
+++ b/vcl/source/filter/graphicfilter2.cxx
@@ -28,7 +28,7 @@
#define DATA_SIZE 640
GraphicDescriptor::GraphicDescriptor( const INetURLObject& rPath ) :
- pFileStm( ::utl::UcbStreamHelper::CreateStream( rPath.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::READ ) ),
+ pFileStm( ::utl::UcbStreamHelper::CreateStream( rPath.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::READ ).release() ),
aPathExt( rPath.GetFileExtension().toAsciiLowerCase() ),
bOwnStream( true )
{
diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx
index ff59da4a9f0b..467e130c8738 100644
--- a/vcl/source/gdi/impgraph.cxx
+++ b/vcl/source/gdi/impgraph.cxx
@@ -1444,7 +1444,7 @@ bool ImpGraphic::ImplSwapOut()
std::unique_ptr<SvStream> xOStm;
try
{
- xOStm.reset(::utl::UcbStreamHelper::CreateStream( aTmpURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::READWRITE | StreamMode::SHARE_DENYWRITE ));
+ xOStm = ::utl::UcbStreamHelper::CreateStream( aTmpURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::READWRITE | StreamMode::SHARE_DENYWRITE );
}
catch( const css::uno::Exception& )
{
@@ -1571,7 +1571,7 @@ bool ImpGraphic::ImplSwapIn()
std::unique_ptr<SvStream> xIStm;
try
{
- xIStm.reset(::utl::UcbStreamHelper::CreateStream( aSwapURL, StreamMode::READWRITE | StreamMode::SHARE_DENYWRITE ));
+ xIStm = ::utl::UcbStreamHelper::CreateStream( aSwapURL, StreamMode::READWRITE | StreamMode::SHARE_DENYWRITE );
}
catch( const css::uno::Exception& )
{
diff --git a/vcl/source/graphic/GraphicLoader.cxx b/vcl/source/graphic/GraphicLoader.cxx
index 22151bf9d88a..770cb2158fba 100644
--- a/vcl/source/graphic/GraphicLoader.cxx
+++ b/vcl/source/graphic/GraphicLoader.cxx
@@ -24,8 +24,8 @@ Graphic loadFromURL(OUString const& rURL)
{
Graphic aGraphic;
- std::unique_ptr<SvStream> pInputStream;
- pInputStream.reset(utl::UcbStreamHelper::CreateStream(rURL, StreamMode::READ));
+ std::unique_ptr<SvStream> pInputStream
+ = utl::UcbStreamHelper::CreateStream(rURL, StreamMode::READ);
if (pInputStream)
{
diff --git a/vcl/source/graphic/UnoGraphicProvider.cxx b/vcl/source/graphic/UnoGraphicProvider.cxx
index bf0b0bc8f654..5b28ed3723c5 100644
--- a/vcl/source/graphic/UnoGraphicProvider.cxx
+++ b/vcl/source/graphic/UnoGraphicProvider.cxx
@@ -366,7 +366,7 @@ uno::Reference< ::graphic::XGraphic > SAL_CALL GraphicProvider::queryGraphic( co
if( xIStm.is() )
{
- pIStm.reset(::utl::UcbStreamHelper::CreateStream( xIStm ));
+ pIStm = ::utl::UcbStreamHelper::CreateStream( xIStm );
}
else if( !aPath.isEmpty() )
{
@@ -379,7 +379,7 @@ uno::Reference< ::graphic::XGraphic > SAL_CALL GraphicProvider::queryGraphic( co
xRet = implLoadStandardImage( aPath );
if( !xRet.is() )
- pIStm.reset(::utl::UcbStreamHelper::CreateStream( aPath, StreamMode::READ ));
+ pIStm = ::utl::UcbStreamHelper::CreateStream( aPath, StreamMode::READ );
}
else if( xBtm.is() )
{
@@ -441,10 +441,10 @@ uno::Sequence< uno::Reference<graphic::XGraphic> > SAL_CALL GraphicProvider::que
SolarMutexGuard aGuard;
// Turn properties into streams.
- std::vector< std::shared_ptr<SvStream> > aStreams;
+ std::vector< std::unique_ptr<SvStream> > aStreams;
for (const auto& rMediaProperties : rMediaPropertiesSeq)
{
- SvStream* pStream = nullptr;
+ std::unique_ptr<SvStream> pStream;
uno::Reference<io::XInputStream> xStream;
for (sal_Int32 i = 0; rMediaProperties.getLength(); ++i)
@@ -458,14 +458,13 @@ uno::Sequence< uno::Reference<graphic::XGraphic> > SAL_CALL GraphicProvider::que
}
}
- aStreams.push_back(std::shared_ptr<SvStream>(pStream));
-
+ aStreams.push_back(std::move(pStream));
}
// Import: streams to graphics.
std::vector< std::shared_ptr<Graphic> > aGraphics;
GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
- rFilter.ImportGraphics(aGraphics, aStreams);
+ rFilter.ImportGraphics(aGraphics, std::move(aStreams));
// Returning: graphics to UNO objects.
std::vector< uno::Reference<graphic::XGraphic> > aRet;
@@ -718,7 +717,7 @@ void SAL_CALL GraphicProvider::storeGraphic( const uno::Reference< ::graphic::XG
OUString aURL;
aValue >>= aURL;
- pOStm.reset(::utl::UcbStreamHelper::CreateStream( aURL, StreamMode::WRITE | StreamMode::TRUNC ));
+ pOStm = ::utl::UcbStreamHelper::CreateStream( aURL, StreamMode::WRITE | StreamMode::TRUNC );
aPath = aURL;
}
else if (aName == "OutputStream")
@@ -728,7 +727,7 @@ void SAL_CALL GraphicProvider::storeGraphic( const uno::Reference< ::graphic::XG
aValue >>= xOStm;
if( xOStm.is() )
- pOStm.reset(::utl::UcbStreamHelper::CreateStream( xOStm ));
+ pOStm = ::utl::UcbStreamHelper::CreateStream( xOStm );
}
}