diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2024-03-06 16:06:40 +0600 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2024-03-11 04:43:28 +0100 |
commit | 1ac5353bbb25bd9ff0ab0e157b3dbd0da325480a (patch) | |
tree | 540dc6574b0d1b2e67afee3d670b8805493f28fa /sc/source/ui/app/drwtrans.cxx | |
parent | e2bfc34d146806a8f96be0cd2323d716f12cba4e (diff) |
Use weak reference to SfxObjectShell in SfxEventHint to avoid use-after-free
The events may be processed after the shell has been destroyed. This is
happening reliably after commit e2bfc34d146806a8f96be0cd2323d716f12cba4e
(Reimplement OleComponentNative_Impl to use IGlobalInterfaceTable,
2024-03-11) when controlling LibreOffice from external Java scripts; but
obviously, it could happen before as well.
Now SotObject inherits from cppu::OWeakObject, instead of SvRefBase.
Change-Id: I73a3531499a3068c801c98f40de39bdf8ad90b2b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164458
Tested-by: Mike Kaganski <mike.kaganski@collabora.com>
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sc/source/ui/app/drwtrans.cxx')
-rw-r--r-- | sc/source/ui/app/drwtrans.cxx | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/sc/source/ui/app/drwtrans.cxx b/sc/source/ui/app/drwtrans.cxx index 3257a6cae4d3..76c221dd18d3 100644 --- a/sc/source/ui/app/drwtrans.cxx +++ b/sc/source/ui/app/drwtrans.cxx @@ -677,13 +677,12 @@ void ScDrawTransferObj::InitDocShell() if ( m_aDocShellRef.is() ) return; - ScDocShell* pDocSh = new ScDocShell; - m_aDocShellRef = pDocSh; // ref must be there before InitNew + m_aDocShellRef = new ScDocShell; // ref must be there before InitNew - pDocSh->DoInitNew(); + m_aDocShellRef->DoInitNew(); - ScDocument& rDestDoc = pDocSh->GetDocument(); - rDestDoc.InitDrawLayer( pDocSh ); + ScDocument& rDestDoc = m_aDocShellRef->GetDocument(); + rDestDoc.InitDrawLayer(m_aDocShellRef.get()); auto pPool = rDestDoc.GetStyleSheetPool(); pPool->CopyStyleFrom(m_pModel->GetStyleSheetPool(), ScResId(STR_STYLENAME_STANDARD), SfxStyleFamily::Frame); @@ -717,18 +716,18 @@ void ScDrawTransferObj::InitDocShell() } tools::Rectangle aDestArea( Point(), m_aSrcSize ); - pDocSh->SetVisArea( aDestArea ); + m_aDocShellRef->SetVisArea(aDestArea); ScViewOptions aViewOpt( rDestDoc.GetViewOptions() ); aViewOpt.SetOption( VOPT_GRID, false ); rDestDoc.SetViewOptions( aViewOpt ); - ScViewData aViewData( *pDocSh, nullptr ); + ScViewData aViewData(*m_aDocShellRef, nullptr); aViewData.SetTabNo( 0 ); aViewData.SetScreen( aDestArea ); aViewData.SetCurX( 0 ); aViewData.SetCurY( 0 ); - pDocSh->UpdateOle(aViewData, true); + m_aDocShellRef->UpdateOle(aViewData, true); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |