From ae44d2affa524045735232c6e1b4f851bd4d48ad Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Wed, 9 Oct 2024 20:25:38 +0200 Subject: [PATCH] cid#1607338 Data race condition move this logic to the destructor, like we do elsewhere Change-Id: Ie41c78b0a01d79020cb77fd5be70116f473e910f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174747 Tested-by: Jenkins Reviewed-by: Noel Grandin --- sd/inc/stlsheet.hxx | 3 --- sd/source/core/stlsheet.cxx | 26 ++++---------------------- 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/sd/inc/stlsheet.hxx b/sd/inc/stlsheet.hxx index fc3db5d68cd2..aa7238e5b0e8 100644 --- a/sd/inc/stlsheet.hxx +++ b/sd/inc/stlsheet.hxx @@ -87,9 +87,6 @@ public: // SfxStyleSheetBase virtual bool SetName(const OUString& rNewName, bool bReindexNow = true) override; - // XInterface - virtual void SAL_CALL release( ) noexcept override; - // XServiceInfo virtual OUString SAL_CALL getImplementationName() override; virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; diff --git a/sd/source/core/stlsheet.cxx b/sd/source/core/stlsheet.cxx index 4c61c8d72b1c..1293e4740b9f 100644 --- a/sd/source/core/stlsheet.cxx +++ b/sd/source/core/stlsheet.cxx @@ -149,6 +149,10 @@ SdStyleSheet::SdStyleSheet(const OUString& rDisplayName, SfxStyleSheetBasePool& SdStyleSheet::~SdStyleSheet() { + // restore reference count, prevent double-delete from calling dispose + osl_atomic_increment( &m_refCount ); + dispose(); + delete pSet; pSet = nullptr; // that following destructors also get a change } @@ -727,28 +731,6 @@ rtl::Reference SdStyleSheet::CreateEmptyUserStyle( SfxStyleSheetBa return new SdStyleSheet(aName, rPool, eFamily, SfxStyleSearchBits::UserDefined); } -// XInterface - -void SAL_CALL SdStyleSheet::release( ) noexcept -{ - if (osl_atomic_decrement( &m_refCount ) != 0) - return; - - // restore reference count: - osl_atomic_increment( &m_refCount ); - if (! m_bDisposed) try - { - dispose(); - } - catch (RuntimeException const&) - { - // don't break throw () - TOOLS_WARN_EXCEPTION( "sd", "" ); - } - OSL_ASSERT( m_bDisposed ); - SdStyleSheetBase::release(); -} - // XComponent void SAL_CALL SdStyleSheet::dispose( )