[Libreoffice-commits] core.git: sfx2/source

Noel Grandin noel.grandin at collabora.co.uk
Thu Feb 1 06:06:52 UTC 2018


 sfx2/source/appl/module.cxx     |   36 ++++++++++++++++--------------------
 sfx2/source/control/msgpool.cxx |    5 ++++-
 sfx2/source/control/objface.cxx |    6 +++++-
 3 files changed, 25 insertions(+), 22 deletions(-)

New commits:
commit a0c2d1be6a5ce1edb2e8b64a96d7d4d0d92f310c
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Tue Jan 16 15:43:05 2018 +0200

    loplugin:useuniqueptr in SfxModule_Impl
    
    Change-Id: I218cd34aefcf8bfbc8a52379fb1e15ec2ef3ac31
    Reviewed-on: https://gerrit.libreoffice.org/48700
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

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);
     }


More information about the Libreoffice-commits mailing list