summaryrefslogtreecommitdiff
path: root/sc/source
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2016-03-11 06:43:06 +0100
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2016-03-11 06:38:15 +0000
commite94d5233dd7939c54eb52fff456e817cecdf0a4c (patch)
tree24acd3465e88b1a2a26246272a41236edfbe9b21 /sc/source
parentfb827f2a342602f7e62dbdebb638326193315eb6 (diff)
work on sane lifecylce for SfxFilter
all SfxFilter instances should now be hold inside of a std::shared_ptr. This fixes a number of huge memory leaks in the test framework and removes one huge source of memory issue in sfx2. SfxMedium contains a pointer to the SfxFilter but does not own. Therefore it is required that any SfxFilter belonging to a SfxMedium lives longer. However this seems to work mostly by hoping that all SfxFilter instances are stored in a global array. As we have seen with the tests this is not true (there are also some cases inside of sd that seem to not follow that pattern as well). Change-Id: I12fd04a504cc4efc0a94967abd91c6fe2c6a8ce8 Reviewed-on: https://gerrit.libreoffice.org/23140 Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com> Tested-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Diffstat (limited to 'sc/source')
-rw-r--r--sc/source/ui/docshell/arealink.cxx2
-rw-r--r--sc/source/ui/docshell/docsh.cxx4
-rw-r--r--sc/source/ui/docshell/docsh4.cxx2
-rw-r--r--sc/source/ui/docshell/externalrefmgr.cxx2
-rw-r--r--sc/source/ui/docshell/tablink.cxx12
-rw-r--r--sc/source/ui/miscdlgs/linkarea.cxx4
-rw-r--r--sc/source/ui/unoobj/scdetect.cxx2
-rw-r--r--sc/source/ui/view/viewfun4.cxx4
8 files changed, 16 insertions, 16 deletions
diff --git a/sc/source/ui/docshell/arealink.cxx b/sc/source/ui/docshell/arealink.cxx
index 2dfba9596477..f4030935ec5f 100644
--- a/sc/source/ui/docshell/arealink.cxx
+++ b/sc/source/ui/docshell/arealink.cxx
@@ -236,7 +236,7 @@ bool ScAreaLink::Refresh( const OUString& rNewFile, const OUString& rNewFilter,
OUString aNewUrl( ScGlobal::GetAbsDocName( rNewFile, pImpl->m_pDocSh ) );
bool bNewUrlName = (aNewUrl != aFileName);
- const SfxFilter* pFilter = pImpl->m_pDocSh->GetFactory().GetFilterContainer()->GetFilter4FilterName(rNewFilter);
+ std::shared_ptr<const SfxFilter> pFilter = pImpl->m_pDocSh->GetFactory().GetFilterContainer()->GetFilter4FilterName(rNewFilter);
if (!pFilter)
return false;
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index 0309e1dcc44a..4c69ed1965df 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -1049,7 +1049,7 @@ bool ScDocShell::ConvertFrom( SfxMedium& rMedium )
const SfxUInt16Item* pUpdateDocItem = SfxItemSet::GetItem<SfxUInt16Item>(rMedium.GetItemSet(), SID_UPDATEDOCMODE, false);
nCanUpdate = pUpdateDocItem ? pUpdateDocItem->GetValue() : css::document::UpdateDocMode::NO_UPDATE;
- const SfxFilter* pFilter = rMedium.GetFilter();
+ std::shared_ptr<const SfxFilter> pFilter = rMedium.GetFilter();
if (pFilter)
{
OUString aFltName = pFilter->GetFilterName();
@@ -1517,7 +1517,7 @@ bool ScDocShell::ConvertFrom( SfxMedium& rMedium )
bool ScDocShell::LoadExternal( SfxMedium& rMed )
{
- const SfxFilter* pFilter = rMed.GetFilter();
+ std::shared_ptr<const SfxFilter> pFilter = rMed.GetFilter();
if (!pFilter)
return false;
diff --git a/sc/source/ui/docshell/docsh4.cxx b/sc/source/ui/docshell/docsh4.cxx
index 98f094b74f90..62b27d8eb215 100644
--- a/sc/source/ui/docshell/docsh4.cxx
+++ b/sc/source/ui/docshell/docsh4.cxx
@@ -718,7 +718,7 @@ void ScDocShell::Execute( SfxRequest& rReq )
// GetFilter needs name without the prefix.
ScDocumentLoader::RemoveAppPrefix( aFilterName );
- const SfxFilter* pFilter = ScDocShell::Factory().GetFilterContainer()->GetFilter4FilterName( aFilterName );
+ std::shared_ptr<const SfxFilter> pFilter = ScDocShell::Factory().GetFilterContainer()->GetFilter4FilterName( aFilterName );
SfxItemSet* pSet = new SfxAllItemSet( pApp->GetPool() );
if (!aOptions.isEmpty())
pSet->Put( SfxStringItem( SID_FILE_FILTEROPTIONS, aOptions ) );
diff --git a/sc/source/ui/docshell/externalrefmgr.cxx b/sc/source/ui/docshell/externalrefmgr.cxx
index 8319e5ea0cf4..c2ace4a4e825 100644
--- a/sc/source/ui/docshell/externalrefmgr.cxx
+++ b/sc/source/ui/docshell/externalrefmgr.cxx
@@ -2431,7 +2431,7 @@ SfxObjectShellRef ScExternalRefManager::loadSrcDocument(sal_uInt16 nFileId, OUSt
else
ScDocumentLoader::GetFilterName(aFile, rFilter, aOptions, true, false);
ScDocumentLoader::GetFilterName(aFile, rFilter, aOptions, true, false);
- const SfxFilter* pFilter = ScDocShell::Factory().GetFilterContainer()->GetFilter4FilterName(rFilter);
+ std::shared_ptr<const SfxFilter> pFilter = ScDocShell::Factory().GetFilterContainer()->GetFilter4FilterName(rFilter);
if (pFileData->maRelativeName.isEmpty())
{
diff --git a/sc/source/ui/docshell/tablink.cxx b/sc/source/ui/docshell/tablink.cxx
index 2b2572c3a7ad..aedb902a4f7e 100644
--- a/sc/source/ui/docshell/tablink.cxx
+++ b/sc/source/ui/docshell/tablink.cxx
@@ -171,7 +171,7 @@ bool ScTableLink::Refresh(const OUString& rNewFile, const OUString& rNewFilter,
OUString aNewUrl = ScGlobal::GetAbsDocName(rNewFile, pImpl->m_pDocSh);
bool bNewUrlName = !aFileName.equals(aNewUrl);
- const SfxFilter* pFilter = pImpl->m_pDocSh->GetFactory().GetFilterContainer()->GetFilter4FilterName(rNewFilter);
+ std::shared_ptr<const SfxFilter> pFilter = pImpl->m_pDocSh->GetFactory().GetFilterContainer()->GetFilter4FilterName(rNewFilter);
if (!pFilter)
return false;
@@ -462,7 +462,7 @@ bool ScDocumentLoader::GetFilterName( const OUString& rFileName,
// Filter-Detection
- const SfxFilter* pSfxFilter = nullptr;
+ std::shared_ptr<const SfxFilter> pSfxFilter;
SfxMedium* pMedium = new SfxMedium( rFileName, STREAM_STD_READ );
if ( pMedium->GetError() == ERRCODE_NONE )
{
@@ -471,9 +471,9 @@ bool ScDocumentLoader::GetFilterName( const OUString& rFileName,
SfxFilterMatcher aMatcher("scalc");
if( bWithContent )
- aMatcher.GuessFilter( *pMedium, &pSfxFilter );
+ aMatcher.GuessFilter( *pMedium, pSfxFilter );
else
- aMatcher.GuessFilterIgnoringContent( *pMedium, &pSfxFilter );
+ aMatcher.GuessFilterIgnoringContent( *pMedium, pSfxFilter );
}
bool bOK = false;
@@ -497,7 +497,7 @@ void ScDocumentLoader::RemoveAppPrefix( OUString& rFilterName )
rFilterName = rFilterName.copy( aAppPrefix.getLength());
}
-SfxMedium* ScDocumentLoader::CreateMedium( const OUString& rFileName, const SfxFilter* pFilter,
+SfxMedium* ScDocumentLoader::CreateMedium( const OUString& rFileName, std::shared_ptr<const SfxFilter> pFilter,
const OUString& rOptions )
{
// Always create SfxItemSet so ScDocShell can set options.
@@ -517,7 +517,7 @@ ScDocumentLoader::ScDocumentLoader( const OUString& rFileName,
if ( rFilterName.isEmpty() )
GetFilterName( rFileName, rFilterName, rOptions, true, bWithInteraction );
- const SfxFilter* pFilter = ScDocShell::Factory().GetFilterContainer()->GetFilter4FilterName( rFilterName );
+ std::shared_ptr<const SfxFilter> pFilter = ScDocShell::Factory().GetFilterContainer()->GetFilter4FilterName( rFilterName );
pMedium = CreateMedium( rFileName, pFilter, rOptions);
if ( pMedium->GetError() != ERRCODE_NONE )
diff --git a/sc/source/ui/miscdlgs/linkarea.cxx b/sc/source/ui/miscdlgs/linkarea.cxx
index 98b1958f8e1c..2306e69c048b 100644
--- a/sc/source/ui/miscdlgs/linkarea.cxx
+++ b/sc/source/ui/miscdlgs/linkarea.cxx
@@ -220,10 +220,10 @@ IMPL_LINK_TYPED( ScLinkedAreaDlg, DialogClosedHdl, sfx2::FileDialogHelper*, _pFi
const OUString aHTMLFilterName( FILTERNAME_HTML );
const OUString aWebQFilterName( FILTERNAME_QUERY );
- const SfxFilter* pFilter = pMed->GetFilter();
+ std::shared_ptr<const SfxFilter> pFilter = pMed->GetFilter();
if (pFilter && aHTMLFilterName.equals(pFilter->GetFilterName()))
{
- const SfxFilter* pNewFilter =
+ std::shared_ptr<const SfxFilter> pNewFilter =
ScDocShell::Factory().GetFilterContainer()->GetFilter4FilterName( aWebQFilterName );
if( pNewFilter )
pMed->SetFilter( pNewFilter );
diff --git a/sc/source/ui/unoobj/scdetect.cxx b/sc/source/ui/unoobj/scdetect.cxx
index 66dcac2945d3..0f8c1ba8169e 100644
--- a/sc/source/ui/unoobj/scdetect.cxx
+++ b/sc/source/ui/unoobj/scdetect.cxx
@@ -301,7 +301,7 @@ OUString SAL_CALL ScFilterDetect::detect( uno::Sequence<beans::PropertyValue>& l
return OUString();
SfxFilterMatcher aMatcher("scalc");
- const SfxFilter* pFilter = aMatcher.GetFilter4FilterName(OUString::createFromAscii(pSearchFilterName));
+ std::shared_ptr<const SfxFilter> pFilter = aMatcher.GetFilter4FilterName(OUString::createFromAscii(pSearchFilterName));
if (!pFilter)
return OUString();
diff --git a/sc/source/ui/view/viewfun4.cxx b/sc/source/ui/view/viewfun4.cxx
index 6fac2e8b6fed..0e23548a18e0 100644
--- a/sc/source/ui/view/viewfun4.cxx
+++ b/sc/source/ui/view/viewfun4.cxx
@@ -584,7 +584,7 @@ bool ScViewFunc::PasteFile( const Point& rPos, const OUString& rFile, bool bLink
if (!bLink) // for bLink only graphics or URL
{
// 1. can I open the file?
- const SfxFilter* pFlt = nullptr;
+ std::shared_ptr<const SfxFilter> pFlt;
// search only for its own filters, without selection box (as in ScDocumentLoader)
SfxFilterMatcher aMatcher( ScDocShell::Factory().GetFilterContainer()->GetName() );
@@ -592,7 +592,7 @@ bool ScViewFunc::PasteFile( const Point& rPos, const OUString& rFile, bool bLink
// #i73992# GuessFilter no longer calls UseInteractionHandler.
// This is UI, so it can be called here.
aSfxMedium.UseInteractionHandler(true);
- ErrCode nErr = aMatcher.GuessFilter( aSfxMedium, &pFlt );
+ ErrCode nErr = aMatcher.GuessFilter( aSfxMedium, pFlt );
if ( pFlt && !nErr )
{