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

New commits:
commit 0a9c19ca567017c7b21be336e82a2ea41d993769
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Sun Dec 22 13:22:30 2024 +0000
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Fri Dec 27 22:12:17 2024 +0100

    cid#1607623 Data race condition
    
    Change-Id: Id0c2ec62a246a301d41732d71c99dfa3d02631b5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179313
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sax/source/fastparser/fastparser.cxx 
b/sax/source/fastparser/fastparser.cxx
index 8815cd58329e..6e6756ab0013 100644
--- a/sax/source/fastparser/fastparser.cxx
+++ b/sax/source/fastparser/fastparser.cxx
@@ -198,6 +198,7 @@ struct Entity : public ParserData
     void characters( const OUString& sChars );
     void endElement();
     void processingInstruction( const OUString& rTarget, const OUString& rData 
);
+    void transferUsedEvents();
     EventList& getEventList();
     Event& getEvent( CallbackType aType );
 };
@@ -534,18 +535,23 @@ void Entity::processingInstruction( const OUString& 
rTarget, const OUString& rDa
     }
 }
 
+void Entity::transferUsedEvents()
+{
+    std::unique_lock aGuard(maEventProtector);
+    if (!maUsedEvents.empty())
+    {
+        mxProducedEvents = std::move(maUsedEvents.front());
+        maUsedEvents.pop();
+        aGuard.unlock(); // unlock
+        mnProducedEventsSize = 0;
+    }
+}
+
 EventList& Entity::getEventList()
 {
     if (!mxProducedEvents)
     {
-        std::unique_lock aGuard(maEventProtector);
-        if (!maUsedEvents.empty())
-        {
-            mxProducedEvents = std::move(maUsedEvents.front());
-            maUsedEvents.pop();
-            aGuard.unlock(); // unlock
-            mnProducedEventsSize = 0;
-        }
+        transferUsedEvents();
         if (!mxProducedEvents)
         {
             mxProducedEvents.emplace();
@@ -992,11 +998,12 @@ void FastSaxParserImpl::produce( bool bForceFlush )
     }
 
     rEntity.maPendingEvents.push(std::move(*rEntity.mxProducedEvents));
-    rEntity.mxProducedEvents.reset();
-    assert(!rEntity.mxProducedEvents);
 
     aGuard.unlock(); // unlock
 
+    rEntity.mxProducedEvents.reset();
+    assert(!rEntity.mxProducedEvents);
+
     rEntity.maConsumeResume.set();
 }
 
  • core.git: sax/source Xisco Fauli (via logerrit)
    • core.git: sax/source Caolán McNamara (via logerrit)

Reply via email to