[Libreoffice-commits] core.git: sax/source

Kohei Yoshida kohei.yoshida at collabora.com
Wed Dec 3 16:52:54 PST 2014


 sax/source/fastparser/fastparser.cxx |   22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

New commits:
commit a09a709594dd0f6e38f8c6bf28433bd391e8842d
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Wed Dec 3 19:41:04 2014 -0500

    Prevent hang during loading of xlsm doc.
    
    * We need to call xmlInitParser() before using it in a multi-threaded
      way (according to the libxml2 doc).
    * Better to use 'rEntity' which references the one stored in the vector
      rather than 'entity' whose copy gets stored in the vector. On Windows
      at least 'rEntity' and 'entity' hold different parser pointer values.
    * Free the parser before popping the entity. Popping the entity first then
      freeing the parser using its pointer value stored in the entity looks
      weird.
    
    Change-Id: I6b64a6d8ac9c1d4fea8339d8fb2d38dfffbba47b

diff --git a/sax/source/fastparser/fastparser.cxx b/sax/source/fastparser/fastparser.cxx
index 92791fc..fc1f5a9 100644
--- a/sax/source/fastparser/fastparser.cxx
+++ b/sax/source/fastparser/fastparser.cxx
@@ -720,6 +720,8 @@ sal_Int32 FastSaxParserImpl::GetTokenWithContextNamespace( sal_Int32 nNamespaceT
 void FastSaxParserImpl::parseStream(const InputSource& maStructSource)
     throw (SAXException, IOException, RuntimeException, std::exception)
 {
+    xmlInitParser();
+
     // Only one text at one time
     MutexGuard guard( maMutex );
 
@@ -741,11 +743,11 @@ void FastSaxParserImpl::parseStream(const InputSource& maStructSource)
     try
     {
         // start the document
-        if( entity.mxDocumentHandler.is() )
+        if( rEntity.mxDocumentHandler.is() )
         {
             Reference< XLocator > xLoc( mxDocumentLocator.get() );
-            entity.mxDocumentHandler->setDocumentLocator( xLoc );
-            entity.mxDocumentHandler->startDocument();
+            rEntity.mxDocumentHandler->setDocumentLocator( xLoc );
+            rEntity.mxDocumentHandler->startDocument();
         }
 
         rEntity.mbEnableThreads = (rEntity.maStructSource.aInputStream->available() > 10000);
@@ -786,33 +788,33 @@ void FastSaxParserImpl::parseStream(const InputSource& maStructSource)
         }
 
         // finish document
-        if( entity.mxDocumentHandler.is() )
+        if( rEntity.mxDocumentHandler.is() )
         {
-            entity.mxDocumentHandler->endDocument();
+            rEntity.mxDocumentHandler->endDocument();
         }
     }
     catch (const SAXException&)
     {
-        popEntity();
         // TODO free mpParser.myDoc ?
-        xmlFreeParserCtxt( entity.mpParser );
+        xmlFreeParserCtxt( rEntity.mpParser );
+        popEntity();
         throw;
     }
     catch (const IOException&)
     {
+        xmlFreeParserCtxt( rEntity.mpParser );
         popEntity();
-        xmlFreeParserCtxt( entity.mpParser );
         throw;
     }
     catch (const RuntimeException&)
     {
+        xmlFreeParserCtxt( rEntity.mpParser );
         popEntity();
-        xmlFreeParserCtxt( entity.mpParser );
         throw;
     }
 
+    xmlFreeParserCtxt( rEntity.mpParser );
     popEntity();
-    xmlFreeParserCtxt( entity.mpParser );
 }
 
 void FastSaxParserImpl::setFastDocumentHandler( const Reference< XFastDocumentHandler >& Handler ) throw (RuntimeException)


More information about the Libreoffice-commits mailing list