Kaydet (Commit) 713ac313 authored tarafından Michael Stahl's avatar Michael Stahl

svx: fix deadlock in Gallery::GetGalleryInstance()

Seen in UITest_writer_tests.

Use C++11 thread-safe static initialisation here, which should
avoid the deadlock that is caused by relying on
osl::Mutex::getGlobalMutex().

Thread #1:

2  in osl_acquireMutex(oslMutexImpl*) (pMutex=0x1ad2c70) at sal/osl/unx/mutex.cxx:97
3  in osl::Mutex::acquire() (this=0x7ff3252b9628 <rtl::Static<osl::Mutex, (anonymous namespace)::theImplHelperInitMutex>::get()::instance>) at include/osl/mutex.hxx:56
4  in osl::Guard<osl::Mutex>::Guard(osl::Mutex&) (this=0x7ffca8bdd6c0, t=...) at include/osl/mutex.hxx:129
5  in cppu::getTypeEntries(cppu::class_data*) (cd=0x7ff31e458fe0 <cppu::detail::ImplClassData<cppu::WeakImplHelper<com::sun::star::io::XActiveDataControl, com::sun::star::io::XActiveDataSink>, com::sun::star::io::XActiveDataControl, com::sun::star::io::XActiveDataSink>::operator()()::s_cd>) at cppuhelper/source/implbase_ex.cxx:89
6  in cppu::queryDeepNoXInterface(typelib_TypeDescriptionReference const*, cppu::class_data*, void*) (pDemandedTDR=0x2e643b0, cd=0x7ff31e458fe0 <cppu::detail::ImplClassData<cppu::WeakImplHelper<com::sun::star::io::XActiveDataControl, com::sun::star::io::XActiveDataSink>, com::sun::star::io::XActiveDataControl, com::sun::star::io::XActiveDataSink>::operator()()::s_cd>, that=0x387cbe0) at cppuhelper/source/implbase_ex.cxx:173
[...]
20 in utl::UcbStreamHelper::CreateStream(rtl::OUString const&, StreamMode) (rFileName="file://instdir/program/../share/gallery/sounds.thm", eOpenMode=StreamMode::READ) at unotools/source/ucbhelper/ucbstreamhelper.cxx:149
21 in GalleryTheme::CreateThemeEntry(INetURLObject const&, bool) (rURL=..., bReadOnly=false) at svx/source/gallery2/galtheme.cxx:692
22 in Gallery::ImplLoadSubDirs(INetURLObject const&, bool&) (this=0x38762c0, rBaseURL=..., rbDirIsReadOnly=@0x7ffca8bde7df: false) at svx/source/gallery2/gallery1.cxx:474
23 in Gallery::ImplLoad(rtl::OUString const&) (this=0x38762c0, rMultiPath="file://instdir/program/../share/gallery;file://workdir/UITest/writer_tests/user/user/gallery") at svx/source/gallery2/gallery1.cxx:301
24 in Gallery::Gallery(rtl::OUString const&) (this=0x38762c0, rMultiPath="file://instdir/program/../share/gallery;file://workdir/UITest/writer_tests/user/user/gallery") at svx/source/gallery2/gallery1.cxx:257
25 in Gallery::GetGalleryInstance() () at svx/source/gallery2/gallery1.cxx:273
26 in GalleryExplorer::BeginLocking(unsigned int) (nThemeId=3) at svx/source/gallery2/galexpl.cxx:264
27 in SvxBmpNumValueSet::init() (this=0x3873ed0) at svx/source/dialog/svxbmpnumvalueset.cxx:501

Thread #8 Grammar Checking:

2  in osl_acquireMutex(oslMutexImpl*) (pMutex=0x7ff329045420 <globalMutexImpl>) at sal/osl/unx/mutex.cxx:97
3  in osl::Mutex::acquire() (this=0x7ff32903b780 <osl_getGlobalMutex::globalMutex>) at include/osl/mutex.hxx:56
4  in osl::Guard<osl::Mutex>::Guard(osl::Mutex*) (this=0x7ff2f5b30030, pT_=0x7ff32903b780 <osl_getGlobalMutex::globalMutex>) at include/osl/mutex.hxx:122
5  in com::sun::star::container::cppu_detail_getUnoType(com::sun::star::container::XEnumeration const*) () at workdir/UnoApiHeadersTarget/udkapi/comprehensive/com/sun/star/container/XEnumeration.hpp:69
6  in cppu::UnoType<com::sun::star::container::XEnumeration>::get() () at include/cppu/unotype.hxx:296
7  in cppu::detail::cppu_detail_getUnoType<com::sun::star::container::XEnumeration>(com::sun::star::uno::Reference<com::sun::star::container::XEnumeration> const*) () at include/cppu/unotype.hxx:259
8  in cppu::UnoType<com::sun::star::uno::Reference<com::sun::star::container::XEnumeration> >::get() () at include/cppu/unotype.hxx:296
9  in com::sun::star::reflection::detail::theXTypeDescriptionEnumerationType::operator()() const (this=0x7ff2f5b30177) at workdir/UnoApiHeadersTarget/udkapi/comprehensive/com/sun/star/reflection/XTypeDescriptionEnumeration.hpp:30
10 in rtl::StaticWithInit<com::sun::star::uno::Type*, com::sun::star::reflection::detail::theXTypeDescriptionEnumerationType, com::sun::star::reflection::detail::theXTypeDescriptionEnumerationType, com::sun::star::uno::Type*>::get() () at include/rtl/instance.hxx:603
11 in com::sun::star::reflection::cppu_detail_getUnoType(com::sun::star::reflection::XTypeDescriptionEnumeration const*) () at workdir/UnoApiHeadersTarget/udkapi/comprehensive/com/sun/star/reflection/XTypeDescriptionEnumeration.hpp:57
12 in cppu::UnoType<com::sun::star::reflection::XTypeDescriptionEnumeration>::get() () at include/cppu/unotype.hxx:296
13 in com::sun::star::reflection::XTypeDescriptionEnumeration::static_type(void*) () at workdir/UnoApiHeadersTarget/udkapi/comprehensive/com/sun/star/reflection/XTypeDescriptionEnumeration.hpp:102
14 in cppu::getTypeEntries(cppu::class_data*) (cd=0x7ff3252b8ac0 <cppu::detail::ImplClassData<cppu::WeakImplHelper<com::sun::star::reflection::XTypeDescriptionEnumeration>, com::sun::star::reflection::XTypeDescriptionEnumeration>::operator()()::s_cd>) at cppuhelper/source/implbase_ex.cxx:96

Change-Id: I3aa3167ca8989b3d6be053e1c97f3b7a64bfbfb8
Reviewed-on: https://gerrit.libreoffice.org/49986Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMichael Stahl <mstahl@redhat.com>
üst c40ef4d1
......@@ -263,16 +263,10 @@ Gallery::~Gallery()
Gallery* Gallery::GetGalleryInstance()
{
static Gallery* s_pGallery = nullptr;
if (!s_pGallery)
{
::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
if (!s_pGallery && !utl::ConfigManager::IsFuzzing())
{
s_pGallery = new Gallery( SvtPathOptions().GetGalleryPath() );
}
}
// note: this would deadlock if it used osl::Mutex::getGlobalMutex()
static Gallery *const s_pGallery(
utl::ConfigManager::IsFuzzing() ? nullptr :
new Gallery(SvtPathOptions().GetGalleryPath()));
return s_pGallery;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment