include/vcl/svapp.hxx | 20 ++++++++++++++++++++ vcl/win/dtrans/WinClipboard.cxx | 13 ++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-)
New commits: commit c921f9bd64187823af2356d7a8ceb77444c17219 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Mon Dec 14 10:00:40 2020 +0300 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Wed Jan 6 12:22:17 2021 +0100 Release solar mutex before using an apartment-threaded COM object See https://lists.freedesktop.org/archives/libreoffice/2020-December/086448.html for motivation This partially reverts f5ab8bcbfd20ecce4a358f62ee3f81b8b968a5de. Although this change is questionable, it's intended to avoid crashes (tdf#139074); a better fix should replace this eventually. Optionally releasing a lock isn't a good API and might hide other bugs, but the better solution to handle all requests in the main thread would need an even larger rewrite of the Windows clipboard code. It's simply too late for that in this LO release cycle. Change-Id: I60e847599fe873025c9903b9d6290ed4cdf4a961 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107669 Tested-by: Mike Kaganski <mike.kagan...@collabora.com> Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/include/vcl/svapp.hxx b/include/vcl/svapp.hxx index bfa92cf88321..fa5702717086 100644 --- a/include/vcl/svapp.hxx +++ b/include/vcl/svapp.hxx @@ -1421,6 +1421,26 @@ public: ~SolarMutexReleaser() { Application::AcquireSolarMutex( mnReleased ); } }; +/** + A helper class that calls Application::ReleaseSolarMutex() in its constructor + *if it was acquired* and restores the mutex in its destructor. +*/ +class SolarMutexReleaserIfAcquired +{ + const sal_uInt32 mnReleased; +public: + SolarMutexReleaserIfAcquired() + : mnReleased( + Application::GetSolarMutex().IsCurrentThread() ? Application::ReleaseSolarMutex() : 0) + { + } + ~SolarMutexReleaserIfAcquired() + { + if (mnReleased) + Application::AcquireSolarMutex(mnReleased); + } +}; + VCL_DLLPUBLIC Application* GetpApp(); // returns true if vcl is already initialized diff --git a/vcl/win/dtrans/WinClipboard.cxx b/vcl/win/dtrans/WinClipboard.cxx index 4135b5cef93c..1f49bde99192 100644 --- a/vcl/win/dtrans/WinClipboard.cxx +++ b/vcl/win/dtrans/WinClipboard.cxx @@ -92,9 +92,6 @@ CWinClipboard::~CWinClipboard() uno::Reference<datatransfer::XTransferable> SAL_CALL CWinClipboard::getContents() { - DBG_TESTSOLARMUTEX(); - SolarMutexReleaser aReleaser; - osl::MutexGuard aGuard(m_aMutex); if (rBHelper.bDisposed) @@ -129,8 +126,14 @@ uno::Reference<datatransfer::XTransferable> SAL_CALL CWinClipboard::getContents( // com smart pointer to the IDataObject from clipboard IDataObjectPtr pIDo(new CAPNDataObject(pIDataObject)); - // remember pIDo destroys itself due to the smart pointer - rClipContent = CDOTransferable::create(m_xContext, pIDo); + { + // before calling COM methods of an apartment-threaded COM object, release solar mutex + // to avoid deadlocking on waiting clipboard thread that would try to acquire it + SolarMutexReleaserIfAcquired aReleaser; + + // remember pIDo destroys itself due to the smart pointer + rClipContent = CDOTransferable::create(m_xContext, pIDo); + } osl::MutexGuard aGuard2(m_ClipContentMutex); m_foreignContent = rClipContent; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits