diff options
author | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2016-03-11 06:43:06 +0100 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2016-03-11 06:38:15 +0000 |
commit | e94d5233dd7939c54eb52fff456e817cecdf0a4c (patch) | |
tree | 24acd3465e88b1a2a26246272a41236edfbe9b21 /sd/source/ui | |
parent | fb827f2a342602f7e62dbdebb638326193315eb6 (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 'sd/source/ui')
-rw-r--r-- | sd/source/ui/dlg/navigatr.cxx | 4 | ||||
-rw-r--r-- | sd/source/ui/docshell/docshel4.cxx | 6 | ||||
-rw-r--r-- | sd/source/ui/func/fuinsfil.cxx | 10 | ||||
-rw-r--r-- | sd/source/ui/unoidl/sddetect.cxx | 2 | ||||
-rw-r--r-- | sd/source/ui/view/sdview4.cxx | 4 |
5 files changed, 12 insertions, 14 deletions
diff --git a/sd/source/ui/dlg/navigatr.cxx b/sd/source/ui/dlg/navigatr.cxx index bbee98c57b1c..8003a4aec1ee 100644 --- a/sd/source/ui/dlg/navigatr.cxx +++ b/sd/source/ui/dlg/navigatr.cxx @@ -579,7 +579,7 @@ bool SdNavigatorWin::InsertFile(const OUString& rFileName) else { // show dragged-in document - const SfxFilter* pFilter = nullptr; + std::shared_ptr<const SfxFilter> pFilter; ErrCode nErr = 0; if (aFileName != maDropFileName) @@ -587,7 +587,7 @@ bool SdNavigatorWin::InsertFile(const OUString& rFileName) SfxMedium aMed(aFileName, (StreamMode::READ | StreamMode::SHARE_DENYNONE)); SfxFilterMatcher aMatch( OUString("simpress") ); aMed.UseInteractionHandler( true ); - nErr = aMatch.GuessFilter(aMed, &pFilter); + nErr = aMatch.GuessFilter(aMed, pFilter); } if ((pFilter && !nErr) || aFileName == maDropFileName) diff --git a/sd/source/ui/docshell/docshel4.cxx b/sd/source/ui/docshell/docshel4.cxx index ff5999d6d030..71ac8e4e45dd 100644 --- a/sd/source/ui/docshell/docshel4.cxx +++ b/sd/source/ui/docshell/docshel4.cxx @@ -572,7 +572,7 @@ bool DrawDocShell::ConvertTo( SfxMedium& rMedium ) if( mpDoc->GetPageCount() ) { - const SfxFilter* pMediumFilter = rMedium.GetFilter(); + std::shared_ptr<const SfxFilter> pMediumFilter = rMedium.GetFilter(); const OUString aTypeName( pMediumFilter->GetTypeName() ); SdFilter* pFilter = nullptr; @@ -613,8 +613,6 @@ bool DrawDocShell::ConvertTo( SfxMedium& rMedium ) bRet = pFilter->Export(); if( !bRet ) mpDoc->SetSwapGraphicsMode( nOldSwapMode ); - - delete pFilter; } } @@ -945,7 +943,7 @@ bool DrawDocShell::GetObjectIsmarked(const OUString& rBookmark, bool bRealizeMul bool DrawDocShell::SaveAsOwnFormat( SfxMedium& rMedium ) { - const SfxFilter* pFilter = rMedium.GetFilter(); + std::shared_ptr<const SfxFilter> pFilter = rMedium.GetFilter(); if (pFilter->IsOwnTemplateFormat()) { diff --git a/sd/source/ui/func/fuinsfil.cxx b/sd/source/ui/func/fuinsfil.cxx index e057342b7c26..04aba7188a9d 100644 --- a/sd/source/ui/func/fuinsfil.cxx +++ b/sd/source/ui/func/fuinsfil.cxx @@ -97,7 +97,7 @@ OUString lcl_GetExtensionsList ( ::std::vector< FilterDesc > const& rFilterDescL } void lcl_AddFilter ( ::std::vector< FilterDesc >& rFilterDescList, - const SfxFilter *pFilter ) + std::shared_ptr<const SfxFilter> pFilter ) { if (pFilter) rFilterDescList.push_back( ::std::make_pair( pFilter->GetUIName(), pFilter->GetDefaultExtension() ) ); @@ -165,7 +165,7 @@ void FuInsertFile::DoExecute( SfxRequest& rReq ) try { // Get main filter - const SfxFilter* pFilter = SfxFilter::GetDefaultFilterFromFactory( aOwnCont ); + std::shared_ptr<const SfxFilter> pFilter = SfxFilter::GetDefaultFilterFromFactory( aOwnCont ); lcl_AddFilter( aFilterVector, pFilter ); // get template filter @@ -259,9 +259,9 @@ void FuInsertFile::DoExecute( SfxRequest& rReq ) mpDocSh->SetWaitCursor( true ); std::unique_ptr<SfxMedium> xMedium(new SfxMedium(aFile, StreamMode::READ | StreamMode::NOCREATE)); - const SfxFilter* pFilter = nullptr; + std::shared_ptr<const SfxFilter> pFilter; - SfxGetpApp()->GetFilterMatcher().GuessFilter(*xMedium, &pFilter); + SfxGetpApp()->GetFilterMatcher().GuessFilter(*xMedium, pFilter); bool bDrawMode = mpViewShell && dynamic_cast< const DrawViewShell *>( mpViewShell ) != nullptr; bool bInserted = false; @@ -726,7 +726,7 @@ bool FuInsertFile::InsSDDinOlMode(SfxMedium* pMedium) void FuInsertFile::GetSupportedFilterVector( ::std::vector< OUString >& rFilterVector ) { SfxFilterMatcher& rMatcher = SfxGetpApp()->GetFilterMatcher(); - const SfxFilter* pSearchFilter = nullptr; + std::shared_ptr<const SfxFilter> pSearchFilter; rFilterVector.clear(); diff --git a/sd/source/ui/unoidl/sddetect.cxx b/sd/source/ui/unoidl/sddetect.cxx index 4eff4b14fb55..5ad76a4bbeb5 100644 --- a/sd/source/ui/unoidl/sddetect.cxx +++ b/sd/source/ui/unoidl/sddetect.cxx @@ -123,7 +123,7 @@ OUString SAL_CALL SdFilterDetect::detect( Sequence< beans::PropertyValue >& lDes } SfxFilterMatcher aMatch("sdraw"); - const SfxFilter* pFilter = aMatch.GetFilter4FilterName( aName ); + std::shared_ptr<const SfxFilter> pFilter = aMatch.GetFilter4FilterName( aName ); if ( pFilter ) return pFilter->GetRealTypeName(); } diff --git a/sd/source/ui/view/sdview4.cxx b/sd/source/ui/view/sdview4.cxx index ffda4fe52287..c13639fb8e16 100644 --- a/sd/source/ui/view/sdview4.cxx +++ b/sd/source/ui/view/sdview4.cxx @@ -446,9 +446,9 @@ IMPL_LINK_NOARG_TYPED(View, DropInsertFileHdl, Idle *, void) } if( !bOK ) { - const SfxFilter* pFoundFilter = nullptr; + std::shared_ptr<const SfxFilter> pFoundFilter; SfxMedium aSfxMedium( aCurrentDropFile, StreamMode::READ | StreamMode::SHARE_DENYNONE ); - ErrCode nErr = SfxGetpApp()->GetFilterMatcher().GuessFilter( aSfxMedium, &pFoundFilter ); + ErrCode nErr = SfxGetpApp()->GetFilterMatcher().GuessFilter( aSfxMedium, pFoundFilter ); if( pFoundFilter && !nErr ) { |