From 3db4830c4137563f68c92aef4a31f2a39ac00748 Mon Sep 17 00:00:00 2001 From: Xisco Fauli Date: Mon, 6 Jun 2016 13:23:35 +0200 Subject: [PATCH] tdf#89329: use shared_ptr for pImpl in syslocale Change-Id: I646495e3538cb438a06765fe8cde252bad667bea Reviewed-on: https://gerrit.libreoffice.org/25969 Tested-by: Jenkins Reviewed-by: Noel Grandin --- include/unotools/syslocale.hxx | 3 +-- unotools/source/misc/syslocale.cxx | 16 +++++++--------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/include/unotools/syslocale.hxx b/include/unotools/syslocale.hxx index 037c6ed9a31e..58615770f8f0 100644 --- a/include/unotools/syslocale.hxx +++ b/include/unotools/syslocale.hxx @@ -45,8 +45,7 @@ class UNOTOOLS_DLLPUBLIC SvtSysLocale { friend class SvtSysLocale_Impl; // access to mutex - static SvtSysLocale_Impl* pImpl; - static sal_Int32 nRefCount; + std::shared_ptr pImpl; UNOTOOLS_DLLPRIVATE static ::osl::Mutex& GetMutex(); diff --git a/unotools/source/misc/syslocale.cxx b/unotools/source/misc/syslocale.cxx index e93e620a5049..b0cef62e7ee9 100644 --- a/unotools/source/misc/syslocale.cxx +++ b/unotools/source/misc/syslocale.cxx @@ -34,8 +34,7 @@ using namespace osl; using namespace com::sun::star; -SvtSysLocale_Impl* SvtSysLocale::pImpl = nullptr; -sal_Int32 SvtSysLocale::nRefCount = 0; +std::weak_ptr pSysLocale; class SvtSysLocale_Impl : public utl::ConfigurationListener { @@ -114,19 +113,18 @@ void SvtSysLocale_Impl::setDateAcceptancePatternsConfig() SvtSysLocale::SvtSysLocale() { MutexGuard aGuard( GetMutex() ); + pImpl = pSysLocale.lock(); if ( !pImpl ) - pImpl = new SvtSysLocale_Impl; - ++nRefCount; + { + pImpl = std::make_shared(); + pSysLocale = pImpl; + } } SvtSysLocale::~SvtSysLocale() { MutexGuard aGuard( GetMutex() ); - if ( !--nRefCount ) - { - delete pImpl; - pImpl = nullptr; - } + pImpl.reset(); } // static