summaryrefslogtreecommitdiff
path: root/sax
diff options
context:
space:
mode:
authordante <dante19031999@gmail.com>2020-12-18 03:25:21 +0100
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-12-19 16:09:18 +0100
commitf460d8e8178cc6fad02347e2bab6580efe51c260 (patch)
treeda819d20f0af2e4b1be3d473634b4b05524be1f5 /sax
parenta37f29983f3fee58bde40967667ebae84a6c7537 (diff)
Proposition for solution for memory error in 106804
https://gerrit.libreoffice.org/c/core/+/106804 This needs to be merged in the 7.1, it corrects a memory leak introduced in this same version. Change-Id: Id3c3f86f88c32e631f0c414fbd7942aba2a91239 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107930 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sax')
-rw-r--r--sax/source/fastparser/fastparser.cxx29
1 files changed, 19 insertions, 10 deletions
diff --git a/sax/source/fastparser/fastparser.cxx b/sax/source/fastparser/fastparser.cxx
index 94d2651d4dff..f2a1ef3f2a92 100644
--- a/sax/source/fastparser/fastparser.cxx
+++ b/sax/source/fastparser/fastparser.cxx
@@ -227,6 +227,7 @@ public:
private:
std::vector<ReplacementPair> m_Replacements;
+ std::vector<xmlEntityPtr> m_TemporalEntities;
public:
// XFastParser
@@ -673,6 +674,8 @@ FastSaxParserImpl::~FastSaxParserImpl()
{
if( mxDocumentLocator.is() )
mxDocumentLocator->dispose();
+ for ( size_t i = 0; i < m_TemporalEntities.size(); ++i )
+ if (m_TemporalEntities[i] != nullptr) xmlFree(m_TemporalEntities[i]);
}
void FastSaxParserImpl::DefineNamespace( const OString& rPrefix, const OUString& namespaceURL )
@@ -1398,9 +1401,13 @@ xmlEntityPtr FastSaxParserImpl::callbackGetEntity( const xmlChar *name )
{
auto it = std::lower_bound(m_Replacements.begin(), m_Replacements.end(), dname);
if (it != m_Replacements.end() && it->name.compareToAscii(dname) == 0)
- return xmlNewEntity(
+ {
+ xmlEntityPtr entpt = xmlNewEntity(
nullptr, name, XML_INTERNAL_GENERAL_ENTITY, nullptr, nullptr,
BAD_CAST(OUStringToOString(it->replacement, RTL_TEXTENCODING_UTF8).getStr()));
+ m_TemporalEntities.push_back(entpt);
+ return entpt;
+ }
}
if( lname < 2 )
return xmlGetPredefinedEntity(name);
@@ -1415,21 +1422,23 @@ xmlEntityPtr FastSaxParserImpl::callbackGetEntity( const xmlChar *name )
if( cval == 0 )
return xmlGetPredefinedEntity(name);
OUString vname( &cval, 1 );
- return xmlNewEntity( nullptr,
- name,
- XML_INTERNAL_GENERAL_ENTITY, nullptr, nullptr,
- BAD_CAST(OUStringToOString(vname,RTL_TEXTENCODING_UTF8).getStr()));
+ xmlEntityPtr entpt
+ = xmlNewEntity(nullptr, name, XML_INTERNAL_GENERAL_ENTITY, nullptr, nullptr,
+ BAD_CAST(OUStringToOString(vname, RTL_TEXTENCODING_UTF8).getStr()));
+ m_TemporalEntities.push_back(entpt);
+ return entpt;
}
else
{
cval = static_cast<sal_uInt32>( strtoul( dname + 2, nullptr, 10 ) );
if( cval == 0 )
return xmlGetPredefinedEntity(name);
- OUString vname( &cval, 1 );
- return xmlNewEntity( nullptr,
- name,
- XML_INTERNAL_GENERAL_ENTITY, nullptr, nullptr,
- BAD_CAST(OUStringToOString(vname,RTL_TEXTENCODING_UTF8).getStr()));
+ OUString vname(&cval, 1);
+ xmlEntityPtr entpt
+ = xmlNewEntity(nullptr, name, XML_INTERNAL_GENERAL_ENTITY, nullptr, nullptr,
+ BAD_CAST(OUStringToOString(vname, RTL_TEXTENCODING_UTF8).getStr()));
+ m_TemporalEntities.push_back(entpt);
+ return entpt;
}
}
return xmlGetPredefinedEntity(name);