[Libreoffice-commits] core.git: 2 commits - i18npool/qa sw/inc sw/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Sep 18 07:06:36 UTC 2018


 i18npool/qa/cppunit/test_textsearch.cxx  |    8 ++------
 sw/inc/docsh.hxx                         |    2 +-
 sw/source/core/unocore/unocrsrhelper.cxx |    7 ++-----
 sw/source/uibase/app/docsh.cxx           |   23 ++++++++++++-----------
 sw/source/uibase/uiview/view2.cxx        |    6 +++---
 5 files changed, 20 insertions(+), 26 deletions(-)

New commits:
commit 6131eee742a972c41b9017de455b8b8104bcaf32
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Fri Sep 14 14:38:55 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Tue Sep 18 09:06:23 2018 +0200

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

diff --git a/i18npool/qa/cppunit/test_textsearch.cxx b/i18npool/qa/cppunit/test_textsearch.cxx
index 18fd1d9079a6..012bbeb3eddd 100644
--- a/i18npool/qa/cppunit/test_textsearch.cxx
+++ b/i18npool/qa/cppunit/test_textsearch.cxx
@@ -60,14 +60,13 @@ private:
 void TestTextSearch::testICU()
 {
     UErrorCode nErr = U_ZERO_ERROR;
-    RegexMatcher* pRegexMatcher;
     sal_uInt32 nSearchFlags = UREGEX_UWORD | UREGEX_CASE_INSENSITIVE;
 
     OUString aString( "abcdefgh" );
     OUString aPattern( "e" );
     IcuUniString aSearchPat( reinterpret_cast<const UChar*>(aPattern.getStr()), aPattern.getLength() );
 
-    pRegexMatcher = new RegexMatcher( aSearchPat, nSearchFlags, nErr );
+    std::unique_ptr<RegexMatcher> pRegexMatcher(new RegexMatcher( aSearchPat, nSearchFlags, nErr ));
 
     IcuUniString aSource( reinterpret_cast<const UChar*>(aString.getStr()), aString.getLength() );
     pRegexMatcher->reset( aSource );
@@ -79,13 +78,11 @@ void TestTextSearch::testICU()
     CPPUNIT_ASSERT_EQUAL( static_cast<int32_t>(5), pRegexMatcher->end( nErr ) );
     CPPUNIT_ASSERT_EQUAL( U_ZERO_ERROR, nErr );
 
-    delete pRegexMatcher;
-
     OUString aString2( "acababaabcababadcdaa" );
     OUString aPattern2( "a" );
 
     IcuUniString aSearchPat2( reinterpret_cast<const UChar*>(aPattern2.getStr()), aPattern2.getLength() );
-    pRegexMatcher = new RegexMatcher( aSearchPat2, nSearchFlags, nErr );
+    pRegexMatcher.reset(new RegexMatcher( aSearchPat2, nSearchFlags, nErr ));
 
     IcuUniString aSource2( reinterpret_cast<const UChar*>(aString2.getStr()), aString2.getLength() );
     pRegexMatcher->reset( aSource2 );
@@ -96,7 +93,6 @@ void TestTextSearch::testICU()
     CPPUNIT_ASSERT_EQUAL( U_ZERO_ERROR, nErr );
     CPPUNIT_ASSERT_EQUAL( static_cast<int32_t>(1), pRegexMatcher->end( nErr ) );
     CPPUNIT_ASSERT_EQUAL( U_ZERO_ERROR, nErr );
-    delete pRegexMatcher;
 }
 
 void TestTextSearch::testSearches()
commit 32074859ba79489f1211542aca295a450443203e
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Fri Sep 14 14:38:42 2018 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Tue Sep 18 09:06:13 2018 +0200

    loplugin:useuniqueptr in SwDocShell::StartConvertFrom
    
    fixing a leak in SwView::InsertMedium
    
    Change-Id: I9abd97151b0fd7b3f6c286926e1a317ea47dc232
    Reviewed-on: https://gerrit.libreoffice.org/60606
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sw/inc/docsh.hxx b/sw/inc/docsh.hxx
index f2c17c1747c1..21344ca76cf7 100644
--- a/sw/inc/docsh.hxx
+++ b/sw/inc/docsh.hxx
@@ -231,7 +231,7 @@ public:
                 { return const_cast<SwDocShell*>(this)->GetFEShell(); }
 
     /// For inserting document.
-    Reader* StartConvertFrom(SfxMedium& rMedium, SwReader** ppRdr,
+    Reader* StartConvertFrom(SfxMedium& rMedium, std::unique_ptr<SwReader>& rpRdr,
                             SwCursorShell const * pCursorSh = nullptr, SwPaM* pPaM = nullptr);
 
 #if defined(_WIN32)
diff --git a/sw/source/core/unocore/unocrsrhelper.cxx b/sw/source/core/unocore/unocrsrhelper.cxx
index af5322b35d58..5e4d9d3af9fc 100644
--- a/sw/source/core/unocore/unocrsrhelper.cxx
+++ b/sw/source/core/unocore/unocrsrhelper.cxx
@@ -1061,12 +1061,12 @@ void InsertFile(SwUnoCursor* pUnoCursor, const OUString& rURL,
     pMed->Download();   // if necessary: start the download
     if( aRef.is() && 1 < aRef->GetRefCount() )  // Ref still valid?
     {
-        SwReader* pRdr;
+        std::unique_ptr<SwReader> pRdr;
         SfxItemSet* pSet =  pMed->GetItemSet();
         pSet->Put(SfxBoolItem(FN_API_CALL, true));
         if(!sPassword.isEmpty())
             pSet->Put(SfxStringItem(SID_PASSWORD, sPassword));
-        Reader *pRead = pDocSh->StartConvertFrom( *pMed, &pRdr, nullptr, pUnoCursor);
+        Reader *pRead = pDocSh->StartConvertFrom( *pMed, pRdr, nullptr, pUnoCursor);
         if( pRead )
         {
 
@@ -1091,9 +1091,6 @@ void InsertFile(SwUnoCursor* pUnoCursor, const OUString& rURL,
                     nContent = 0;
                 pUnoCursor->GetMark()->nContent.Assign( pCntNode, nContent );
             }
-
-            delete pRdr;
-
         }
     }
 }
diff --git a/sw/source/uibase/app/docsh.cxx b/sw/source/uibase/app/docsh.cxx
index ee1fa8228b4d..fd10b466dd54 100644
--- a/sw/source/uibase/app/docsh.cxx
+++ b/sw/source/uibase/app/docsh.cxx
@@ -153,17 +153,16 @@ bool SwDocShell::InsertGeneratedStream(SfxMedium & rMedium,
     if (!::sw::XTextRangeToSwPaM(aPam, xInsertPosition))
         return false;
     // similar to SwView::InsertMedium
-    SwReader *pReader(nullptr);
-    Reader *const pRead = StartConvertFrom(rMedium, &pReader, nullptr, &aPam);
+    std::unique_ptr<SwReader> pReader;
+    Reader *const pRead = StartConvertFrom(rMedium, pReader, nullptr, &aPam);
     if (!pRead)
         return false;
     ErrCode const nError = pReader->Read(*pRead);
-    delete pReader;
     return ERRCODE_NONE == nError;
 }
 
 // Prepare loading
-Reader* SwDocShell::StartConvertFrom(SfxMedium& rMedium, SwReader** ppRdr,
+Reader* SwDocShell::StartConvertFrom(SfxMedium& rMedium, std::unique_ptr<SwReader>& rpRdr,
                                     SwCursorShell const *pCursorShell,
                                     SwPaM* pPaM )
 {
@@ -195,10 +194,12 @@ Reader* SwDocShell::StartConvertFrom(SfxMedium& rMedium, SwReader** ppRdr,
         ? SwReaderType::Storage & pRead->GetReaderType()
         : SwReaderType::Stream & pRead->GetReaderType() )
     {
-        *ppRdr = pPaM ? new SwReader( rMedium, aFileName, *pPaM ) :
-            pCursorShell ?
-                new SwReader( rMedium, aFileName, *pCursorShell->GetCursor() )
-                    : new SwReader( rMedium, aFileName, m_xDoc.get() );
+        if (pPaM)
+            rpRdr.reset(new SwReader( rMedium, aFileName, *pPaM ));
+        else if (pCursorShell)
+            rpRdr.reset(new SwReader( rMedium, aFileName, *pCursorShell->GetCursor() ));
+        else
+            rpRdr.reset(new SwReader( rMedium, aFileName, m_xDoc.get() ));
     }
     else
         return nullptr;
@@ -230,8 +231,8 @@ Reader* SwDocShell::StartConvertFrom(SfxMedium& rMedium, SwReader** ppRdr,
 // Loading
 bool SwDocShell::ConvertFrom( SfxMedium& rMedium )
 {
-    SwReader* pRdr;
-    SwRead pRead = StartConvertFrom(rMedium, &pRdr);
+    std::unique_ptr<SwReader> pRdr;
+    SwRead pRead = StartConvertFrom(rMedium, pRdr);
     if (!pRead)
       return false; // #129881# return if no reader is found
     tools::SvRef<SotStorage> pStg=pRead->getSotStorageRef(); // #i45333# save sot storage ref in case of recursive calls
@@ -278,7 +279,7 @@ bool SwDocShell::ConvertFrom( SfxMedium& rMedium )
     UpdateFontList();
     InitDrawModelAndDocShell(this, m_xDoc ? m_xDoc->getIDocumentDrawModelAccess().GetDrawModel() : nullptr);
 
-    delete pRdr;
+    pRdr.reset();
 
     SW_MOD()->SetEmbeddedLoadSave( false );
 
diff --git a/sw/source/uibase/uiview/view2.cxx b/sw/source/uibase/uiview/view2.cxx
index 06e3e8cc6bf0..a5a4ec0d730e 100644
--- a/sw/source/uibase/uiview/view2.cxx
+++ b/sw/source/uibase/uiview/view2.cxx
@@ -2155,8 +2155,8 @@ long SwView::InsertMedium( sal_uInt16 nSlotId, std::unique_ptr<SfxMedium> pMediu
         pMedium->Download();    // start download if needed
         if( aRef.is() && 1 < aRef->GetRefCount() )  // still a valid ref?
         {
-            SwReader* pRdr;
-            Reader *pRead = pDocSh->StartConvertFrom(*pMedium, &pRdr, m_pWrtShell.get());
+            std::unique_ptr<SwReader> pRdr;
+            Reader *pRead = pDocSh->StartConvertFrom(*pMedium, pRdr, m_pWrtShell.get());
             if( pRead ||
                 (pMedium->GetFilter()->GetFilterFlags() & SfxFilterFlags::STARONEFILTER) )
             {
@@ -2174,7 +2174,7 @@ long SwView::InsertMedium( sal_uInt16 nSlotId, std::unique_ptr<SfxMedium> pMediu
                     if( pRead )
                     {
                         nErrno = pRdr->Read( *pRead );  // and insert document
-                        delete pRdr;
+                        pRdr.reset();
                     }
                     else
                     {


More information about the Libreoffice-commits mailing list