summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2016-02-12 13:40:46 +0100
committerCaolán McNamara <caolanm@redhat.com>2016-02-18 09:26:58 +0000
commit1226da376576434c9cea3c80bf304190605edc4c (patch)
tree9df6d736d4b1e800232c3b298be7e4dcb1a59227
parent14279955b467241a70b61f993c334757c2b4a756 (diff)
sw: don't crash if Office.Common/Cache/Writer/OLE_Objects set to 1
(possibly regression from b717bda1f6484905aebc571c4538165a1fbfd2bb) (cherry picked from commit 60d4dd0a6c44b45ed424ca6a0ddcf857ec089b24) Change-Id: I9113fe2e769cd6ba56bdccc629ac63241b238553 Reviewed-on: https://gerrit.libreoffice.org/22335 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--sw/source/core/ole/ndole.cxx35
1 files changed, 20 insertions, 15 deletions
diff --git a/sw/source/core/ole/ndole.cxx b/sw/source/core/ole/ndole.cxx
index ddedf7716b32..c2bccbda314d 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 = 0;
+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=0;
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();
@@ -939,6 +939,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;
@@ -972,6 +973,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;
@@ -995,7 +997,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();
+ }
}
}