diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-05-20 10:08:30 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-05-20 10:47:35 +0200 |
commit | a25385e0d8027d7257ab95a4b787404dfca59913 (patch) | |
tree | 69c59dc0462e490d1afc0121ae955830befa1081 /xmloff | |
parent | a69cc693fee8581d1612e79be13e0234ad72cd6e (diff) |
simplify some XMLPropertyState memory management
which fixes a leak if some of the code throws an exception
Change-Id: Ic89060e7951060458ffe7ee5b6fe51cd076ef19b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115830
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'xmloff')
-rw-r--r-- | xmloff/source/text/txtflde.cxx | 2 | ||||
-rw-r--r-- | xmloff/source/text/txtparae.cxx | 26 |
2 files changed, 8 insertions, 20 deletions
diff --git a/xmloff/source/text/txtflde.cxx b/xmloff/source/text/txtflde.cxx index 111df2f0a7bf..962e30e995d4 100644 --- a/xmloff/source/text/txtflde.cxx +++ b/xmloff/source/text/txtflde.cxx @@ -896,7 +896,7 @@ void XMLTextFieldExport::ExportFieldAutoStyle( // export text style with the addition of the combined characters DBG_ASSERT(nullptr != pCombinedCharactersPropertyState, "need proper PropertyState for combined characters"); - const XMLPropertyState *aStates[] = { pCombinedCharactersPropertyState.get(), nullptr }; + o3tl::span<XMLPropertyState> aStates( pCombinedCharactersPropertyState.get(), 1 ); GetExport().GetTextParagraphExport()->Add( XmlStyleFamily::TEXT_TEXT, xRangePropSet, aStates); diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx index b5c5de5b9133..cd715f15e599 100644 --- a/xmloff/source/text/txtparae.cxx +++ b/xmloff/source/text/txtparae.cxx @@ -510,7 +510,7 @@ void FieldParamExporter::ExportParameter(const OUString& sKey, const OUString& s void XMLTextParagraphExport::Add( XmlStyleFamily nFamily, const Reference < XPropertySet > & rPropSet, - const XMLPropertyState** ppAddStates, bool bDontSeek ) + const o3tl::span<XMLPropertyState> aAddStates, bool bDontSeek ) { rtl::Reference < SvXMLExportPropertyMapper > xPropMapper; switch( nFamily ) @@ -537,14 +537,8 @@ void XMLTextParagraphExport::Add( XmlStyleFamily nFamily, vector< XMLPropertyState > aPropStates = xPropMapper->Filter(GetExport(), rPropSet); - if( ppAddStates ) - { - while( *ppAddStates ) - { - aPropStates.push_back( **ppAddStates ); - ppAddStates++; - } - } + for (const XMLPropertyState& rState : aAddStates) + aPropStates.push_back( rState ); if( aPropStates.empty() ) return; @@ -741,7 +735,7 @@ OUString XMLTextParagraphExport::Find( XmlStyleFamily nFamily, const Reference < XPropertySet > & rPropSet, const OUString& rParent, - const XMLPropertyState** ppAddStates) const + const o3tl::span<XMLPropertyState> aAddStates) const { OUString sName( rParent ); rtl::Reference < SvXMLExportPropertyMapper > xPropMapper; @@ -765,14 +759,8 @@ OUString XMLTextParagraphExport::Find( if( !xPropMapper.is() ) return sName; vector<XMLPropertyState> aPropStates(xPropMapper->Filter(GetExport(), rPropSet)); - if( ppAddStates ) - { - while( *ppAddStates ) - { - aPropStates.push_back( **ppAddStates ); - ++ppAddStates; - } - } + for (const XMLPropertyState& rState : aAddStates) + aPropStates.push_back( rState ); if( std::any_of( aPropStates.begin(), aPropStates.end(), lcl_validPropState ) ) sName = GetAutoStylePool().Find( nFamily, sName, aPropStates ); @@ -1438,7 +1426,7 @@ void XMLTextParagraphExport::collectTextAutoStylesOptimized( bool bIsProgress ) aAny = xAutoStylesEnum->nextElement(); Reference< XAutoStyle > xAutoStyle = *o3tl::doAccess<Reference<XAutoStyle>>(aAny); Reference < XPropertySet > xPSet( xAutoStyle, uno::UNO_QUERY ); - Add( nFamily, xPSet, nullptr, true ); + Add( nFamily, xPSet, {}, true ); } }; collectFamily("CharacterStyles", XmlStyleFamily::TEXT_TEXT); |