diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2024-08-22 09:27:34 +0500 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2024-09-09 11:57:29 +0500 |
commit | 968e3be4d261f6d4f5698ee4acad5d1bac647855 (patch) | |
tree | efcb67f53f0d23c18e41b886528b9ded84f5a591 | |
parent | 4ae90355d888555865145e39958c0e7ee5ed0a01 (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>
-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 ae4a292c37ce..e2af0872f452 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; |