[Libreoffice-commits] core.git: Branch 'libreoffice-5-1' - sw/source

Michael Stahl mstahl at redhat.com
Mon Feb 15 23:04:05 UTC 2016


 sw/source/core/ole/ndole.cxx |   35 ++++++++++++++++++++---------------
 1 file changed, 20 insertions(+), 15 deletions(-)

New commits:
commit 4d0f0654f96aafba1c88b4ffa90b7561afadabbf
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri Feb 12 13:40:46 2016 +0100

    sw: don't crash if Office.Common/Cache/Writer/OLE_Objects set to 1
    
    (possibly regression from b717bda1f6484905aebc571c4538165a1fbfd2bb)
    
    Change-Id: I9113fe2e769cd6ba56bdccc629ac63241b238553
    (cherry picked from commit 60d4dd0a6c44b45ed424ca6a0ddcf857ec089b24)
    Reviewed-on: https://gerrit.libreoffice.org/22332
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>

diff --git a/sw/source/core/ole/ndole.cxx b/sw/source/core/ole/ndole.cxx
index 6089e69..d7aabd1 100644
--- a/sw/source/core/ole/ndole.cxx
+++ b/sw/source/core/ole/ndole.cxx
@@ -84,7 +84,7 @@ public:
     void RemoveObj( SwOLEObj& rObj );
 };
 
-SwOLELRUCache* pOLELRU_Cache = nullptr;
+std::shared_ptr<SwOLELRUCache> g_pOLELRU_Cache;
 
 class SwOLEListener_Impl : public ::cppu::WeakImplHelper< embed::XStateChangeListener >
 {
@@ -102,7 +102,7 @@ SwOLEListener_Impl::SwOLEListener_Impl( SwOLEObj* pObj )
 {
     if ( mpObj->IsOleRef() && mpObj->GetOleRef()->getCurrentState() == embed::EmbedStates::RUNNING )
     {
-        pOLELRU_Cache->InsertObj( *mpObj );
+        g_pOLELRU_Cache->InsertObj( *mpObj );
     }
 }
 
@@ -114,29 +114,29 @@ void SAL_CALL SwOLEListener_Impl::stateChanged( const lang::EventObject&, ::sal_
 {
     if ( mpObj && nOldState == embed::EmbedStates::LOADED && nNewState == embed::EmbedStates::RUNNING )
     {
-        if( !pOLELRU_Cache )
-            pOLELRU_Cache = new SwOLELRUCache;
-        pOLELRU_Cache->InsertObj( *mpObj );
+        if (!g_pOLELRU_Cache)
+            g_pOLELRU_Cache.reset(new SwOLELRUCache);
+        g_pOLELRU_Cache->InsertObj( *mpObj );
     }
     else if ( mpObj && nNewState == embed::EmbedStates::LOADED && nOldState == embed::EmbedStates::RUNNING )
     {
-        if ( pOLELRU_Cache )
-            pOLELRU_Cache->RemoveObj( *mpObj );
+        if (g_pOLELRU_Cache)
+            g_pOLELRU_Cache->RemoveObj( *mpObj );
     }
 }
 
 void SwOLEListener_Impl::Release()
 {
-    if ( mpObj && pOLELRU_Cache )
-        pOLELRU_Cache->RemoveObj( *mpObj );
+    if (mpObj && g_pOLELRU_Cache)
+        g_pOLELRU_Cache->RemoveObj( *mpObj );
     mpObj=nullptr;
     release();
 }
 
 void SAL_CALL SwOLEListener_Impl::disposing( const lang::EventObject& ) throw (uno::RuntimeException, std::exception)
 {
-    if ( mpObj && pOLELRU_Cache )
-        pOLELRU_Cache->RemoveObj( *mpObj );
+    if (mpObj && g_pOLELRU_Cache)
+        g_pOLELRU_Cache->RemoveObj( *mpObj );
 }
 
 // TODO/LATER: actually SwEmbedObjectLink should be used here, but because different objects are used to control
@@ -810,9 +810,9 @@ const uno::Reference < embed::XEmbeddedObject > SwOLEObj::GetOleRef()
     else if ( xOLERef->getCurrentState() == embed::EmbedStates::RUNNING )
     {
         // move object to first position in cache
-        if( !pOLELRU_Cache )
-            pOLELRU_Cache = new SwOLELRUCache;
-        pOLELRU_Cache->InsertObj( *this );
+        if (!g_pOLELRU_Cache)
+            g_pOLELRU_Cache.reset(new SwOLELRUCache);
+        g_pOLELRU_Cache->InsertObj( *this );
     }
 
     return xOLERef.GetObject();
@@ -937,6 +937,7 @@ void SwOLELRUCache::Load()
         {
             if (nVal < m_nLRU_InitSize)
             {
+                std::shared_ptr<SwOLELRUCache> tmp(g_pOLELRU_Cache); // prevent delete this
                 // size of cache has been changed
                 sal_Int32 nCount = m_OleObjects.size();
                 sal_Int32 nPos = nCount;
@@ -970,6 +971,7 @@ void SwOLELRUCache::InsertObj( SwOLEObj& rObj )
     }
     if (it == m_OleObjects.end())
     {
+        std::shared_ptr<SwOLELRUCache> tmp(g_pOLELRU_Cache); // prevent delete this
         // try to remove objects if necessary
         sal_Int32 nCount = m_OleObjects.size();
         sal_Int32 nPos = nCount-1;
@@ -993,7 +995,10 @@ void SwOLELRUCache::RemoveObj( SwOLEObj& rObj )
     }
     if (m_OleObjects.empty())
     {
-        DELETEZ( pOLELRU_Cache );
+        if (g_pOLELRU_Cache.unique()) // test that we're not in InsertObj()
+        {
+            g_pOLELRU_Cache.reset();
+        }
     }
 }
 


More information about the Libreoffice-commits mailing list