salhelper/source/timer.cxx |    4 ++++
 1 file changed, 4 insertions(+)

New commits:
commit f974edd5f7f18152a6c8ba29778a28469289b6df
Author:     Stephan Bergmann <[email protected]>
AuthorDate: Tue May 27 11:56:02 2025 +0200
Commit:     Stephan Bergmann <[email protected]>
CommitDate: Tue May 27 15:16:21 2025 +0200

    Guard concurrent access of TimerManagerImpl::m_pImpl
    
    ...which was found to be a potential issue while inspecting
    011760896551817d4fe8018214eff6d011bb385a "Timer - shutdown and re-start
    salhelper::Timer thread." and its follow-up
    c6c8e1c325f22039bbd709085eaa4d95ffa22192 "don't return impl by shared_ptr"
    
    Change-Id: I6a515b3b3c84a3010d90d115c801f2e5cbcc245a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185894
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <[email protected]>

diff --git a/salhelper/source/timer.cxx b/salhelper/source/timer.cxx
index 89cc5d6c5b2f..b5db12420762 100644
--- a/salhelper/source/timer.cxx
+++ b/salhelper/source/timer.cxx
@@ -63,6 +63,8 @@ class TimerManagerImpl final
 {
     std::mutex m_Lock; // shared lock with each impl. thread
     salhelper::Timer* m_pHead; // the underlying shared queue
+
+    std::mutex m_implLock;
     std::shared_ptr<TimerManager> m_pImpl;
 
 public:
@@ -70,6 +72,7 @@ public:
 
     void joinThread()
     {
+        std::scoped_lock g(m_implLock);
         m_pImpl.reset();
     }
 
@@ -82,6 +85,7 @@ public:
 
     TimerManager& ensureThread()
     {
+        std::scoped_lock g(m_implLock);
         if (!m_pImpl)
             m_pImpl.reset(new TimerManager(m_pHead, m_Lock));
         return *m_pImpl;

Reply via email to