summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/unotools/defaultoptions.hxx2
-rw-r--r--unotools/source/config/defaultoptions.cxx25
2 files changed, 14 insertions, 13 deletions
diff --git a/include/unotools/defaultoptions.hxx b/include/unotools/defaultoptions.hxx
index f4937662d4c2..56761d28fbfa 100644
--- a/include/unotools/defaultoptions.hxx
+++ b/include/unotools/defaultoptions.hxx
@@ -30,7 +30,7 @@ class SvtDefaultOptions_Impl;
class SAL_WARN_UNUSED UNOTOOLS_DLLPUBLIC SvtDefaultOptions : public utl::detail::Options
{
private:
- std::unique_ptr<SvtDefaultOptions_Impl> pImpl;
+ std::shared_ptr<SvtDefaultOptions_Impl> pImpl;
public:
diff --git a/unotools/source/config/defaultoptions.cxx b/unotools/source/config/defaultoptions.cxx
index 6f021d4240c4..8a99dc5540fb 100644
--- a/unotools/source/config/defaultoptions.cxx
+++ b/unotools/source/config/defaultoptions.cxx
@@ -93,6 +93,7 @@ public:
OUString m_aUserDictionaryPath;
SvtDefaultOptions_Impl();
+ ~SvtDefaultOptions_Impl();
OUString GetDefaultPath( sal_uInt16 nId ) const;
virtual void Notify( const css::uno::Sequence<OUString>& aPropertyNames) override;
@@ -103,8 +104,7 @@ private:
// global ----------------------------------------------------------------
-static SvtDefaultOptions_Impl* pOptions = nullptr;
-static sal_Int32 nRefCount = 0;
+std::weak_ptr<SvtDefaultOptions_Impl> pOptions;
typedef OUString SvtDefaultOptions_Impl:: *PathStrPtr;
@@ -313,6 +313,12 @@ SvtDefaultOptions_Impl::SvtDefaultOptions_Impl() : ConfigItem( "Office.Common/Pa
}
}
+SvtDefaultOptions_Impl::~SvtDefaultOptions_Impl()
+{
+ if ( IsModified() )
+ Commit();
+}
+
// class SvtDefaultOptions -----------------------------------------------
namespace { struct lclMutex : public rtl::Static< ::osl::Mutex, lclMutex > {}; }
@@ -320,25 +326,20 @@ SvtDefaultOptions::SvtDefaultOptions()
{
// Global access, must be guarded (multithreading)
::osl::MutexGuard aGuard( lclMutex::get() );
- if ( !pOptions )
+ pImpl = pOptions.lock();
+ if ( !pImpl )
{
- pOptions = new SvtDefaultOptions_Impl;
+ pImpl = std::make_shared<SvtDefaultOptions_Impl>();
+ pOptions = pImpl;
ItemHolder1::holdConfigItem(E_DEFAULTOPTIONS);
}
- ++nRefCount;
- pImpl.reset(pOptions);
}
SvtDefaultOptions::~SvtDefaultOptions()
{
// Global access, must be guarded (multithreading)
::osl::MutexGuard aGuard( lclMutex::get() );
- if ( !--nRefCount )
- {
- if ( pOptions->IsModified() )
- pOptions->Commit();
- DELETEZ( pOptions );
- }
+ pImpl.reset();
}
OUString SvtDefaultOptions::GetDefaultPath( sal_uInt16 nId ) const