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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Thu Dec 20 09:03:18 UTC 2018


 include/sfx2/bindings.hxx            |    2 +-
 sfx2/source/appl/shutdownicon.cxx    |    6 ++----
 sfx2/source/appl/xpackcreator.cxx    |   10 +++++-----
 sfx2/source/control/bindings.cxx     |    8 ++++----
 sfx2/source/control/dispatch.cxx     |    8 ++++----
 sfx2/source/dialog/backingwindow.cxx |    6 +++---
 sfx2/source/doc/docfile.cxx          |   16 +++++++---------
 sfx2/source/doc/sfxbasemodel.cxx     |    3 +--
 8 files changed, 27 insertions(+), 32 deletions(-)

New commits:
commit 146f98e7100ae57ced080c7d9fa028f01df99ca8
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Wed Dec 19 11:00:47 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Dec 20 10:02:54 2018 +0100

    use unique_ptr in sfx2
    
    Change-Id: I4e0bba9b8bebdeb9263ad71d3ab505d8beed17b7
    Reviewed-on: https://gerrit.libreoffice.org/65441
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/sfx2/bindings.hxx b/include/sfx2/bindings.hxx
index 38a41a25bcee..89663708cd82 100644
--- a/include/sfx2/bindings.hxx
+++ b/include/sfx2/bindings.hxx
@@ -99,7 +99,7 @@ private:
                                     SfxCallMode nCall, const SfxPoolItem **pInternalArgs, bool bGlobalOnly=false);
     SAL_DLLPRIVATE void SetSubBindings_Impl( SfxBindings* );
     SAL_DLLPRIVATE void UpdateSlotServer_Impl(); // Update SlotServer
-    SAL_DLLPRIVATE SfxItemSet* CreateSet_Impl(SfxStateCache& rCache, const SfxSlot* &pRealSlot,
+    SAL_DLLPRIVATE std::unique_ptr<SfxItemSet> CreateSet_Impl(SfxStateCache& rCache, const SfxSlot* &pRealSlot,
                                               const SfxSlotServer**, SfxFoundCacheArr_Impl&);
     SAL_DLLPRIVATE std::size_t GetSlotPos( sal_uInt16 nId, std::size_t nStartSearchAt = 0 );
     SAL_DLLPRIVATE void Update_Impl(SfxStateCache& rCache);
diff --git a/sfx2/source/appl/shutdownicon.cxx b/sfx2/source/appl/shutdownicon.cxx
index e917c3a91a0c..bc4c6ba5b8b2 100644
--- a/sfx2/source/appl/shutdownicon.cxx
+++ b/sfx2/source/appl/shutdownicon.cxx
@@ -493,13 +493,11 @@ ShutdownIcon* ShutdownIcon::createInstance()
     if (pShutdownIcon)
         return pShutdownIcon;
 
-    ShutdownIcon *pIcon = nullptr;
     try {
-        pIcon = new ShutdownIcon( comphelper::getProcessComponentContext() );
+        std::unique_ptr<ShutdownIcon> pIcon(new ShutdownIcon( comphelper::getProcessComponentContext() ));
         pIcon->init ();
-        pShutdownIcon = pIcon;
+        pShutdownIcon = pIcon.release();
     } catch (...) {
-        delete pIcon;
     }
 
     return pShutdownIcon;
diff --git a/sfx2/source/appl/xpackcreator.cxx b/sfx2/source/appl/xpackcreator.cxx
index f5b7f7edf289..0e0c559476bf 100644
--- a/sfx2/source/appl/xpackcreator.cxx
+++ b/sfx2/source/appl/xpackcreator.cxx
@@ -67,7 +67,7 @@ void SAL_CALL OPackageStructureCreator::convertToPackage( const OUString& aFolde
     ::ucbhelper::Content aContent;
     if( ::ucbhelper::Content::create( aFolderUrl, xComEnv, comphelper::getProcessComponentContext(), aContent ) )
     {
-        SvStream* pTempStream = nullptr;
+        std::unique_ptr<SvStream> pTempStream;
 
         OUString aTempURL = ::utl::TempFile().GetURL();
         try {
@@ -82,7 +82,7 @@ void SAL_CALL OPackageStructureCreator::convertToPackage( const OUString& aFolde
 
                 if ( !aTempURL.isEmpty() )
                 {
-                    pTempStream = new SvFileStream( aTempURL, StreamMode::STD_READWRITE );
+                    pTempStream.reset(new SvFileStream( aTempURL, StreamMode::STD_READWRITE ));
                     tools::SvRef<SotStorage> aTargetStorage = new SotStorage( true, *pTempStream );
                     aStorage->CopyTo( aTargetStorage.get() );
                     aTargetStorage->Commit();
@@ -116,7 +116,7 @@ void SAL_CALL OPackageStructureCreator::convertToPackage( const OUString& aFolde
         }
         catch (const uno::RuntimeException&)
         {
-            delete pTempStream;
+            pTempStream.reset();
 
             if ( !aTempURL.isEmpty() )
                 ::utl::UCBContentHelper::Kill( aTempURL );
@@ -125,7 +125,7 @@ void SAL_CALL OPackageStructureCreator::convertToPackage( const OUString& aFolde
         }
         catch (const io::IOException&)
         {
-            delete pTempStream;
+            pTempStream.reset();
 
             if ( !aTempURL.isEmpty() )
                 ::utl::UCBContentHelper::Kill( aTempURL );
@@ -136,7 +136,7 @@ void SAL_CALL OPackageStructureCreator::convertToPackage( const OUString& aFolde
         {
         }
 
-        delete pTempStream;
+        pTempStream.reset();
 
         if ( !aTempURL.isEmpty() )
             ::utl::UCBContentHelper::Kill( aTempURL );
diff --git a/sfx2/source/control/bindings.cxx b/sfx2/source/control/bindings.cxx
index c5f564444b74..e1803db01f56 100644
--- a/sfx2/source/control/bindings.cxx
+++ b/sfx2/source/control/bindings.cxx
@@ -259,7 +259,7 @@ void SfxBindings::Update_Impl(SfxStateCache& rCache /*The up to date SfxStatusCa
     const SfxSlot *pRealSlot = nullptr;
     const SfxSlotServer* pMsgServer = nullptr;
     SfxFoundCacheArr_Impl aFound;
-    SfxItemSet *pSet = CreateSet_Impl(rCache, pRealSlot, &pMsgServer, aFound);
+    std::unique_ptr<SfxItemSet> pSet = CreateSet_Impl(rCache, pRealSlot, &pMsgServer, aFound);
     bool bUpdated = false;
     if ( pSet )
     {
@@ -280,7 +280,7 @@ void SfxBindings::Update_Impl(SfxStateCache& rCache /*The up to date SfxStatusCa
             bUpdated = true;
         }
 
-        delete pSet;
+        pSet.reset();
     }
 
     if (!bUpdated)
@@ -1093,7 +1093,7 @@ void SfxBindings::UpdateSlotServer_Impl()
 }
 
 
-SfxItemSet* SfxBindings::CreateSet_Impl
+std::unique_ptr<SfxItemSet> SfxBindings::CreateSet_Impl
 (
     SfxStateCache&          rCache,     // in: Status-Cache from nId
     const SfxSlot*&         pRealSlot,  // out: RealSlot to nId
@@ -1182,7 +1182,7 @@ SfxItemSet* SfxBindings::CreateSet_Impl
         pRanges[j++] = rFound[i++].nWhichId;
     }
     pRanges[j] = 0; // terminating NULL
-    SfxItemSet *pSet = new SfxItemSet(rPool, pRanges.get());
+    std::unique_ptr<SfxItemSet> pSet(new SfxItemSet(rPool, pRanges.get()));
     pRanges.reset();
     return pSet;
 }
diff --git a/sfx2/source/control/dispatch.cxx b/sfx2/source/control/dispatch.cxx
index c0d8802954ec..52a625346cbc 100644
--- a/sfx2/source/control/dispatch.cxx
+++ b/sfx2/source/control/dispatch.cxx
@@ -939,16 +939,16 @@ const SfxPoolItem* SfxDispatcher::Execute(sal_uInt16 nSlot, SfxCallMode eCall,
     const SfxSlot *pSlot = nullptr;
     if ( GetShellAndSlot_Impl( nSlot,  &pShell, &pSlot, false, true ) )
     {
-        SfxRequest* pReq;
+        std::unique_ptr<SfxRequest> pReq;
         if ( pArgs && *pArgs )
         {
             SfxAllItemSet aSet( pShell->GetPool() );
             for ( const SfxPoolItem **pArg = pArgs; *pArg; ++pArg )
                 MappedPut_Impl( aSet, **pArg );
-            pReq = new SfxRequest( nSlot, eCall, aSet );
+            pReq.reset(new SfxRequest( nSlot, eCall, aSet ));
         }
         else
-            pReq =  new SfxRequest( nSlot, eCall, pShell->GetPool() );
+            pReq.reset(new SfxRequest( nSlot, eCall, pShell->GetPool() ));
         pReq->SetModifier( nModi );
         if( pInternalArgs && *pInternalArgs)
         {
@@ -959,7 +959,7 @@ const SfxPoolItem* SfxDispatcher::Execute(sal_uInt16 nSlot, SfxCallMode eCall,
         }
         Execute_( *pShell, *pSlot, *pReq, eCall );
         const SfxPoolItem* pRet = pReq->GetReturnValue();
-        delete pReq; return pRet;
+        return pRet;
     }
     return nullptr;
 }
diff --git a/sfx2/source/dialog/backingwindow.cxx b/sfx2/source/dialog/backingwindow.cxx
index c67ce9d6a7bd..664e609ca7fd 100644
--- a/sfx2/source/dialog/backingwindow.cxx
+++ b/sfx2/source/dialog/backingwindow.cxx
@@ -772,9 +772,9 @@ void BackingWindow::dispatchURL( const OUString& i_rURL,
         // dispatch the URL
         if ( xDispatch.is() )
         {
-            ImplDelayedDispatch* pDisp = new ImplDelayedDispatch( xDispatch, aDispatchURL, i_rArgs );
-            if( Application::PostUserEvent( Link<void*,void>( nullptr, implDispatchDelayed ), pDisp ) == nullptr )
-                delete pDisp; // event could not be posted for unknown reason, at least don't leak
+            std::unique_ptr<ImplDelayedDispatch> pDisp(new ImplDelayedDispatch( xDispatch, aDispatchURL, i_rArgs ));
+            if( Application::PostUserEvent( Link<void*,void>( nullptr, implDispatchDelayed ), pDisp.get() ) )
+                pDisp.release();
         }
     }
     catch (const css::uno::RuntimeException&)
diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx
index e6eefe86e6b6..535af7fcc17d 100644
--- a/sfx2/source/doc/docfile.cxx
+++ b/sfx2/source/doc/docfile.cxx
@@ -3172,10 +3172,10 @@ void SfxMedium::CompleteReOpen()
     bool bUseInteractionHandler = pImpl->bUseInteractionHandler;
     pImpl->bUseInteractionHandler = false;
 
-    ::utl::TempFile* pTmpFile = nullptr;
+    std::unique_ptr<::utl::TempFile> pTmpFile;
     if ( pImpl->pTempFile )
     {
-        pTmpFile = pImpl->pTempFile.release();
+        pTmpFile = std::move(pImpl->pTempFile);
         pImpl->m_aName.clear();
     }
 
@@ -3188,15 +3188,14 @@ void SfxMedium::CompleteReOpen()
             pImpl->pTempFile->EnableKillingFile();
             pImpl->pTempFile.reset();
         }
-        pImpl->pTempFile.reset( pTmpFile );
+        pImpl->pTempFile = std::move( pTmpFile );
         if ( pImpl->pTempFile )
             pImpl->m_aName = pImpl->pTempFile->GetFileName();
     }
     else if (pTmpFile)
     {
         pTmpFile->EnableKillingFile();
-        delete pTmpFile;
-
+        pTmpFile.reset();
     }
 
     pImpl->bUseInteractionHandler = bUseInteractionHandler;
@@ -3717,7 +3716,7 @@ void SfxMedium::CreateTempFile( bool bReplace )
             GetOutStream();
             if ( pImpl->m_pOutStream )
             {
-                char        *pBuf = new char [8192];
+                std::unique_ptr<char[]> pBuf(new char [8192]);
                 ErrCode      nErr = ERRCODE_NONE;
 
                 pImpl->m_pInStream->Seek(0);
@@ -3725,13 +3724,12 @@ void SfxMedium::CreateTempFile( bool bReplace )
 
                 while( !pImpl->m_pInStream->eof() && nErr == ERRCODE_NONE )
                 {
-                    sal_uInt32 nRead = pImpl->m_pInStream->ReadBytes(pBuf, 8192);
+                    sal_uInt32 nRead = pImpl->m_pInStream->ReadBytes(pBuf.get(), 8192);
                     nErr = pImpl->m_pInStream->GetError();
-                    pImpl->m_pOutStream->WriteBytes( pBuf, nRead );
+                    pImpl->m_pOutStream->WriteBytes( pBuf.get(), nRead );
                 }
 
                 bTransferSuccess = true;
-                delete[] pBuf;
                 CloseInStream();
             }
             CloseOutStream_Impl();
diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx
index 42dc41c53dc9..e7f49fdb4b32 100644
--- a/sfx2/source/doc/sfxbasemodel.cxx
+++ b/sfx2/source/doc/sfxbasemodel.cxx
@@ -1951,11 +1951,10 @@ Any SAL_CALL SfxBaseModel::getTransferData( const datatransfer::DataFlavor& aFla
                 utl::TempFile aTmp;
                 aTmp.EnableKillingFile();
                 storeToURL( aTmp.GetURL(), Sequence < beans::PropertyValue >() );
-                SvStream* pStream = aTmp.GetStream( StreamMode::READ );
+                std::unique_ptr<SvStream> pStream(aTmp.GetStream( StreamMode::READ ));
                 const sal_uInt32 nLen = pStream->TellEnd();
                 Sequence< sal_Int8 > aSeq( nLen );
                 pStream->ReadBytes(aSeq.getArray(), nLen);
-                delete pStream;
                 if( aSeq.getLength() )
                     aAny <<= aSeq;
             }


More information about the Libreoffice-commits mailing list