diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2018-06-26 12:17:27 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2018-06-26 14:19:36 +0200 |
commit | f5e2dbb40cab1a21dc972806ee4038f52843e838 (patch) | |
tree | 9a31eebd39107bd4d84c262e786548ec831af392 /sax/source/expatwrap/sax_expat.cxx | |
parent | d8733e2c59f120acf9feddff04964becc3358621 (diff) |
Avoid potential double-delete in ~XMLFile2UTFConverter
...as the implicitly defined copy operations would just copy the m_p* member
pointers. Needed some modification of the ParserCleanup class so that Entity
(which has a XMLFile2UTFConverter member) can be std::move'd into
SaxExpatParser_Impl::pushEntity.
Found by new -Wdeprecated-copy of GCC trunk towards GCC 9.
Change-Id: I0cb5b5dbcd55249b475ed74b4ac6bcb12f20f2c6
Reviewed-on: https://gerrit.libreoffice.org/56453
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'sax/source/expatwrap/sax_expat.cxx')
-rw-r--r-- | sax/source/expatwrap/sax_expat.cxx | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/sax/source/expatwrap/sax_expat.cxx b/sax/source/expatwrap/sax_expat.cxx index 49f9471b7b03..b7e76d4eb207 100644 --- a/sax/source/expatwrap/sax_expat.cxx +++ b/sax/source/expatwrap/sax_expat.cxx @@ -20,6 +20,7 @@ #include <string.h> #include <cassert> #include <memory> +#include <utility> #include <vector> @@ -159,8 +160,8 @@ public: // module scope // External entity stack vector<struct Entity> vecEntity; - void pushEntity( const struct Entity &entity ) - { vecEntity.push_back( entity ); } + void pushEntity( Entity &&entity ) + { vecEntity.push_back( std::move(entity) ); } void popEntity() { vecEntity.pop_back( ); } struct Entity &getEntity() @@ -388,18 +389,18 @@ class ParserCleanup { private: SaxExpatParser_Impl& m_rParser; - Entity& m_rEntity; + XML_Parser m_xmlParser; public: - ParserCleanup(SaxExpatParser_Impl& rParser, Entity& rEntity) + ParserCleanup(SaxExpatParser_Impl& rParser, XML_Parser xmlParser) : m_rParser(rParser) - , m_rEntity(rEntity) + , m_xmlParser(xmlParser) { } ~ParserCleanup() { m_rParser.popEntity(); //XML_ParserFree accepts a null arg - XML_ParserFree(m_rEntity.pParser); + XML_ParserFree(m_xmlParser); } }; @@ -469,9 +470,10 @@ void SaxExpatParser::parseStream( const InputSource& structSource) m_pImpl->exception = SAXParseException(); - m_pImpl->pushEntity( entity ); + auto const xmlParser = entity.pParser; + m_pImpl->pushEntity( std::move(entity) ); - ParserCleanup aEnsureFree(*m_pImpl, entity); + ParserCleanup aEnsureFree(*m_pImpl, xmlParser); // start the document if( m_pImpl->rDocumentHandler.is() ) { @@ -847,7 +849,8 @@ bool SaxExpatParser_Impl::callbackExternalEntityRef( } entity.converter.setInputStream( entity.structSource.aInputStream ); - pImpl->pushEntity( entity ); + auto const xmlParser = entity.pParser; + pImpl->pushEntity( std::move(entity) ); try { pImpl->parse(); @@ -870,7 +873,7 @@ bool SaxExpatParser_Impl::callbackExternalEntityRef( pImpl->popEntity(); - XML_ParserFree( entity.pParser ); + XML_ParserFree( xmlParser ); } return bOK; |