Kaydet (Commit) 26cbb3d1 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Related tdf#82775: Check for disposed-ness

...instead of dereferencing null pointers

Change-Id: I9d1709468a5b601b9f3d86dadea7a8e817f449d8
üst 38e965fe
...@@ -390,33 +390,24 @@ public: ...@@ -390,33 +390,24 @@ public:
private: private:
bool m_bConfigRead; bool m_bConfigRead;
css::uno::Reference< css::uno::XComponentContext > m_xContext; css::uno::Reference< css::uno::XComponentContext > m_xContext;
ConfigurationAccess_FactoryManager* m_pConfigAccess; rtl::Reference<ConfigurationAccess_FactoryManager> m_pConfigAccess;
}; };
UIElementFactoryManager::UIElementFactoryManager( const Reference< XComponentContext >& rxContext ) : UIElementFactoryManager::UIElementFactoryManager( const Reference< XComponentContext >& rxContext ) :
UIElementFactoryManager_BASE(m_aMutex), UIElementFactoryManager_BASE(m_aMutex),
m_bConfigRead( false ), m_bConfigRead( false ),
m_xContext(rxContext) m_xContext(rxContext),
{ m_pConfigAccess(
m_pConfigAccess = new ConfigurationAccess_FactoryManager(rxContext, new ConfigurationAccess_FactoryManager(
"/org.openoffice.Office.UI.Factories/Registered/UIElementFactories"); rxContext,
m_pConfigAccess->acquire(); "/org.openoffice.Office.UI.Factories/Registered/UIElementFactories"))
} {}
UIElementFactoryManager::~UIElementFactoryManager() UIElementFactoryManager::~UIElementFactoryManager() {}
{
disposing();
}
void SAL_CALL UIElementFactoryManager::disposing() void SAL_CALL UIElementFactoryManager::disposing()
{ {
osl::MutexGuard g(rBHelper.rMutex); m_pConfigAccess.clear();
if (m_pConfigAccess)
{
// reduce reference count
m_pConfigAccess->release();
m_pConfigAccess = nullptr;
}
} }
// XUIElementFactory // XUIElementFactory
...@@ -429,6 +420,10 @@ throw ( css::container::NoSuchElementException, css::lang::IllegalArgumentExcept ...@@ -429,6 +420,10 @@ throw ( css::container::NoSuchElementException, css::lang::IllegalArgumentExcept
OUString aModuleId; OUString aModuleId;
{ // SAFE { // SAFE
osl::MutexGuard g(rBHelper.rMutex); osl::MutexGuard g(rBHelper.rMutex);
if (rBHelper.bDisposed) {
throw css::lang::DisposedException(
"disposed", static_cast<OWeakObject *>(this));
}
if ( !m_bConfigRead ) if ( !m_bConfigRead )
{ {
...@@ -473,6 +468,10 @@ throw ( RuntimeException, std::exception ) ...@@ -473,6 +468,10 @@ throw ( RuntimeException, std::exception )
{ {
// SAFE // SAFE
osl::MutexGuard g(rBHelper.rMutex); osl::MutexGuard g(rBHelper.rMutex);
if (rBHelper.bDisposed) {
throw css::lang::DisposedException(
"disposed", static_cast<OWeakObject *>(this));
}
if ( !m_bConfigRead ) if ( !m_bConfigRead )
{ {
...@@ -489,6 +488,10 @@ throw ( RuntimeException, std::exception ) ...@@ -489,6 +488,10 @@ throw ( RuntimeException, std::exception )
OUString aServiceSpecifier; OUString aServiceSpecifier;
{ // SAFE { // SAFE
osl::MutexGuard g(rBHelper.rMutex); osl::MutexGuard g(rBHelper.rMutex);
if (rBHelper.bDisposed) {
throw css::lang::DisposedException(
"disposed", static_cast<OWeakObject *>(this));
}
if ( !m_bConfigRead ) if ( !m_bConfigRead )
{ {
...@@ -524,6 +527,10 @@ throw ( ElementExistException, RuntimeException, std::exception ) ...@@ -524,6 +527,10 @@ throw ( ElementExistException, RuntimeException, std::exception )
{ {
// SAFE // SAFE
osl::MutexGuard g(rBHelper.rMutex); osl::MutexGuard g(rBHelper.rMutex);
if (rBHelper.bDisposed) {
throw css::lang::DisposedException(
"disposed", static_cast<OWeakObject *>(this));
}
if ( !m_bConfigRead ) if ( !m_bConfigRead )
{ {
...@@ -540,6 +547,10 @@ throw ( NoSuchElementException, RuntimeException, std::exception ) ...@@ -540,6 +547,10 @@ throw ( NoSuchElementException, RuntimeException, std::exception )
{ {
// SAFE // SAFE
osl::MutexGuard g(rBHelper.rMutex); osl::MutexGuard g(rBHelper.rMutex);
if (rBHelper.bDisposed) {
throw css::lang::DisposedException(
"disposed", static_cast<OWeakObject *>(this));
}
if ( !m_bConfigRead ) if ( !m_bConfigRead )
{ {
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <cppuhelper/basemutex.hxx> #include <cppuhelper/basemutex.hxx>
#include <cppuhelper/compbase.hxx> #include <cppuhelper/compbase.hxx>
#include <cppuhelper/supportsservice.hxx> #include <cppuhelper/supportsservice.hxx>
#include <rtl/ref.hxx>
#include <tools/diagnose_ex.h> #include <tools/diagnose_ex.h>
using namespace ::com::sun::star; using namespace ::com::sun::star;
...@@ -79,34 +80,24 @@ private: ...@@ -79,34 +80,24 @@ private:
css::uno::Reference< css::uno::XComponentContext > m_xContext; css::uno::Reference< css::uno::XComponentContext > m_xContext;
bool m_bConfigRead; bool m_bConfigRead;
ConfigurationAccess_FactoryManager* m_pConfigAccess; rtl::Reference<ConfigurationAccess_FactoryManager> m_pConfigAccess;
}; };
WindowContentFactoryManager::WindowContentFactoryManager( const uno::Reference< uno::XComponentContext >& rxContext ) : WindowContentFactoryManager::WindowContentFactoryManager( const uno::Reference< uno::XComponentContext >& rxContext ) :
WindowContentFactoryManager_BASE(m_aMutex), WindowContentFactoryManager_BASE(m_aMutex),
m_xContext( rxContext ), m_xContext( rxContext ),
m_bConfigRead( false ) m_bConfigRead( false ),
{ m_pConfigAccess(
m_pConfigAccess = new ConfigurationAccess_FactoryManager( m_xContext, new ConfigurationAccess_FactoryManager(
"/org.openoffice.Office.UI.WindowContentFactories/Registered/ContentFactories" ); m_xContext,
m_pConfigAccess->acquire(); "/org.openoffice.Office.UI.WindowContentFactories/Registered/ContentFactories"))
} {}
WindowContentFactoryManager::~WindowContentFactoryManager() WindowContentFactoryManager::~WindowContentFactoryManager() {}
{
disposing();
}
void SAL_CALL WindowContentFactoryManager::disposing() void SAL_CALL WindowContentFactoryManager::disposing()
{ {
osl::MutexGuard g(rBHelper.rMutex); m_pConfigAccess.clear();
if (m_pConfigAccess)
{
// reduce reference count
m_pConfigAccess->release();
m_pConfigAccess = nullptr;
}
} }
// XSingleComponentFactory // XSingleComponentFactory
...@@ -165,6 +156,10 @@ throw (uno::Exception, uno::RuntimeException, std::exception) ...@@ -165,6 +156,10 @@ throw (uno::Exception, uno::RuntimeException, std::exception)
// module identifier, user interface element type and name // module identifier, user interface element type and name
{ // SAFE { // SAFE
osl::MutexGuard g(rBHelper.rMutex); osl::MutexGuard g(rBHelper.rMutex);
if (rBHelper.bDisposed) {
throw css::lang::DisposedException(
"disposed", static_cast<OWeakObject *>(this));
}
if ( !m_bConfigRead ) if ( !m_bConfigRead )
{ {
m_bConfigRead = true; m_bConfigRead = true;
......
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