[Libreoffice-commits] core.git: 6 commits - bridges/source helpcompiler/inc helpcompiler/source include/svl svl/qa svl/source tools/source UnoControls/source

Noel Grandin noel.grandin at collabora.co.uk
Mon Apr 16 06:23:53 UTC 2018


 UnoControls/source/base/basecontainercontrol.cxx |    2 -
 UnoControls/source/controls/progressmonitor.cxx  |   38 +++++++++--------------
 UnoControls/source/inc/progressmonitor.hxx       |    5 +--
 bridges/source/jni_uno/jni_info.cxx              |   14 ++++----
 bridges/source/jni_uno/jni_info.h                |    4 +-
 helpcompiler/inc/HelpCompiler.hxx                |   14 ++++----
 helpcompiler/source/HelpCompiler.cxx             |    6 +--
 helpcompiler/source/HelpLinker.cxx               |    6 +--
 include/svl/itempool.hxx                         |    2 -
 svl/qa/unit/items/test_itempool.cxx              |    2 -
 svl/source/fsstor/fsstorage.cxx                  |    3 -
 svl/source/fsstor/fsstorage.hxx                  |    2 -
 svl/source/inc/poolio.hxx                        |   10 +-----
 svl/source/items/itempool.cxx                    |   24 +++++++-------
 svl/source/items/itemset.cxx                     |    2 -
 svl/source/items/poolio.cxx                      |    2 -
 tools/source/stream/stream.cxx                   |    7 +++-
 17 files changed, 66 insertions(+), 77 deletions(-)

New commits:
commit be408facea08a28c83b2de6c0587235a6949e704
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Fri Apr 13 09:37:35 2018 +0200

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

diff --git a/svl/source/fsstor/fsstorage.cxx b/svl/source/fsstor/fsstorage.cxx
index c899bfe357c4..c1350f86270a 100644
--- a/svl/source/fsstor/fsstorage.cxx
+++ b/svl/source/fsstor/fsstorage.cxx
@@ -1035,8 +1035,7 @@ void SAL_CALL FSStorage::dispose()
         m_pImpl->m_pListenersContainer->disposeAndClear( aSource );
     }
 
-    delete m_pImpl;
-    m_pImpl = nullptr;
+    m_pImpl.reset();
 }
 
 void SAL_CALL FSStorage::addEventListener(
diff --git a/svl/source/fsstor/fsstorage.hxx b/svl/source/fsstor/fsstorage.hxx
index a3ba6b2ffc65..18574f2b7205 100644
--- a/svl/source/fsstor/fsstorage.hxx
+++ b/svl/source/fsstor/fsstorage.hxx
@@ -43,7 +43,7 @@ class FSStorage : public css::lang::XTypeProvider
                 , public ::cppu::OWeakObject
 {
     ::osl::Mutex m_aMutex;
-    FSStorage_Impl* m_pImpl;
+    std::unique_ptr<FSStorage_Impl> m_pImpl;
 
 protected:
 
commit 23ae341869ddb0d1af81ee7a5705b776817afd4c
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Thu Apr 12 15:40:33 2018 +0200

    assert that we own the data before freeing it
    
    Change-Id: I9676da22c00570cd59f2f46b04beb5f1337bbacf
    Reviewed-on: https://gerrit.libreoffice.org/52887
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/tools/source/stream/stream.cxx b/tools/source/stream/stream.cxx
index 5d6d3e58336b..b48275819739 100644
--- a/tools/source/stream/stream.cxx
+++ b/tools/source/stream/stream.cxx
@@ -1866,7 +1866,12 @@ bool SvMemoryStream::ReAllocateMemory( long nDiff )
 
 void SvMemoryStream::FreeMemory()
 {
-    delete[] pBuf;
+    assert(bOwnsData);
+    if (bOwnsData)
+    {
+        delete[] pBuf;
+        pBuf = nullptr;
+    }
 }
 
 void* SvMemoryStream::SwitchBuffer()
commit 3d44b720f58366398e7f59c00dba6339712a670f
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Thu Apr 12 15:40:12 2018 +0200

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

diff --git a/include/svl/itempool.hxx b/include/svl/itempool.hxx
index f4f5d86f3a08..29f736f44ca1 100644
--- a/include/svl/itempool.hxx
+++ b/include/svl/itempool.hxx
@@ -77,7 +77,7 @@ private:
 
 public:
     // for default SfxItemSet::CTOR, set default WhichRanges
-    void                            FillItemIdRanges_Impl( sal_uInt16*& pWhichRanges ) const;
+    void                            FillItemIdRanges_Impl( std::unique_ptr<sal_uInt16[]>& pWhichRanges ) const;
     const sal_uInt16*               GetFrozenIdRanges() const;
 
 protected:
diff --git a/svl/qa/unit/items/test_itempool.cxx b/svl/qa/unit/items/test_itempool.cxx
index a3132be80b0a..cde5dee62f2c 100644
--- a/svl/qa/unit/items/test_itempool.cxx
+++ b/svl/qa/unit/items/test_itempool.cxx
@@ -80,7 +80,7 @@ void PoolItemTest::testPool()
     }
 
     // Test rehash
-    for (SfxPoolItemArray_Impl *pSlice : pImpl->maPoolItems)
+    for (auto & pSlice : pImpl->maPoolItems)
     {
         if (pSlice)
             pSlice->ReHash();
diff --git a/svl/source/inc/poolio.hxx b/svl/source/inc/poolio.hxx
index 538c89994603..359b88c863dd 100644
--- a/svl/source/inc/poolio.hxx
+++ b/svl/source/inc/poolio.hxx
@@ -71,14 +71,14 @@ public:
 struct SfxItemPool_Impl
 {
     SfxBroadcaster                  aBC;
-    std::vector<SfxPoolItemArray_Impl*> maPoolItems;
+    std::vector<std::unique_ptr<SfxPoolItemArray_Impl>> maPoolItems;
     std::vector<SfxItemPoolUser*>   maSfxItemPoolUsers; /// ObjectUser section
     OUString                        aName;
     std::vector<SfxPoolItem*>       maPoolDefaults;
     std::vector<SfxPoolItem*>*      mpStaticDefaults;
     SfxItemPool*                    mpMaster;
     SfxItemPool*                    mpSecondary;
-    sal_uInt16*                     mpPoolRanges;
+    std::unique_ptr<sal_uInt16[]>   mpPoolRanges;
     sal_uInt16                      mnStart;
     sal_uInt16                      mnEnd;
     MapUnit                         eDefMetric;
@@ -105,13 +105,9 @@ struct SfxItemPool_Impl
 
     void DeleteItems()
     {
-        for (auto pPoolItemArray : maPoolItems)
-            delete pPoolItemArray;
         maPoolItems.clear();
         maPoolDefaults.clear();
-
-        delete[] mpPoolRanges;
-        mpPoolRanges = nullptr;
+        mpPoolRanges.reset();
     }
 
     // unit testing
diff --git a/svl/source/items/itempool.cxx b/svl/source/items/itempool.cxx
index 07eab0ab3435..76e9d90b485f 100644
--- a/svl/source/items/itempool.cxx
+++ b/svl/source/items/itempool.cxx
@@ -620,11 +620,11 @@ const SfxPoolItem& SfxItemPool::Put( const SfxPoolItem& rItem, sal_uInt16 nWhich
             typeid(rItem) == typeid(GetDefaultItem(nWhich)));
 
     const sal_uInt16 nIndex = GetIndex_Impl(nWhich);
-    SfxPoolItemArray_Impl* pItemArr = pImpl->maPoolItems[nIndex];
+    SfxPoolItemArray_Impl* pItemArr = pImpl->maPoolItems[nIndex].get();
     if (!pItemArr)
     {
-        pImpl->maPoolItems[nIndex] = new SfxPoolItemArray_Impl;
-        pItemArr = pImpl->maPoolItems[nIndex];
+        pImpl->maPoolItems[nIndex].reset(new SfxPoolItemArray_Impl);
+        pItemArr = pImpl->maPoolItems[nIndex].get();
     }
 
     std::vector<SfxPoolItem*>::iterator ppFree;
@@ -753,7 +753,7 @@ void SfxItemPool::Remove( const SfxPoolItem& rItem )
         return;
 
     // Find Item in own Pool
-    SfxPoolItemArray_Impl* pItemArr = pImpl->maPoolItems[nIndex];
+    SfxPoolItemArray_Impl* pItemArr = pImpl->maPoolItems[nIndex].get();
     assert(pItemArr && "removing Item not in Pool");
 
     SfxPoolItemArray_Impl::PoolItemPtrToIndexMap::const_iterator it;
@@ -826,7 +826,7 @@ void SfxItemPool::FreezeIdRanges()
 }
 
 
-void SfxItemPool::FillItemIdRanges_Impl( sal_uInt16*& pWhichRanges ) const
+void SfxItemPool::FillItemIdRanges_Impl( std::unique_ptr<sal_uInt16[]>& pWhichRanges ) const
 {
     DBG_ASSERT( !pImpl->mpPoolRanges, "GetFrozenRanges() would be faster!" );
 
@@ -835,20 +835,20 @@ void SfxItemPool::FillItemIdRanges_Impl( sal_uInt16*& pWhichRanges ) const
     for( pPool = this; pPool; pPool = pPool->pImpl->mpSecondary )
         ++nLevel;
 
-    pWhichRanges = new sal_uInt16[ 2*nLevel + 1 ];
+    pWhichRanges.reset(new sal_uInt16[ 2*nLevel + 1 ]);
 
     nLevel = 0;
     for( pPool = this; pPool; pPool = pPool->pImpl->mpSecondary )
     {
-        *(pWhichRanges+(nLevel++)) = pPool->pImpl->mnStart;
-        *(pWhichRanges+(nLevel++)) = pPool->pImpl->mnEnd;
-        *(pWhichRanges+nLevel) = 0;
+        pWhichRanges[nLevel++] = pPool->pImpl->mnStart;
+        pWhichRanges[nLevel++] = pPool->pImpl->mnEnd;
+        pWhichRanges[nLevel] = 0;
     }
 }
 
 const sal_uInt16* SfxItemPool::GetFrozenIdRanges() const
 {
-    return pImpl->mpPoolRanges;
+    return pImpl->mpPoolRanges.get();
 }
 
 const SfxPoolItem *SfxItemPool::GetItem2Default(sal_uInt16 nWhich) const
@@ -870,7 +870,7 @@ const SfxPoolItem *SfxItemPool::GetItem2(sal_uInt16 nWhich, sal_uInt32 nOfst) co
     if ( nOfst == SFX_ITEMS_DEFAULT )
         return (*pImpl->mpStaticDefaults)[ GetIndex_Impl(nWhich) ];
 
-    SfxPoolItemArray_Impl* pItemArr = pImpl->maPoolItems[GetIndex_Impl(nWhich)];
+    SfxPoolItemArray_Impl* pItemArr = pImpl->maPoolItems[GetIndex_Impl(nWhich)].get();
     if( pItemArr && nOfst < pItemArr->size() )
         return (*pItemArr)[nOfst];
 
@@ -887,7 +887,7 @@ sal_uInt32 SfxItemPool::GetItemCount2(sal_uInt16 nWhich) const
         return 0;
     }
 
-    SfxPoolItemArray_Impl* pItemArr = pImpl->maPoolItems[GetIndex_Impl(nWhich)];
+    SfxPoolItemArray_Impl* pItemArr = pImpl->maPoolItems[GetIndex_Impl(nWhich)].get();
     if  ( pItemArr )
         return pItemArr->size();
     return 0;
diff --git a/svl/source/items/itemset.cxx b/svl/source/items/itemset.cxx
index 784e23a33e22..e967089e17ee 100644
--- a/svl/source/items/itemset.cxx
+++ b/svl/source/items/itemset.cxx
@@ -94,8 +94,6 @@ SfxItemSet::SfxItemSet(SfxItemPool& rPool)
 {
     m_pWhichRanges = const_cast<sal_uInt16*>(m_pPool->GetFrozenIdRanges());
     assert( m_pWhichRanges && "don't create ItemSets with full range before FreezeIdRanges()" );
-    if (!m_pWhichRanges)
-        m_pPool->FillItemIdRanges_Impl( m_pWhichRanges );
 
     const sal_uInt16 nSize = TotalCount();
     m_pItems.reset(new const SfxPoolItem*[nSize]{});
diff --git a/svl/source/items/poolio.cxx b/svl/source/items/poolio.cxx
index 4d73a8af581f..c73e85c2b0ac 100644
--- a/svl/source/items/poolio.cxx
+++ b/svl/source/items/poolio.cxx
@@ -104,7 +104,7 @@ bool SfxItemPool::CheckItemInPool(const SfxPoolItem *pItem) const
     if( IsStaticDefaultItem(pItem) || IsPoolDefaultItem(pItem) )
         return true;
 
-    SfxPoolItemArray_Impl* pItemArr = pImpl->maPoolItems[GetIndex_Impl(pItem->Which())];
+    SfxPoolItemArray_Impl* pItemArr = pImpl->maPoolItems[GetIndex_Impl(pItem->Which())].get();
     DBG_ASSERT(pItemArr, "ItemArr is not available");
 
     for ( size_t i = 0; i < pItemArr->size(); ++i )
commit 73c29a2978f967d317235d524aad535a6bafbff0
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Thu Apr 12 15:39:54 2018 +0200

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

diff --git a/helpcompiler/inc/HelpCompiler.hxx b/helpcompiler/inc/HelpCompiler.hxx
index 952e58acc987..e063bd61f1a7 100644
--- a/helpcompiler/inc/HelpCompiler.hxx
+++ b/helpcompiler/inc/HelpCompiler.hxx
@@ -165,19 +165,19 @@ public:
     std::string document_module;
     std::string document_title;
 
-    HashSet *appl_hidlist;
-    Hashtable *appl_keywords;
-    Stringtable *appl_helptexts;
+    std::unique_ptr<HashSet> appl_hidlist;
+    std::unique_ptr<Hashtable> appl_keywords;
+    std::unique_ptr<Stringtable> appl_helptexts;
     xmlDocPtr appl_doc;
 
     StreamTable() :
-        appl_hidlist(nullptr), appl_keywords(nullptr), appl_helptexts(nullptr), appl_doc(nullptr)
+        appl_doc(nullptr)
     {}
     void dropappl()
     {
-        delete appl_hidlist;
-        delete appl_keywords;
-        delete appl_helptexts;
+        appl_hidlist.reset();
+        appl_keywords.reset();
+        appl_helptexts.reset();
         if (appl_doc) xmlFreeDoc(appl_doc);
     }
     ~StreamTable()
diff --git a/helpcompiler/source/HelpCompiler.cxx b/helpcompiler/source/HelpCompiler.cxx
index cc8c319e58a5..2c56ecafc628 100644
--- a/helpcompiler/source/HelpCompiler.cxx
+++ b/helpcompiler/source/HelpCompiler.cxx
@@ -476,9 +476,9 @@ bool HelpCompiler::compile()
 
     streamTable.dropappl();
     streamTable.appl_doc = docResolvedDoc;
-    streamTable.appl_hidlist = aparser.hidlist.release();
-    streamTable.appl_helptexts = aparser.helptexts.release();
-    streamTable.appl_keywords = aparser.keywords.release();
+    streamTable.appl_hidlist = std::move(aparser.hidlist);
+    streamTable.appl_helptexts = std::move(aparser.helptexts);
+    streamTable.appl_keywords = std::move(aparser.keywords);
 
     streamTable.document_id = documentId;
     streamTable.document_path = fileName;
diff --git a/helpcompiler/source/HelpLinker.cxx b/helpcompiler/source/HelpLinker.cxx
index 315ce57035ca..b146349200b7 100644
--- a/helpcompiler/source/HelpLinker.cxx
+++ b/helpcompiler/source/HelpLinker.cxx
@@ -383,7 +383,7 @@ void HelpLinker::link()
             // add once this as its own id.
             addBookmark( pFileDbBase_DBHelp, documentPath, fileB, std::string(), jarfileB, titleB);
 
-            const HashSet *hidlist = streamTable.appl_hidlist;
+            const HashSet *hidlist = streamTable.appl_hidlist.get();
             if (hidlist && !hidlist->empty())
             {
                 // now iterate over all elements of the hidlist
@@ -403,7 +403,7 @@ void HelpLinker::link()
             }
 
             // now the keywords
-            const Hashtable *anchorToLL = streamTable.appl_keywords;
+            const Hashtable *anchorToLL = streamTable.appl_keywords.get();
             if (anchorToLL && !anchorToLL->empty())
             {
                 std::string fakedHid = URLEncoder::encode(documentPath);
@@ -424,7 +424,7 @@ void HelpLinker::link()
             }
 
             // and last the helptexts
-            const Stringtable *helpTextHash = streamTable.appl_helptexts;
+            const Stringtable *helpTextHash = streamTable.appl_helptexts.get();
             if (helpTextHash && !helpTextHash->empty())
             {
                 for (auto const& elem : *helpTextHash)
commit 2e0cf814671e99a1d1a902a5828768c620c4674c
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Thu Apr 12 15:39:25 2018 +0200

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

diff --git a/UnoControls/source/base/basecontainercontrol.cxx b/UnoControls/source/base/basecontainercontrol.cxx
index 499bf34e6bd9..cbc476731078 100644
--- a/UnoControls/source/base/basecontainercontrol.cxx
+++ b/UnoControls/source/base/basecontainercontrol.cxx
@@ -167,8 +167,6 @@ void SAL_CALL BaseContainerControl::dispose()
     // remove controls
     Sequence< Reference< XControl > >   seqCtrls    =   getControls();
 
-    for ( auto & i : maControlInfoList )
-        delete i;
     maControlInfoList.clear();
 
     for ( Reference< XControl > const & control : seqCtrls )
diff --git a/UnoControls/source/controls/progressmonitor.cxx b/UnoControls/source/controls/progressmonitor.cxx
index 4d513ee26b2f..b43afd5d6e73 100644
--- a/UnoControls/source/controls/progressmonitor.cxx
+++ b/UnoControls/source/controls/progressmonitor.cxx
@@ -197,7 +197,7 @@ void SAL_CALL ProgressMonitor::addText(
     }
 
     // Else ... take memory for new item ...
-    IMPL_TextlistItem*  pTextItem = new IMPL_TextlistItem;
+    std::unique_ptr<IMPL_TextlistItem> pTextItem(new IMPL_TextlistItem);
 
     // Set values ...
     pTextItem->sTopic   = rTopic;
@@ -209,11 +209,11 @@ void SAL_CALL ProgressMonitor::addText(
     // ... and insert it in right list.
     if ( bbeforeProgress )
     {
-        maTextlist_Top.push_back( pTextItem );
+        maTextlist_Top.push_back( std::move(pTextItem) );
     }
     else
     {
-        maTextlist_Bottom.push_back( pTextItem );
+        maTextlist_Bottom.push_back( std::move(pTextItem) );
     }
 
     // ... update window
@@ -239,15 +239,17 @@ void SAL_CALL ProgressMonitor::removeText ( const OUString& rTopic, sal_Bool bbe
         // ... delete item from right list ...
         if ( bbeforeProgress )
         {
-            vector< IMPL_TextlistItem* >::iterator
-                itr = find( maTextlist_Top.begin(), maTextlist_Top.end(), pSearchItem );
+            auto itr = std::find_if( maTextlist_Top.begin(), maTextlist_Top.end(),
+                            [&] (std::unique_ptr<IMPL_TextlistItem> const &p)
+                            { return p.get() == pSearchItem; } );
             if (itr != maTextlist_Top.end())
                 maTextlist_Top.erase(itr);
         }
         else
         {
-            vector< IMPL_TextlistItem* >::iterator
-                itr = find( maTextlist_Bottom.begin(), maTextlist_Bottom.end(), pSearchItem );
+            auto itr = std::find_if( maTextlist_Bottom.begin(), maTextlist_Bottom.end(),
+                            [&] (std::unique_ptr<IMPL_TextlistItem> const &p)
+                            { return p.get() == pSearchItem; } );
             if (itr != maTextlist_Bottom.end())
                 maTextlist_Bottom.erase(itr);
         }
@@ -723,7 +725,7 @@ void ProgressMonitor::impl_rebuildFixedText ()
 
         // Collect all topics from list and format text.
         // "\n" MUST BE at the end of line!!! => Else ... topic and his text are not in the same line!!!
-        for (IMPL_TextlistItem* pSearchItem : maTextlist_Top)
+        for (auto const & pSearchItem : maTextlist_Top)
         {
             aCollectString  +=  pSearchItem->sTopic + "\n";
         }
@@ -738,7 +740,7 @@ void ProgressMonitor::impl_rebuildFixedText ()
 
         // Collect all topics from list and format text.
         // "\n" MUST BE at the end of line!!! => Else ... topic and his text are not in the same line!!!
-        for (IMPL_TextlistItem* pSearchItem : maTextlist_Top)
+        for (auto const & pSearchItem : maTextlist_Top)
         {
             aCollectString  +=  pSearchItem->sText + "\n";
         }
@@ -755,7 +757,7 @@ void ProgressMonitor::impl_rebuildFixedText ()
 
         // Collect all topics from list and format text.
         // "\n" MUST BE at the end of line!!! => Else ... topic and his text are not in the same line!!!
-        for (IMPL_TextlistItem* pSearchItem : maTextlist_Bottom)
+        for (auto const & pSearchItem : maTextlist_Bottom)
         {
             aCollectString  +=  pSearchItem->sTopic + "\n";
         }
@@ -770,7 +772,7 @@ void ProgressMonitor::impl_rebuildFixedText ()
 
         // Collect all topics from list and format text.
         // "\n" MUST BE at the end of line!!! => Else ... topic and his text are not in the same line!!!
-        for (IMPL_TextlistItem* pSearchItem : maTextlist_Bottom)
+        for (auto const & pSearchItem : maTextlist_Bottom)
         {
             aCollectString  +=  pSearchItem->sText + "\n";
         }
@@ -786,17 +788,7 @@ void ProgressMonitor::impl_cleanMemory ()
     MutexGuard aGuard ( m_aMutex );
 
     // Delete all of lists.
-
-    for (IMPL_TextlistItem* pSearchItem : maTextlist_Top)
-    {
-        delete pSearchItem;
-    }
     maTextlist_Top.clear();
-
-    for (IMPL_TextlistItem* pSearchItem : maTextlist_Bottom)
-    {
-        delete pSearchItem;
-    }
     maTextlist_Bottom.clear();
 }
 
@@ -804,7 +796,7 @@ void ProgressMonitor::impl_cleanMemory ()
 IMPL_TextlistItem* ProgressMonitor::impl_searchTopic ( const OUString& rTopic, bool bbeforeProgress )
 {
     // Get right textlist for following operations.
-    ::std::vector< IMPL_TextlistItem* >* pTextList;
+    ::std::vector< std::unique_ptr<IMPL_TextlistItem> >* pTextList;
 
     // Ready for multithreading
     ClearableMutexGuard aGuard ( m_aMutex );
@@ -827,7 +819,7 @@ IMPL_TextlistItem* ProgressMonitor::impl_searchTopic ( const OUString& rTopic, b
 
     for ( nPosition = 0; nPosition < nCount; ++nPosition )
     {
-        IMPL_TextlistItem* pSearchItem = pTextList->at( nPosition );
+        auto pSearchItem = pTextList->at( nPosition ).get();
 
         if ( pSearchItem->sTopic == rTopic )
         {
diff --git a/UnoControls/source/inc/progressmonitor.hxx b/UnoControls/source/inc/progressmonitor.hxx
index 5ab211eaa0ef..e31cdab1de1c 100644
--- a/UnoControls/source/inc/progressmonitor.hxx
+++ b/UnoControls/source/inc/progressmonitor.hxx
@@ -60,6 +60,7 @@
 #include <rtl/ref.hxx>
 
 #include <vector>
+#include <memory>
 
 #include <basecontainercontrol.hxx>
 
@@ -276,11 +277,11 @@ private:
 // private variables
 
 private:
-    ::std::vector < IMPL_TextlistItem* >          maTextlist_Top;         // Elements before progress
+    ::std::vector < std::unique_ptr<IMPL_TextlistItem> > maTextlist_Top;         // Elements before progress
     css::uno::Reference< css::awt::XFixedText >   m_xTopic_Top;   // (used, if parameter "beforeProgress"=true in "addText, updateText, removeText")
     css::uno::Reference< css::awt::XFixedText >   m_xText_Top;
 
-    ::std::vector < IMPL_TextlistItem* >          maTextlist_Bottom;      // Elements below of progress
+    ::std::vector < std::unique_ptr<IMPL_TextlistItem> > maTextlist_Bottom;      // Elements below of progress
     css::uno::Reference< css::awt::XFixedText >   m_xTopic_Bottom;   // (used, if parameter "beforeProgress"=false in "addText, updateText, removeText")
     css::uno::Reference< css::awt::XFixedText >   m_xText_Bottom;
 
commit 2d2906da813362d83bc6a7d7093eefcc9566dbb1
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Thu Apr 12 15:08:22 2018 +0200

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

diff --git a/bridges/source/jni_uno/jni_info.cxx b/bridges/source/jni_uno/jni_info.cxx
index 82b773d6d58c..9b43356856af 100644
--- a/bridges/source/jni_uno/jni_info.cxx
+++ b/bridges/source/jni_uno/jni_info.cxx
@@ -61,7 +61,7 @@ void JNI_interface_type_info::destroy( JNIEnv * jni_env )
     JNI_type_info::destruct( jni_env );
     jni_env->DeleteGlobalRef( m_proxy_ctor );
     jni_env->DeleteGlobalRef( m_type );
-    delete [] m_methods;
+    m_methods.reset();
     delete this;
 }
 
@@ -104,7 +104,7 @@ JNI_interface_type_info::JNI_interface_type_info(
                 reinterpret_cast< typelib_InterfaceTypeDescription * >(
                     m_td.get() );
             // coverity [ctor_dtor_leak]
-            m_methods = new jmethodID[ td->nMapFunctionIndexToMemberIndex ];
+            m_methods.reset(new jmethodID[ td->nMapFunctionIndexToMemberIndex ]);
             sal_Int32 nMethodIndex = 0;
             typelib_TypeDescriptionReference ** ppMembers = td->ppMembers;
             sal_Int32 nMembers = td->nMembers;
@@ -211,7 +211,7 @@ JNI_interface_type_info::JNI_interface_type_info(
         }
         catch (...)
         {
-            delete [] m_methods;
+            m_methods.reset();
             throw;
         }
     }
@@ -224,7 +224,7 @@ JNI_interface_type_info::JNI_interface_type_info(
 void JNI_compound_type_info::destroy( JNIEnv * jni_env )
 {
     JNI_type_info::destruct( jni_env );
-    delete [] m_fields;
+    m_fields.reset();
     delete this;
 }
 
@@ -289,7 +289,7 @@ JNI_compound_type_info::JNI_compound_type_info(
                 jni_info->m_RuntimeException_type.getTypeLibType() ))
         {
             // coverity [ctor_dtor_leak]
-            m_fields = new jfieldID[ 2 ];
+            m_fields.reset(new jfieldID[ 2 ]);
             m_fields[ 0 ] = nullptr; // special Throwable.getMessage()
             // field Context
             m_fields[ 1 ] = jni->GetFieldID(
@@ -301,7 +301,7 @@ JNI_compound_type_info::JNI_compound_type_info(
         {
             // retrieve field ids for all direct members
             sal_Int32 nMembers = td->nMembers;
-            m_fields = new jfieldID[ nMembers ];
+            m_fields.reset(new jfieldID[ nMembers ]);
 
             for ( sal_Int32 nPos = 0; nPos < nMembers; ++nPos )
             {
@@ -334,7 +334,7 @@ JNI_compound_type_info::JNI_compound_type_info(
     }
     catch (...)
     {
-        delete [] m_fields;
+        m_fields.reset();
         throw;
     }
 
diff --git a/bridges/source/jni_uno/jni_info.h b/bridges/source/jni_uno/jni_info.h
index 920e78453afe..98ba7c9e505a 100644
--- a/bridges/source/jni_uno/jni_info.h
+++ b/bridges/source/jni_uno/jni_info.h
@@ -82,7 +82,7 @@ struct JNI_interface_type_info : public JNI_type_info
     jobject                                     m_proxy_ctor; // proxy ctor
     jobject                                     m_type;
     // sorted via typelib function index
-    jmethodID *                                 m_methods;
+    std::unique_ptr<jmethodID[]>                m_methods;
 
     virtual void destroy( JNIEnv * jni_env ) override;
     explicit JNI_interface_type_info(
@@ -98,7 +98,7 @@ struct JNI_compound_type_info : public JNI_type_info
     // ctor( msg ) for exceptions
     jmethodID                                   m_exc_ctor;
     // sorted via typelib member index
-    jfieldID *                                  m_fields;
+    std::unique_ptr<jfieldID[]>                 m_fields;
 
     virtual void destroy( JNIEnv * jni_env ) override;
     explicit JNI_compound_type_info(


More information about the Libreoffice-commits mailing list