unoxml/source/dom/documentbuilder.cxx |   17 +++++++++++++----
 unoxml/source/dom/documentbuilder.hxx |    8 +-------
 2 files changed, 14 insertions(+), 11 deletions(-)

New commits:
commit 9389e0c6397d258e579bd0cdddafae0c4140da5d
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Fri Sep 27 21:27:10 2024 +0100
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Mon Sep 30 12:27:25 2024 +0200

    cid#1557088 Data race condition
    
    since:
    
    commit d181d8acbf49e2fe87c8cf53a9431e503ccced55
    CommitDate: Fri Aug 25 12:44:33 2017 +0200
    
        tdf#84237 use XErrorHandler in CDocumentBuilder
    
    Change-Id: Iac1d2b88f2910298d30de4d12798bb38c36a0de9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174102
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    (cherry picked from commit 8e02696b32588e3a1eca3885450873f62213244e)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174021
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/unoxml/source/dom/documentbuilder.cxx 
b/unoxml/source/dom/documentbuilder.cxx
index 46232463497d..f08769492974 100644
--- a/unoxml/source/dom/documentbuilder.cxx
+++ b/unoxml/source/dom/documentbuilder.cxx
@@ -254,14 +254,15 @@ namespace DOM
 
             CDocumentBuilder * const pDocBuilder = 
static_cast<CDocumentBuilder*>(pctx->_private);
 
-            if (pDocBuilder->getErrorHandler().is())   // if custom error 
handler is set (using setErrorHandler ())
+            Reference<XErrorHandler> xErrorHandler = 
pDocBuilder->getErrorHandler();
+            if (xErrorHandler.is())   // if custom error handler is set (using 
setErrorHandler ())
             {
                 // Prepare SAXParseException to be passed to custom 
XErrorHandler::warning function
                 css::xml::sax::SAXParseException 
saxex(make_error_message(pctx), {}, {}, {}, {},
                                                        pctx->lastError.line, 
pctx->lastError.int2);
 
                 // Call custom warning function
-                
pDocBuilder->getErrorHandler()->warning(::css::uno::Any(saxex));
+                xErrorHandler->warning(::css::uno::Any(saxex));
             }
         }
         catch (const css::uno::Exception &)
@@ -284,14 +285,15 @@ namespace DOM
 
             CDocumentBuilder * const pDocBuilder = 
static_cast<CDocumentBuilder*>(pctx->_private);
 
-            if (pDocBuilder->getErrorHandler().is())   // if custom error 
handler is set (using setErrorHandler ())
+            Reference<XErrorHandler> xErrorHandler = 
pDocBuilder->getErrorHandler();
+            if (xErrorHandler.is())   // if custom error handler is set (using 
setErrorHandler ())
             {
                 // Prepare SAXParseException to be passed to custom 
XErrorHandler::error function
                 css::xml::sax::SAXParseException 
saxex(make_error_message(pctx), {}, {}, {}, {},
                                                        pctx->lastError.line, 
pctx->lastError.int2);
 
                 // Call custom warning function
-                pDocBuilder->getErrorHandler()->error(::css::uno::Any(saxex));
+                xErrorHandler->error(::css::uno::Any(saxex));
             }
         }
         catch (const css::uno::Exception &)
@@ -412,6 +414,13 @@ namespace DOM
 
         m_xErrorHandler = xEH;
     }
+
+    Reference< XErrorHandler > CDocumentBuilder::getErrorHandler()
+    {
+        std::scoped_lock const g(m_Mutex);
+
+        return m_xErrorHandler;
+    }
 }
 
 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
diff --git a/unoxml/source/dom/documentbuilder.hxx 
b/unoxml/source/dom/documentbuilder.hxx
index 7b93b170d4c1..c63a8970d289 100644
--- a/unoxml/source/dom/documentbuilder.hxx
+++ b/unoxml/source/dom/documentbuilder.hxx
@@ -104,7 +104,6 @@ namespace DOM
         /// @throws css::uno::RuntimeException
         css::uno::Reference< css::xml::sax::XEntityResolver > 
getEntityResolver();
 
-
         /**
         Specify the ErrorHandler to be used to report errors present in
         the XML document to be parsed.
@@ -115,12 +114,7 @@ namespace DOM
         Get the ErrorHandler to be used to report errors present in
         the XML document to be parsed.
         */
-
-        const css::uno::Reference< css::xml::sax::XErrorHandler >& 
getErrorHandler() const
-        {
-            return m_xErrorHandler;
-        }
-
+        css::uno::Reference< css::xml::sax::XErrorHandler > getErrorHandler();
     };
 }
 

Reply via email to