diff options
author | Julien Nabet <serval2412@yahoo.fr> | 2017-12-27 19:08:51 +0100 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-12-28 08:56:24 +0100 |
commit | aa1bfa6d18e73265f486ed1f9673ac8f0a4e6de5 (patch) | |
tree | 0590ccbd0e76fc0f0de5bddaf9e10c902b95890d /cui | |
parent | 9bf5c139d1081a25dec990c5ca478a8b5d2f33a3 (diff) |
Use unique_ptr for m_aLeaves/m_aGroupedLeaves (cui)
and perhaps avoid memory leaks (see https://bugs.documentfoundation.org/show_bug.cgi?id=114457)
Change-Id: Ib413b0bf6cc65a2696e3429965a67899b7b72d73
Reviewed-on: https://gerrit.libreoffice.org/47094
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'cui')
-rw-r--r-- | cui/source/inc/treeopt.hxx | 14 | ||||
-rw-r--r-- | cui/source/options/treeopt.cxx | 24 |
2 files changed, 13 insertions, 25 deletions
diff --git a/cui/source/inc/treeopt.hxx b/cui/source/inc/treeopt.hxx index 274076d9d99f..3eadd58ef5d4 100644 --- a/cui/source/inc/treeopt.hxx +++ b/cui/source/inc/treeopt.hxx @@ -73,8 +73,6 @@ struct OptionsLeaf m_nGroupIndex( nGroupIndex ) {} }; -typedef std::vector< OptionsLeaf* > VectorOfLeaves; - // struct OptionsNode ---------------------------------------------------- struct OptionsNode @@ -83,8 +81,8 @@ struct OptionsNode OUString m_sLabel; OUString m_sPageURL; bool m_bAllModules; - VectorOfLeaves m_aLeaves; - std::vector< VectorOfLeaves > + std::vector< std::unique_ptr<OptionsLeaf> > m_aLeaves; + std::vector< std::vector< std::unique_ptr<OptionsLeaf> > > m_aGroupedLeaves; OptionsNode( const OUString& rId, @@ -95,14 +93,6 @@ struct OptionsNode m_sLabel( rLabel ), m_sPageURL( rPageURL ), m_bAllModules( bAllModules ) {} - - ~OptionsNode() - { - for ( size_t i = 0; i < m_aLeaves.size(); ++i ) - delete m_aLeaves[i]; - m_aLeaves.clear(); - m_aGroupedLeaves.clear(); - } }; typedef std::vector< OptionsNode* > VectorOfNodes; diff --git a/cui/source/options/treeopt.cxx b/cui/source/options/treeopt.cxx index 076a000d86b2..07be7d1a788c 100644 --- a/cui/source/options/treeopt.cxx +++ b/cui/source/options/treeopt.cxx @@ -1896,26 +1896,26 @@ VectorOfNodes OfaTreeOptionsDialog::LoadNodes( if ( rExtensionId.isEmpty() || sId == rExtensionId ) { - OptionsLeaf* pLeaf = new OptionsLeaf( - sLeafLabel, sLeafURL, sEventHdl, sLeafGrpId, nLeafGrpIdx ); + std::unique_ptr<OptionsLeaf> pLeaf(new OptionsLeaf( + sLeafLabel, sLeafURL, sEventHdl, sLeafGrpId, nLeafGrpIdx )); if ( !sLeafGrpId.isEmpty() ) { bool bAlreadyOpened = false; if ( pNode->m_aGroupedLeaves.size() > 0 ) { - for (std::vector<OptionsLeaf*> & rGroup : pNode->m_aGroupedLeaves) + for (auto & rGroup : pNode->m_aGroupedLeaves) { if ( rGroup.size() > 0 && rGroup[0]->m_sGroupId == sLeafGrpId ) { - std::vector<OptionsLeaf *>::size_type l = 0; + std::vector<std::unique_ptr<OptionsLeaf>>::size_type l = 0; for ( ; l < rGroup.size(); ++l ) { if ( rGroup[l]->m_nGroupIndex >= nLeafGrpIdx ) break; } - rGroup.insert( rGroup.begin() + l, pLeaf ); + rGroup.insert( rGroup.begin() + l, std::move(pLeaf) ); bAlreadyOpened = true; break; } @@ -1923,13 +1923,13 @@ VectorOfNodes OfaTreeOptionsDialog::LoadNodes( } if ( !bAlreadyOpened ) { - VectorOfLeaves aGroupedLeaves; - aGroupedLeaves.push_back( pLeaf ); - pNode->m_aGroupedLeaves.push_back( aGroupedLeaves ); + std::vector< std::unique_ptr<OptionsLeaf> > aGroupedLeaves; + aGroupedLeaves.push_back( std::move(pLeaf) ); + pNode->m_aGroupedLeaves.push_back( std::move(aGroupedLeaves) ); } } else - pNode->m_aLeaves.push_back( pLeaf ); + pNode->m_aLeaves.push_back( std::move(pLeaf) ); } } } @@ -2022,15 +2022,13 @@ void OfaTreeOptionsDialog::InsertNodes( const VectorOfNodes& rNodeList ) { for ( size_t k = 0; k < j.size(); ++k ) { - OptionsLeaf* pLeaf = j[k]; - lcl_insertLeaf( this, pNode, pLeaf, *pTreeLB ); + lcl_insertLeaf( this, pNode, j[k].get(), *pTreeLB ); } } for ( auto const & j: pNode->m_aLeaves ) { - OptionsLeaf* pLeaf = j; - lcl_insertLeaf( this, pNode, pLeaf, *pTreeLB ); + lcl_insertLeaf( this, pNode, j.get(), *pTreeLB ); } } } |