diff options
author | Caolán McNamara <caolanm@redhat.com> | 2017-12-10 11:10:10 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2017-12-10 16:26:07 +0100 |
commit | 4aa0600449b82a419ccd6ffd8d3061fbfea3d1c2 (patch) | |
tree | 9b48315cec8e0429730ca217351f2bc167781ff3 /sax | |
parent | 0ecd8c5fe38b039fb15227a21938884f633c0c78 (diff) |
ofz#4571 Direct-leak
Change-Id: I1fbeec6a29854dbc80736ed442941f55bc1bb0a3
Reviewed-on: https://gerrit.libreoffice.org/46179
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sax')
-rw-r--r-- | sax/source/expatwrap/sax_expat.cxx | 73 |
1 files changed, 33 insertions, 40 deletions
diff --git a/sax/source/expatwrap/sax_expat.cxx b/sax/source/expatwrap/sax_expat.cxx index 25e9c032878f..2c8466646c53 100644 --- a/sax/source/expatwrap/sax_expat.cxx +++ b/sax/source/expatwrap/sax_expat.cxx @@ -384,6 +384,28 @@ SaxExpatParser::initialize(css::uno::Sequence< css::uno::Any > const& rArguments } } +namespace +{ + class ParserCleanup + { + private: + SaxExpatParser_Impl& m_rParser; + Entity& m_rEntity; + public: + ParserCleanup(SaxExpatParser_Impl& rParser, Entity& rEntity) + : m_rParser(rParser) + , m_rEntity(rEntity) + { + } + ~ParserCleanup() + { + m_rParser.popEntity(); + //XML_ParserFree accepts a null arg + XML_ParserFree(m_rEntity.pParser); + } + }; +} + /*************** * * parseStream does Parser-startup initializations. The SaxExpatParser_Impl::parse() method does @@ -451,50 +473,21 @@ void SaxExpatParser::parseStream( const InputSource& structSource) m_pImpl->exception = SAXParseException(); m_pImpl->pushEntity( entity ); - try - { - // start the document - if( m_pImpl->rDocumentHandler.is() ) { - m_pImpl->rDocumentHandler->setDocumentLocator( m_pImpl->rDocumentLocator ); - m_pImpl->rDocumentHandler->startDocument(); - } - m_pImpl->parse(); + ParserCleanup aEnsureFree(*m_pImpl, entity); - // finish document - if( m_pImpl->rDocumentHandler.is() ) { - m_pImpl->rDocumentHandler->endDocument(); - } - } -// catch( SAXParseException &e ) -// { -// m_pImpl->popEntity(); -// XML_ParserFree( entity.pParser ); -// css::uno::Any aAny; -// aAny <<= e; -// throw SAXException( e.Message, e.Context, aAny ); -// } - catch( SAXException & ) - { - m_pImpl->popEntity(); - XML_ParserFree( entity.pParser ); - throw; - } - catch( IOException & ) - { - m_pImpl->popEntity(); - XML_ParserFree( entity.pParser ); - throw; - } - catch( css::uno::RuntimeException & ) - { - m_pImpl->popEntity(); - XML_ParserFree( entity.pParser ); - throw; + // start the document + if( m_pImpl->rDocumentHandler.is() ) { + m_pImpl->rDocumentHandler->setDocumentLocator( m_pImpl->rDocumentLocator ); + m_pImpl->rDocumentHandler->startDocument(); } - m_pImpl->popEntity(); - XML_ParserFree( entity.pParser ); + m_pImpl->parse(); + + // finish document + if( m_pImpl->rDocumentHandler.is() ) { + m_pImpl->rDocumentHandler->endDocument(); + } } void SaxExpatParser::setDocumentHandler(const css::uno::Reference< XDocumentHandler > & xHandler) |