diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2024-08-22 09:27:34 +0500 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2024-08-22 08:22:49 +0200 |
commit | 53ac9e0f3ceff4a18929818667bb8aae9c05ad12 (patch) | |
tree | cb9715354018fbb0d324822157727c33128644fc /embeddedobj/source | |
parent | d255a8306e7a26476fe11dbdcf38f6cb5665a48b (diff) |
Make OleEmbeddedObject::GetRidOfComponent safer when releasing lock
Thanks Michael Stahl for the useful advise - see
https://gerrit.libreoffice.org/c/core/+/171996/comment/4dc20148_5ec861ad/
Change-Id: I16e1876a81a52f291ede49572f012c15d4cd9a6d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172233
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'embeddedobj/source')
-rw-r--r-- | embeddedobj/source/msole/olemisc.cxx | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/embeddedobj/source/msole/olemisc.cxx b/embeddedobj/source/msole/olemisc.cxx index 13fc558a529e..582ae49de56f 100644 --- a/embeddedobj/source/msole/olemisc.cxx +++ b/embeddedobj/source/msole/olemisc.cxx @@ -230,23 +230,26 @@ void OleEmbeddedObject::GetRidOfComponent(osl::ResettableMutexGuard* guard) SaveObject_Impl(); m_pOleComponent->removeCloseListener( m_xClosePreventer ); + // When releasing the guard below, avoid a case when two threads are doing the same; + // store the reference on stack and clear m_pOleComponent in advance + rtl::Reference<OleComponent> pOleComponent(std::move(m_pOleComponent)); try { std::optional<osl::ResettableMutexGuardScopedReleaser> oReleaser; if (guard) oReleaser.emplace(*guard); - m_pOleComponent->close( false ); + pOleComponent->close(false); } catch( const uno::Exception& ) { + m_pOleComponent = std::move(pOleComponent); // TODO: there should be a special listener to wait for component closing // and to notify object, may be object itself can be such a listener m_pOleComponent->addCloseListener( m_xClosePreventer ); throw; } - m_pOleComponent->disconnectEmbeddedObject(); - m_pOleComponent.clear(); + pOleComponent->disconnectEmbeddedObject(); } #else (void)guard; |