Kaydet (Commit) 48c6f4e0 authored tarafından Michael Stahl's avatar Michael Stahl

framework: avoid crashing in ~HandlerCFGAccess() in atexit()

Commit d587931f changed
HandlerCache::s_pConfig to a unique_ptr, which may now crash on
shutdown because it's a utl::ConfigItem and by atexit() time the
configmgr is long gone.

Due to the HandlerCache::m_nRefCount, the crash probably only happens
in case of an unclean shutdown, but we don't know whether this can
happen in practice or not, so just avoid crashing on shutdown.

Change-Id: Ifd2b782aa5592c344d1bc85acaa434c3f2a69b60
Reviewed-on: https://gerrit.libreoffice.org/67029
Tested-by: Jenkins
Reviewed-by: 's avatarMichael Stahl <Michael.Stahl@cib.de>
üst 577a9708
...@@ -93,11 +93,11 @@ class FWI_DLLPUBLIC HandlerCache final ...@@ -93,11 +93,11 @@ class FWI_DLLPUBLIC HandlerCache final
private: private:
/// list of all registered handler registered by her uno implementation names /// list of all registered handler registered by her uno implementation names
static std::unique_ptr<HandlerHash> m_pHandler; static std::unique_ptr<HandlerHash> s_pHandler;
/// maps URL pattern to handler names /// maps URL pattern to handler names
static std::unique_ptr<PatternHash> m_pPattern; static std::unique_ptr<PatternHash> s_pPattern;
/// informs about config updates /// informs about config updates
static std::unique_ptr<HandlerCFGAccess> m_pConfig; static HandlerCFGAccess* s_pConfig;
/// ref count to construct/destruct internal member lists on demand by using singleton mechanism /// ref count to construct/destruct internal member lists on demand by using singleton mechanism
static sal_Int32 m_nRefCount; static sal_Int32 m_nRefCount;
......
...@@ -73,10 +73,10 @@ PatternHash::const_iterator findPatternKey(PatternHash const * hash, const OUStr ...@@ -73,10 +73,10 @@ PatternHash::const_iterator findPatternKey(PatternHash const * hash, const OUStr
That means it use two static member list to hold all necessary information That means it use two static member list to hold all necessary information
and a ref count mechanism to create/destroy it on demand. and a ref count mechanism to create/destroy it on demand.
*/ */
std::unique_ptr<HandlerHash> HandlerCache::m_pHandler; std::unique_ptr<HandlerHash> HandlerCache::s_pHandler;
std::unique_ptr<PatternHash> HandlerCache::m_pPattern; std::unique_ptr<PatternHash> HandlerCache::s_pPattern;
sal_Int32 HandlerCache::m_nRefCount = 0; sal_Int32 HandlerCache::m_nRefCount = 0;
std::unique_ptr<HandlerCFGAccess> HandlerCache::m_pConfig; HandlerCFGAccess* HandlerCache::s_pConfig = nullptr;
/** /**
@short ctor of the cache of all registered protocol handler @short ctor of the cache of all registered protocol handler
...@@ -91,11 +91,11 @@ HandlerCache::HandlerCache() ...@@ -91,11 +91,11 @@ HandlerCache::HandlerCache()
if (m_nRefCount==0) if (m_nRefCount==0)
{ {
m_pHandler.reset(new HandlerHash); s_pHandler.reset(new HandlerHash);
m_pPattern.reset(new PatternHash); s_pPattern.reset(new PatternHash);
m_pConfig.reset(new HandlerCFGAccess(PACKAGENAME_PROTOCOLHANDLER)); s_pConfig = new HandlerCFGAccess(PACKAGENAME_PROTOCOLHANDLER);
m_pConfig->read(*m_pHandler, *m_pPattern); s_pConfig->read(*s_pHandler, *s_pPattern);
m_pConfig->setCache(this); s_pConfig->setCache(this);
} }
++m_nRefCount; ++m_nRefCount;
...@@ -112,11 +112,12 @@ HandlerCache::~HandlerCache() ...@@ -112,11 +112,12 @@ HandlerCache::~HandlerCache()
if( m_nRefCount==1) if( m_nRefCount==1)
{ {
m_pConfig->setCache(nullptr); s_pConfig->setCache(nullptr);
m_pConfig.reset(); delete s_pConfig;
m_pHandler.reset(); s_pConfig = nullptr;
m_pPattern.reset(); s_pHandler.reset();
s_pPattern.reset();
} }
--m_nRefCount; --m_nRefCount;
...@@ -133,10 +134,10 @@ bool HandlerCache::search( const OUString& sURL, ProtocolHandler* pReturn ) cons ...@@ -133,10 +134,10 @@ bool HandlerCache::search( const OUString& sURL, ProtocolHandler* pReturn ) cons
SolarMutexGuard aGuard; SolarMutexGuard aGuard;
PatternHash::const_iterator pItem = findPatternKey(m_pPattern.get(), sURL); PatternHash::const_iterator pItem = findPatternKey(s_pPattern.get(), sURL);
if (pItem!=m_pPattern->end()) if (pItem != s_pPattern->end())
{ {
*pReturn = (*m_pHandler)[pItem->second]; *pReturn = (*s_pHandler)[pItem->second];
bFound = true; bFound = true;
} }
...@@ -158,8 +159,8 @@ void HandlerCache::takeOver(std::unique_ptr<HandlerHash> pHandler, std::unique_p ...@@ -158,8 +159,8 @@ void HandlerCache::takeOver(std::unique_ptr<HandlerHash> pHandler, std::unique_p
{ {
SolarMutexGuard aGuard; SolarMutexGuard aGuard;
m_pHandler = std::move(pHandler); s_pHandler = std::move(pHandler);
m_pPattern = std::move(pPattern); s_pPattern = std::move(pPattern);
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment