summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-01-16 15:43:05 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-02-01 07:06:28 +0100
commita0c2d1be6a5ce1edb2e8b64a96d7d4d0d92f310c (patch)
treeee7d2a37a34492bb8f2158b45108a7e943d34790
parentdad539c0ddeb7bd721c04450138ef2acb934809e (diff)
loplugin:useuniqueptr in SfxModule_Impl
Change-Id: I218cd34aefcf8bfbc8a52379fb1e15ec2ef3ac31 Reviewed-on: https://gerrit.libreoffice.org/48700 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--sfx2/source/appl/module.cxx36
-rw-r--r--sfx2/source/control/msgpool.cxx5
-rw-r--r--sfx2/source/control/objface.cxx6
3 files changed, 25 insertions, 22 deletions
diff --git a/sfx2/source/appl/module.cxx b/sfx2/source/appl/module.cxx
index 202a4391f5ad..38e9db653104 100644
--- a/sfx2/source/appl/module.cxx
+++ b/sfx2/source/appl/module.cxx
@@ -44,10 +44,10 @@ class SfxModule_Impl
{
public:
- SfxSlotPool* pSlotPool;
- SfxTbxCtrlFactArr_Impl* pTbxCtrlFac;
- SfxStbCtrlFactArr_Impl* pStbCtrlFac;
- SfxChildWinFactArr_Impl* pFactArr;
+ std::unique_ptr<SfxSlotPool> pSlotPool;
+ std::unique_ptr<SfxTbxCtrlFactArr_Impl> pTbxCtrlFac;
+ std::unique_ptr<SfxStbCtrlFactArr_Impl> pStbCtrlFac;
+ std::unique_ptr<SfxChildWinFactArr_Impl> pFactArr;
OString maResName;
SfxModule_Impl();
@@ -61,10 +61,10 @@ SfxModule_Impl::SfxModule_Impl()
SfxModule_Impl::~SfxModule_Impl()
{
- delete pSlotPool;
- delete pTbxCtrlFac;
- delete pStbCtrlFac;
- delete pFactArr;
+ pSlotPool.reset();
+ pTbxCtrlFac.reset();
+ pStbCtrlFac.reset();
+ pFactArr.reset();
}
SFX_IMPL_SUPERCLASS_INTERFACE(SfxModule, SfxShell)
@@ -84,11 +84,7 @@ void SfxModule::Construct_Impl(const OString& rResName)
{
SfxApplication *pApp = SfxApplication::GetOrCreate();
pImpl = new SfxModule_Impl;
- pImpl->pSlotPool = new SfxSlotPool(&pApp->GetAppSlotPool_Impl());
-
- pImpl->pTbxCtrlFac=nullptr;
- pImpl->pStbCtrlFac=nullptr;
- pImpl->pFactArr=nullptr;
+ pImpl->pSlotPool.reset( new SfxSlotPool(&pApp->GetAppSlotPool_Impl()) );
pImpl->maResName = rResName;
SetPool( &pApp->GetPool() );
@@ -110,7 +106,7 @@ std::locale SfxModule::GetResLocale() const
SfxSlotPool* SfxModule::GetSlotPool() const
{
- return pImpl->pSlotPool;
+ return pImpl->pSlotPool.get();
}
@@ -119,7 +115,7 @@ void SfxModule::RegisterChildWindow(SfxChildWinFactory *pFact)
DBG_ASSERT( pImpl, "No real Module!" );
if (!pImpl->pFactArr)
- pImpl->pFactArr = new SfxChildWinFactArr_Impl;
+ pImpl->pFactArr.reset( new SfxChildWinFactArr_Impl );
for (size_t nFactory=0; nFactory<pImpl->pFactArr->size(); ++nFactory)
{
@@ -138,7 +134,7 @@ void SfxModule::RegisterChildWindow(SfxChildWinFactory *pFact)
void SfxModule::RegisterToolBoxControl( const SfxTbxCtrlFactory& rFact )
{
if (!pImpl->pTbxCtrlFac)
- pImpl->pTbxCtrlFac = new SfxTbxCtrlFactArr_Impl;
+ pImpl->pTbxCtrlFac.reset( new SfxTbxCtrlFactArr_Impl );
#ifdef DBG_UTIL
for ( size_t n=0; n<pImpl->pTbxCtrlFac->size(); n++ )
@@ -159,7 +155,7 @@ void SfxModule::RegisterToolBoxControl( const SfxTbxCtrlFactory& rFact )
void SfxModule::RegisterStatusBarControl( const SfxStbCtrlFactory& rFact )
{
if (!pImpl->pStbCtrlFac)
- pImpl->pStbCtrlFac = new SfxStbCtrlFactArr_Impl;
+ pImpl->pStbCtrlFac.reset( new SfxStbCtrlFactArr_Impl );
#ifdef DBG_UTIL
for ( size_t n=0; n<pImpl->pStbCtrlFac->size(); n++ )
@@ -179,18 +175,18 @@ void SfxModule::RegisterStatusBarControl( const SfxStbCtrlFactory& rFact )
SfxTbxCtrlFactArr_Impl* SfxModule::GetTbxCtrlFactories_Impl() const
{
- return pImpl->pTbxCtrlFac;
+ return pImpl->pTbxCtrlFac.get();
}
SfxStbCtrlFactArr_Impl* SfxModule::GetStbCtrlFactories_Impl() const
{
- return pImpl->pStbCtrlFac;
+ return pImpl->pStbCtrlFac.get();
}
SfxChildWinFactArr_Impl* SfxModule::GetChildWinFactories_Impl() const
{
- return pImpl->pFactArr;
+ return pImpl->pFactArr.get();
}
VclPtr<SfxTabPage> SfxModule::CreateTabPage( sal_uInt16, vcl::Window*, const SfxItemSet& )
diff --git a/sfx2/source/control/msgpool.cxx b/sfx2/source/control/msgpool.cxx
index f9290e1ebc80..683c00ae98b4 100644
--- a/sfx2/source/control/msgpool.cxx
+++ b/sfx2/source/control/msgpool.cxx
@@ -44,7 +44,10 @@ SfxSlotPool::SfxSlotPool(SfxSlotPool *pParent)
SfxSlotPool::~SfxSlotPool()
{
_pParentPool = nullptr;
- for ( SfxInterface *pIF = FirstInterface(); pIF; pIF = FirstInterface() )
+ // swap out _vInterfaces because ~SfxInterface() might call ReleaseInterface()
+ std::vector<SfxInterface*> tmpInterfaces;
+ tmpInterfaces.swap(_vInterfaces);
+ for ( SfxInterface *pIF : tmpInterfaces )
delete pIF;
}
diff --git a/sfx2/source/control/objface.cxx b/sfx2/source/control/objface.cxx
index aa063e1fd07a..d6af5c21d0b7 100644
--- a/sfx2/source/control/objface.cxx
+++ b/sfx2/source/control/objface.cxx
@@ -201,7 +201,11 @@ SfxInterface::~SfxInterface()
if ( bRegistered )
{
if ( pMod )
- pMod->GetSlotPool()->ReleaseInterface(*this);
+ {
+ // can return nullptr if we are called from the SfxSlotPool destructor
+ if (pMod->GetSlotPool())
+ pMod->GetSlotPool()->ReleaseInterface(*this);
+ }
else
SfxGetpApp()->GetAppSlotPool_Impl().ReleaseInterface(*this);
}