[Libreoffice-commits] core.git: Branch 'libreoffice-5-4' - sax/source
Caolán McNamara
caolanm at redhat.com
Sun Jan 7 20:43:01 UTC 2018
sax/source/fastparser/fastparser.cxx | 154 +++++++++++++++++------------------
1 file changed, 76 insertions(+), 78 deletions(-)
New commits:
commit 19110ae6255dd17d2dbbff82f44c55c266273c64
Author: Caolán McNamara <caolanm at redhat.com>
Date: Wed Nov 29 21:18:11 2017 +0000
ofz: always free with xmlFreeParserCtxt
Reviewed-on: https://gerrit.libreoffice.org/45533
Reviewed-by: Caolán McNamara <caolanm at redhat.com>
Tested-by: Caolán McNamara <caolanm at redhat.com>
(cherry picked from commit 5591aa360874c9133d046eeaa1c315df1a441bc4)
Change-Id: I90aed11ae0a29a0e9fc725b297e10a7ed30c9942
Reviewed-on: https://gerrit.libreoffice.org/47541
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
diff --git a/sax/source/fastparser/fastparser.cxx b/sax/source/fastparser/fastparser.cxx
index eb15b19e94be..bbe7748b149a 100644
--- a/sax/source/fastparser/fastparser.cxx
+++ b/sax/source/fastparser/fastparser.cxx
@@ -735,6 +735,27 @@ sal_Int32 FastSaxParserImpl::GetTokenWithContextNamespace( sal_Int32 nNamespaceT
return FastToken::DONTKNOW;
}
+namespace
+{
+ class ParserCleanup
+ {
+ private:
+ FastSaxParserImpl& m_rParser;
+ Entity& m_rEntity;
+ public:
+ ParserCleanup(FastSaxParserImpl& rParser, Entity& rEntity)
+ : m_rParser(rParser)
+ , m_rEntity(rEntity)
+ {
+ }
+ ~ParserCleanup()
+ {
+ //xmlFreeParserCtxt accepts a null arg
+ xmlFreeParserCtxt(m_rEntity.mpParser);
+ m_rParser.popEntity();
+ }
+ };
+}
/***************
*
* parseStream does Parser-startup initializations. The FastSaxParser::parse() method does
@@ -760,103 +781,80 @@ void FastSaxParserImpl::parseStream(const InputSource& maStructSource)
pushEntity( entity );
Entity& rEntity = getEntity();
- try
+ ParserCleanup aEnsureFree(*this, rEntity);
+
+ // start the document
+ if( rEntity.mxDocumentHandler.is() )
{
- // start the document
- if( rEntity.mxDocumentHandler.is() )
- {
- Reference< XLocator > xLoc( mxDocumentLocator.get() );
- rEntity.mxDocumentHandler->setDocumentLocator( xLoc );
- rEntity.mxDocumentHandler->startDocument();
- }
+ Reference< XLocator > xLoc( mxDocumentLocator.get() );
+ rEntity.mxDocumentHandler->setDocumentLocator( xLoc );
+ rEntity.mxDocumentHandler->startDocument();
+ }
- rEntity.mbEnableThreads = (rEntity.maStructSource.aInputStream->available() > 10000);
+ rEntity.mbEnableThreads = (rEntity.maStructSource.aInputStream->available() > 10000);
- if (rEntity.mbEnableThreads)
- {
- rtl::Reference<ParserThread> xParser;
- xParser = new ParserThread(this);
- xParser->launch();
- bool done = false;
- do {
- rEntity.maConsumeResume.wait();
- rEntity.maConsumeResume.reset();
-
- osl::ResettableMutexGuard aGuard(rEntity.maEventProtector);
- while (!rEntity.maPendingEvents.empty())
- {
- if (rEntity.maPendingEvents.size() <= Entity::mnEventLowWater)
- rEntity.maProduceResume.set(); // start producer again
+ if (rEntity.mbEnableThreads)
+ {
+ rtl::Reference<ParserThread> xParser;
+ xParser = new ParserThread(this);
+ xParser->launch();
+ bool done = false;
+ do {
+ rEntity.maConsumeResume.wait();
+ rEntity.maConsumeResume.reset();
+
+ osl::ResettableMutexGuard aGuard(rEntity.maEventProtector);
+ while (!rEntity.maPendingEvents.empty())
+ {
+ if (rEntity.maPendingEvents.size() <= Entity::mnEventLowWater)
+ rEntity.maProduceResume.set(); // start producer again
- EventList *pEventList = rEntity.maPendingEvents.front();
- rEntity.maPendingEvents.pop();
- aGuard.clear(); // unlock
+ EventList *pEventList = rEntity.maPendingEvents.front();
+ rEntity.maPendingEvents.pop();
+ aGuard.clear(); // unlock
- if (!consume(pEventList))
- done = true;
+ if (!consume(pEventList))
+ done = true;
- aGuard.reset(); // lock
+ aGuard.reset(); // lock
- if ( rEntity.maPendingEvents.size() <= Entity::mnEventLowWater )
+ if ( rEntity.maPendingEvents.size() <= Entity::mnEventLowWater )
+ {
+ aGuard.clear();
+ for (auto aEventIt = pEventList->maEvents.begin();
+ aEventIt != pEventList->maEvents.end(); ++aEventIt)
{
- aGuard.clear();
- for (auto aEventIt = pEventList->maEvents.begin();
- aEventIt != pEventList->maEvents.end(); ++aEventIt)
+ if (aEventIt->mxAttributes.is())
{
- if (aEventIt->mxAttributes.is())
- {
- aEventIt->mxAttributes->clear();
- if( rEntity.mxNamespaceHandler.is() )
- aEventIt->mxDeclAttributes->clear();
- }
- pEventList->mbIsAttributesEmpty = true;
+ aEventIt->mxAttributes->clear();
+ if( rEntity.mxNamespaceHandler.is() )
+ aEventIt->mxDeclAttributes->clear();
}
- aGuard.reset();
+ pEventList->mbIsAttributesEmpty = true;
}
-
- rEntity.maUsedEvents.push(pEventList);
+ aGuard.reset();
}
- } while (!done);
- xParser->join();
- deleteUsedEvents();
- // callbacks used inside XML_Parse may have caught an exception
- if( rEntity.maSavedException.hasValue() )
- rEntity.throwException( mxDocumentLocator, true );
- }
- else
- {
- parse();
- }
+ rEntity.maUsedEvents.push(pEventList);
+ }
+ } while (!done);
+ xParser->join();
+ deleteUsedEvents();
- // finish document
- if( rEntity.mxDocumentHandler.is() )
- {
- rEntity.mxDocumentHandler->endDocument();
- }
- }
- catch (const SAXException&)
- {
- // TODO free mpParser.myDoc ?
- xmlFreeParserCtxt( rEntity.mpParser );
- popEntity();
- throw;
+ // callbacks used inside XML_Parse may have caught an exception
+ if( rEntity.maSavedException.hasValue() )
+ rEntity.throwException( mxDocumentLocator, true );
}
- catch (const IOException&)
+ else
{
- xmlFreeParserCtxt( rEntity.mpParser );
- popEntity();
- throw;
+ parse();
}
- catch (const RuntimeException&)
+
+ // finish document
+ if( rEntity.mxDocumentHandler.is() )
{
- xmlFreeParserCtxt( rEntity.mpParser );
- popEntity();
- throw;
+ rEntity.mxDocumentHandler->endDocument();
}
-
- xmlFreeParserCtxt( rEntity.mpParser );
- popEntity();
}
void FastSaxParserImpl::setFastDocumentHandler( const Reference< XFastDocumentHandler >& Handler )
More information about the Libreoffice-commits
mailing list