diff options
author | Xisco Fauli <xiscofauli@libreoffice.org> | 2024-11-12 11:59:41 +0100 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2024-11-13 09:29:02 +0100 |
commit | 07ba469a350052eee905e908080f98f11517af66 (patch) | |
tree | aed1f95bdcb556e1b82609e22c620db044058a88 /sc | |
parent | 6595fcacfa9afb5f09465785aa0c4af46e972ef0 (diff) |
tdf#163486: PVS: pointer not released in destructor
V773 The 'pDefaults' pointer was not released in destructor. A memory leak is possible.
Change-Id: I7df195d1f515b86e85993d6c0a6cf60bcaff3109
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176477
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/editutil.hxx | 3 | ||||
-rw-r--r-- | sc/source/core/tool/editutil.cxx | 26 |
2 files changed, 7 insertions, 22 deletions
diff --git a/sc/inc/editutil.hxx b/sc/inc/editutil.hxx index d05363c0b2b4..247f1cc783ae 100644 --- a/sc/inc/editutil.hxx +++ b/sc/inc/editutil.hxx @@ -109,9 +109,8 @@ class ScEnginePoolHelper { protected: rtl::Reference<SfxItemPool> m_pEnginePool; - SfxItemSet* m_pDefaults; + std::unique_ptr<SfxItemSet> m_pDefaults; bool m_bDeleteEnginePool; - bool m_bDeleteDefaults; ScEnginePoolHelper( SfxItemPool* pEnginePool, bool bDeleteEnginePool ); ScEnginePoolHelper( const ScEnginePoolHelper& rOrg ); diff --git a/sc/source/core/tool/editutil.cxx b/sc/source/core/tool/editutil.cxx index 29166d8583f3..3c3dac0ee4e9 100644 --- a/sc/source/core/tool/editutil.cxx +++ b/sc/source/core/tool/editutil.cxx @@ -523,25 +523,19 @@ ScEnginePoolHelper::ScEnginePoolHelper( SfxItemPool* pEnginePoolP, bool bDeleteEnginePoolP ) : m_pEnginePool( pEnginePoolP ), - m_pDefaults( nullptr ), - m_bDeleteEnginePool( bDeleteEnginePoolP ), - m_bDeleteDefaults( false ) + m_bDeleteEnginePool( bDeleteEnginePoolP ) { } ScEnginePoolHelper::ScEnginePoolHelper( const ScEnginePoolHelper& rOrg ) : m_pEnginePool( rOrg.m_bDeleteEnginePool ? rOrg.m_pEnginePool->Clone() : rOrg.m_pEnginePool ), - m_pDefaults( nullptr ), - m_bDeleteEnginePool( rOrg.m_bDeleteEnginePool ), - m_bDeleteDefaults( false ) + m_bDeleteEnginePool( rOrg.m_bDeleteEnginePool ) { } ScEnginePoolHelper::~ScEnginePoolHelper() { - if ( m_bDeleteDefaults ) - delete m_pDefaults; } ScEditEngineDefaulter::ScEditEngineDefaulter( SfxItemPool* pEnginePoolP, @@ -572,10 +566,7 @@ void ScEditEngineDefaulter::SetDefaults( const SfxItemSet& rSet, bool bRememberC { if ( bRememberCopy ) { - if ( m_bDeleteDefaults ) - delete m_pDefaults; - m_pDefaults = new SfxItemSet( rSet ); - m_bDeleteDefaults = true; + m_pDefaults = std::make_unique<SfxItemSet>( rSet ); } const SfxItemSet& rNewSet = bRememberCopy ? *m_pDefaults : rSet; bool bUndo = IsUndoEnabled(); @@ -594,10 +585,7 @@ void ScEditEngineDefaulter::SetDefaults( const SfxItemSet& rSet, bool bRememberC void ScEditEngineDefaulter::SetDefaults( std::unique_ptr<SfxItemSet> pSet ) { - if ( m_bDeleteDefaults ) - delete m_pDefaults; - m_pDefaults = pSet.release(); - m_bDeleteDefaults = true; + m_pDefaults = std::move(pSet); if ( m_pDefaults ) SetDefaults( *m_pDefaults, false ); } @@ -606,8 +594,7 @@ void ScEditEngineDefaulter::SetDefaultItem( const SfxPoolItem& rItem ) { if ( !m_pDefaults ) { - m_pDefaults = new SfxItemSet( GetEmptyItemSet() ); - m_bDeleteDefaults = true; + m_pDefaults = std::make_unique<SfxItemSet>( GetEmptyItemSet() ); } m_pDefaults->Put( rItem ); SetDefaults( *m_pDefaults, false ); @@ -617,8 +604,7 @@ const SfxItemSet& ScEditEngineDefaulter::GetDefaults() { if ( !m_pDefaults ) { - m_pDefaults = new SfxItemSet( GetEmptyItemSet() ); - m_bDeleteDefaults = true; + m_pDefaults = std::make_unique<SfxItemSet>( GetEmptyItemSet() ); } return *m_pDefaults; } |