Kaydet (Commit) aa1bfa6d authored tarafından Julien Nabet's avatar Julien Nabet Kaydeden (comit) Noel Grandin

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/47094Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 9bf5c139
......@@ -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;
......
......@@ -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 );
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment