comphelper/source/misc/accessiblewrapper.cxx |    8 ++++++--
 include/comphelper/accessiblewrapper.hxx     |    6 ++++--
 2 files changed, 10 insertions(+), 4 deletions(-)

New commits:
commit db0044242a897e447988169630ff74e4c8bfecf9
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Wed Sep 6 09:12:23 2023 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Wed Sep 6 10:57:49 2023 +0200

    tdf#156683 a11y: Forward when wrapped a11y context is disposing
    
    `OAccessibleContextWrapper` wraps an `XAccessibleContext`
    held in the `m_xInnerContext` member and forwards
    calls to its own methods to that one.
    
    The lifecycle of the wrapper should match that of
    the wrapped context, so handle when the
    wrapped context is disposing by overriding
    `XAccessibleContext::disposing` (that takes
    a `css::lang::EventObject&` parameter) instead of
    overriding `WeakComponentImplHelperBase::disposing`
     (the `disposing` method not taking a param)
    that's meant to be called when/right before the
    object itself gets disposed (but wasn't called
    at all e.g. for the `OToolBoxWindowItemContext`
    case in tdf#156683).
    
    This makes sure that the corresponding entry in the
    `AccessibleEventNotifier` client map is removed and
    event listeners for the wrapper get notified
    (via `AccessibleEventNotifier::revokeClientNotifyDisposing`)
    when the wrapped object is disposing and fixes the tdf#156683
    crash on exit with gtk3 observed in the libreoffice-7-6 branch:
    
        /usr/include/c++/13/debug/vector:450:
        In function:
            std::debug::vector<_Tp, _Allocator>::const_reference std::
            debug::vector<_Tp, _Allocator>::operator[](size_type) const [with 
_Tp =
            
com::sun::star::uno::Reference<com::sun::star::accessibility::XAccessibleEventListener>;
            _Allocator =
            
std::allocator<com::sun::star::uno::Reference<com::sun::star::accessibility::XAccessibleEventListener>
            >; const_reference = const
            
com::sun::star::uno::Reference<com::sun::star::accessibility::XAccessibleEventListener>&;
            size_type = long unsigned int]
    
        Error: attempt to subscript container with out-of-bounds index 0, but
        container only holds 0 elements.
    
        Objects involved in the operation:
            sequence "this" @ 0x561465d8e510 {
              type = 
std::debug::vector<com::sun::star::uno::Reference<com::sun::star::accessibility::XAccessibleEventListener>,
 
std::allocator<com::sun::star::uno::Reference<com::sun::star::accessibility::XAccessibleEventListener>
 > >;
            }
        warn:desktop:197113:197113:desktop/source/app/crashreport.cxx:61: 
minidump generated: 
/home/michi/development/git/libreoffice-WORKTREE/instdir/program/../program/../crash//e338ad13-2338-4cd0-8d5c069d-c28f5cf5.dmp
    
    Backtrace:
    
        1   
comphelper::OInterfaceContainerHelper4<com::sun::star::accessibility::XAccessibleEventListener>::disposeAndClear
                                             interfacecontainer4.hxx     397  
0x7f2c39915cdc
        2   comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing    
                                                                                
         accessibleeventnotifier.cxx 204  0x7f2c39913c75
        3   comphelper::OAccessibleContextWrapper::disposing                    
                                                                                
         accessiblewrapper.cxx       610  0x7f2c3992f033
        4   cppu::WeakComponentImplHelperBase::dispose                          
                                                                                
         implbase.cxx                104  0x7f2c3947491b
        5   
cppu::PartialWeakComponentImplHelper<com::sun::star::accessibility::XAccessibleEventBroadcaster,
 com::sun::star::accessibility::XAccessibleContext>::dispose compbase.hxx       
         90   0x7f2bf8b31c70
        6   cppu::WeakComponentImplHelperBase::release                          
                                                                                
         implbase.cxx                79   0x7f2c39474664
        7   
cppu::PartialWeakComponentImplHelper<com::sun::star::accessibility::XAccessibleEventBroadcaster,
 com::sun::star::accessibility::XAccessibleContext>::release compbase.hxx       
         86   0x7f2c3993133c
        8   comphelper::OAccessibleContextWrapper::release                      
                                                                                
         accessiblewrapper.cxx       475  0x7f2c3992e536
        9   
com::sun::star::uno::Reference<com::sun::star::accessibility::XAccessibleContext>::clear
                                                                     
Reference.hxx               231  0x7f2c26929685
        10  atk_object_wrapper_dispose                                          
                                                                                
         atkwrapper.cxx              1074 0x7f2c26928a2e
        11  atk_object_wrapper_finalize                                         
                                                                                
         atkwrapper.cxx              670  0x7f2c26927677
        12  g_object_unref                                                      
                                                                                
                                          0x7f2c3418c48c
        13  AtkListener::~AtkListener                                           
                                                                                
         atklistener.cxx             57   0x7f2c26900547
        14  AtkListener::~AtkListener                                           
                                                                                
         atklistener.cxx             58   0x7f2c2690057e
        15  cppu::OWeakObject::release                                          
                                                                                
         weak.cxx                    230  0x7f2c39556056
        16  
cppu::WeakImplHelper<com::sun::star::accessibility::XAccessibleEventListener>::release
                                                                       
implbase.hxx                115  0x7f2c2690a92e
        17  
com::sun::star::uno::Reference<com::sun::star::accessibility::XAccessibleEventListener>::~Reference
                                                          Reference.hxx         
      114  0x7f2c39921b9f
        18  
std::_Destroy<com::sun::star::uno::Reference<com::sun::star::accessibility::XAccessibleEventListener>>
                                                       stl_construct.h          
   151  0x7f2c399217af
        19  
std::_Destroy_aux<false>::__destroy<com::sun::star::uno::Reference<com::sun::star::accessibility::XAccessibleEventListener>
 *>                               stl_construct.h             163  
0x7f2c39920bd5
        20  
std::_Destroy<com::sun::star::uno::Reference<com::sun::star::accessibility::XAccessibleEventListener>
 *>                                                     stl_construct.h         
    196  0x7f2c3991f10b
        ... <More>
    
    Reverse-debugging to the start of `atk_object_wrapper_dispose`
    (s. frame 10 above), shows that the the `mpContext` is`:
    
        uno::Reference to ((anonymous namespace)::OToolBoxWindowItemContext *) 
0x5637df79f1b8
    
    Also, call the base class implementation of
    the same method, i.e.
    `OAccessibleContextWrapperHelper::disposing`
    instead of directly disposing via
    `OAccessibleContextWrapperHelper::dispose`.
    The former will call `dispose` via its base
    class implementation if it hasn't been
    disposed yet, s. `OComponentProxyAggregationHelper::disposing`.
    
    Change-Id: Ief66ffbe075af40f10c5fafa62063bda55f66b2f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156610
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/comphelper/source/misc/accessiblewrapper.cxx 
b/comphelper/source/misc/accessiblewrapper.cxx
index 4c8d98977cd3..bd66b7534d46 100644
--- a/comphelper/source/misc/accessiblewrapper.cxx
+++ b/comphelper/source/misc/accessiblewrapper.cxx
@@ -585,8 +585,12 @@ namespace comphelper
     }
 
 
-    void SAL_CALL OAccessibleContextWrapper::disposing()
+    void SAL_CALL OAccessibleContextWrapper::disposing(const 
css::lang::EventObject& rEvent)
     {
+        assert(rEvent.Source == Reference<XInterface>(m_xInnerContext, 
UNO_QUERY)
+               && "OAccessibleContextWrapper::disposing called with event 
source that's not the "
+                  "wrapped a11y context");
+
         AccessibleEventNotifier::TClientId nClientId( 0 );
 
         // --- <mutex lock> -----------------------------------------
@@ -603,7 +607,7 @@ namespace comphelper
         // --- </mutex lock> -----------------------------------------
 
         // let the base class do
-        OAccessibleContextWrapperHelper::dispose();
+        OAccessibleContextWrapperHelper::disposing(rEvent);
 
         // notify the disposal
         if ( nClientId )
diff --git a/include/comphelper/accessiblewrapper.hxx 
b/include/comphelper/accessiblewrapper.hxx
index 8a09ae0110c3..c2ababe40e1a 100644
--- a/include/comphelper/accessiblewrapper.hxx
+++ b/include/comphelper/accessiblewrapper.hxx
@@ -298,8 +298,10 @@ namespace comphelper
         virtual void notifyTranslatedEvent( const 
css::accessibility::AccessibleEventObject& _rEvent ) override;
 
         // OComponentHelper
-        using OAccessibleContextWrapperHelper::disposing;
-        virtual void SAL_CALL disposing() override;
+        using cppu::WeakComponentImplHelperBase::disposing;
+
+        // XAccessibleEventListener
+        virtual void SAL_CALL disposing(const css::lang::EventObject& rEvent) 
override;
 
     protected:
         virtual ~OAccessibleContextWrapper() override;

Reply via email to