From 3ec25899e05035ac882971637dfc9b6fa84437c9 Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Wed, 15 Oct 2014 21:35:06 +0200 Subject: sw: fix temp file leak in SwIoSystem::GetFileFilter() Change-Id: Id483d58a9de27a247880aedfe6bb3fe1d410129c --- sw/source/filter/basflt/iodetect.cxx | 21 +++++++++------------ sw/source/uibase/dbui/dbmgr.cxx | 2 +- sw/source/uibase/dochdl/swdtflvr.cxx | 3 +-- 3 files changed, 11 insertions(+), 15 deletions(-) (limited to 'sw/source') diff --git a/sw/source/filter/basflt/iodetect.cxx b/sw/source/filter/basflt/iodetect.cxx index c6fdded62c63..9c60782a8e05 100644 --- a/sw/source/filter/basflt/iodetect.cxx +++ b/sw/source/filter/basflt/iodetect.cxx @@ -198,9 +198,7 @@ void TerminateBuffer(sal_Char *pBuffer, sal_uLong nBytesRead, sal_uLong nBufferL // Check the type of the stream (file) by searching for corresponding set of bytes. // If no known type is found, return ASCII for now! // Returns the internal FilterName. -// rPrefFltName is the internal FilterName that was chosen by the user in the Open Dlg. -const SfxFilter* SwIoSystem::GetFileFilter(const OUString& rFileName, - const OUString& rPrefFltName, SfxMedium* pMedium) +const SfxFilter* SwIoSystem::GetFileFilter(const OUString& rFileName) { SfxFilterContainer aCntSw( OUString(sSWRITER) ); SfxFilterContainer aCntSwWeb( OUString(sSWRITERWEB) ); @@ -212,21 +210,20 @@ const SfxFilter* SwIoSystem::GetFileFilter(const OUString& rFileName, if ( !pFilter ) return 0; - if( pMedium ? ( pMedium->IsStorage() || SotStorage::IsStorageFile( pMedium->GetInStream() ) ) : SotStorage::IsStorageFile( rFileName ) ) + ::boost::scoped_ptr pMedium; + if (SotStorage::IsStorageFile(rFileName)) { // package storage or OLEStorage based format SotStorageRef xStg; - if (!pMedium ) - { - INetURLObject aObj; - aObj.SetSmartProtocol( INET_PROT_FILE ); - aObj.SetSmartURL( rFileName ); - pMedium = new SfxMedium( aObj.GetMainURL( INetURLObject::NO_DECODE ), STREAM_STD_READ ); - } + INetURLObject aObj; + aObj.SetSmartProtocol( INET_PROT_FILE ); + aObj.SetSmartURL( rFileName ); + pMedium.reset(new SfxMedium(aObj.GetMainURL(INetURLObject::NO_DECODE), STREAM_STD_READ)); // templates should not get precedence over "normal" filters (#i35508, #i33168) const SfxFilter* pTemplateFilter = 0; - const SfxFilter* pOldFilter = pFCntnr->GetFilter4FilterName( rPrefFltName ); + const SfxFilter* pOldFilter = pFCntnr->GetFilter4FilterName(""); + assert(!pOldFilter); bool bLookForTemplate = pOldFilter && pOldFilter->IsOwnTemplateFormat(); if ( pMedium->IsStorage() ) { diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx index a39ad546b17a..141f9a2891e3 100644 --- a/sw/source/uibase/dbui/dbmgr.cxx +++ b/sw/source/uibase/dbui/dbmgr.cxx @@ -867,7 +867,7 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, if( bMergeShell || !pSourceDocSh->IsModified() ) { const SfxFilter* pStoreToFilter = SwIoSystem::GetFileFilter( - pSourceDocSh->GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE ), ::aEmptyOUStr ); + pSourceDocSh->GetMedium()->GetURLObject().GetMainURL(INetURLObject::NO_DECODE)); SfxFilterContainer* pFilterContainer = SwDocShell::Factory().GetFilterContainer(); const OUString* pStoreToFilterOptions = 0; diff --git a/sw/source/uibase/dochdl/swdtflvr.cxx b/sw/source/uibase/dochdl/swdtflvr.cxx index 18f79a541729..14ce7d61f2a6 100644 --- a/sw/source/uibase/dochdl/swdtflvr.cxx +++ b/sw/source/uibase/dochdl/swdtflvr.cxx @@ -2570,8 +2570,7 @@ bool SwTransferable::_PasteFileName( TransferableDataHelper& rData, //Own FileFormat? --> insert, not for StarWriter/Web OUString sFileURL = URIHelper::SmartRel2Abs(INetURLObject(), sFile, Link(), false ); const SfxFilter* pFlt = SW_PASTESDR_SETATTR == nAction - ? 0 : SwIoSystem::GetFileFilter( - sFileURL, aEmptyOUStr ); + ? 0 : SwIoSystem::GetFileFilter(sFileURL); if( pFlt && !rSh.GetView().GetDocShell()->ISA(SwWebDocShell) ) { // and then pull up the insert-region-dialog by PostUser event -- cgit