accessibility/inc/extended/AccessibleGridControl.hxx         |    3 --
 accessibility/inc/extended/AccessibleGridControlTable.hxx    |    3 ++
 accessibility/source/extended/AccessibleGridControl.cxx      |    9 +------
 accessibility/source/extended/AccessibleGridControlTable.cxx |   14 +++++++++++
 4 files changed, 19 insertions(+), 10 deletions(-)

New commits:
commit 4e641d9240a981216d6724141b9b7a9e4c63c82a
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Wed Mar 9 11:51:45 2022 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Wed Mar 9 17:47:10 2022 +0100

    Related: tdf#147742 a11y: Dispose table cells as well
    
    When disposing `AccessibleGridControlTable` (which
    is done in `AccessibleGridControl::disposing`),
    also dispose its cells and clear the references.
    
    Without this in place, a crash sometimes occured
    when running the macro in the sample doc from
    tdf#147742 several times and clicking around in the
    table, with the Orca screen reader active.
    
    This was because a reference to one of
    the `AccessibleGridControlTableCell`s was still
    around after the `AccessibleGridControlTable`
    had already been disposed, and when trying
    to get its accessible name, the call to
    `IAccessibleTable::GetAccessibleObjectName` in
    `AccessibleGridControlCell::getAccessibleName`
    would fail because the object that the
    `m_aTable` reference was referring to had already
    been deleted.
    
    With the cell being disposed as well, the
    `ensureIsAlive()` check at the beginning of
    `AccessibleGridControlCell::getAccessibleName`
    will throw a `DisposedException`, that is then
    handled properly in the calling code.
    
    Backtrace (with master as of commit
    2598c35dbac8dc4492ad1fc79925c5347e683af0):
    
        #0  0x00007fffd9152ed3 in 
accessibility::AccessibleGridControlCell::getAccessibleName() 
(this=0x55555bbcdb70) at 
/home/michi/development/git/libreoffice/accessibility/source/extended/AccessibleGridControlTableCell.cxx:79
        #1  0x00007fffe45e864a in wrapper_get_name(AtkObject*) 
(atk_obj=0x55555bbcef60) at 
/home/michi/development/git/libreoffice/vcl/unx/gtk3/a11y/atkwrapper.cxx:369
        #2  0x00007fffe3a87e5c in  () at 
/lib/x86_64-linux-gnu/libatk-bridge-2.0.so.0
        #3  0x00007fffe3a947de in  () at 
/lib/x86_64-linux-gnu/libatk-bridge-2.0.so.0
        #4  0x00007fffe3a94caf in  () at 
/lib/x86_64-linux-gnu/libatk-bridge-2.0.so.0
        #5  0x00007ffff75feff0 in  () at /lib/x86_64-linux-gnu/libdbus-1.so.3
        #6  0x00007ffff75eea1c in dbus_connection_dispatch () at 
/lib/x86_64-linux-gnu/libdbus-1.so.3
        #7  0x00007fffe36d74a5 in  () at /lib/x86_64-linux-gnu/libatspi.so.0
        #8  0x00007fffe9ab8cdb in g_main_context_dispatch () at 
/lib/x86_64-linux-gnu/libglib-2.0.so.0
        #9  0x00007fffe9ab8f88 in  () at /lib/x86_64-linux-gnu/libglib-2.0.so.0
        #10 0x00007fffe9ab903f in g_main_context_iteration () at 
/lib/x86_64-linux-gnu/libglib-2.0.so.0
        #11 0x00007fffe460f546 in GtkSalData::Yield(bool, bool) 
(this=0x55555567c750, bWait=true, bHandleAllCurrentEvents=false) at 
/home/michi/development/git/libreoffice/vcl/unx/gtk3/gtkdata.cxx:405
        #12 0x00007fffe461402a in GtkInstance::DoYield(bool, bool) 
(this=0x55555567c5d0, bWait=true, bHandleAllCurrentEvents=false) at 
/home/michi/development/git/libreoffice/vcl/unx/gtk3/gtkinst.cxx:427
        #13 0x00007fffef7ab4be in ImplYield(bool, bool) (i_bWait=true, 
i_bAllEvents=false) at 
/home/michi/development/git/libreoffice/vcl/source/app/svapp.cxx:474
        #14 0x00007fffef7ac0b0 in Application::Yield() () at 
/home/michi/development/git/libreoffice/vcl/source/app/svapp.cxx:558
        #15 0x00007fffef7ab18e in Application::Execute() () at 
/home/michi/development/git/libreoffice/vcl/source/app/svapp.cxx:452
        #16 0x00007ffff7c309af in desktop::Desktop::Main() 
(this=0x7fffffffd780) at 
/home/michi/development/git/libreoffice/desktop/source/app/app.cxx:1604
        #17 0x00007fffef7c9d75 in ImplSVMain() () at 
/home/michi/development/git/libreoffice/vcl/source/app/svmain.cxx:202
        #18 0x00007fffef7c9e96 in SVMain() () at 
/home/michi/development/git/libreoffice/vcl/source/app/svmain.cxx:234
        #19 0x00007ffff7c947c9 in soffice_main() () at 
/home/michi/development/git/libreoffice/desktop/source/app/sofficemain.cxx:98
        #20 0x00005555555549f4 in sal_main () at 
/home/michi/development/git/libreoffice/desktop/source/app/main.c:51
        #21 0x00005555555549da in main (argc=4, argv=0x7fffffffdaf8) at 
/home/michi/development/git/libreoffice/desktop/source/app/main.c:49
    
    Change-Id: Idffa76809cbfad746f27d18191fdfc905b64ee0e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131247
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/accessibility/inc/extended/AccessibleGridControlTable.hxx 
b/accessibility/inc/extended/AccessibleGridControlTable.hxx
index bada75124257..602365468505 100644
--- a/accessibility/inc/extended/AccessibleGridControlTable.hxx
+++ b/accessibility/inc/extended/AccessibleGridControlTable.hxx
@@ -139,6 +139,9 @@ public:
     /** @return  The name of this class. */
     virtual OUString SAL_CALL getImplementationName() override;
 
+    // XComponent
+    virtual void SAL_CALL dispose() override;
+
     /**@return m_pCellVector*/
     std::vector< rtl::Reference<AccessibleGridControlTableCell> >& 
getCellVector() { return m_aCellVector;}
 
diff --git a/accessibility/source/extended/AccessibleGridControlTable.cxx 
b/accessibility/source/extended/AccessibleGridControlTable.cxx
index a08302be6d92..3c635e910d72 100644
--- a/accessibility/source/extended/AccessibleGridControlTable.cxx
+++ b/accessibility/source/extended/AccessibleGridControlTable.cxx
@@ -290,6 +290,20 @@ OUString SAL_CALL 
AccessibleGridControlTable::getImplementationName()
     return "com.sun.star.accessibility.AccessibleGridControlTable";
 }
 
+void AccessibleGridControlTable::dispose()
+{
+    for (rtl::Reference<AccessibleGridControlTableCell>& rxCell : 
m_aCellVector)
+    {
+        if (rxCell.is())
+        {
+            rxCell->dispose();
+            rxCell.clear();
+        }
+    }
+
+    AccessibleGridControlTableBase::dispose();
+}
+
 void AccessibleGridControlTable::commitEvent(sal_Int16 nEventId, const 
css::uno::Any& rNewValue,
                                              const css::uno::Any& rOldValue)
 {
commit b86c4d962c7df4a5066ee634df88868b8bb287fe
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Wed Mar 9 11:27:17 2022 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Wed Mar 9 17:46:55 2022 +0100

    a11y: Drop AccessibleGridControl::m_xCell
    
    It's only used in one place and I see no need to keep
    a Reference in this class, so use a local variable
    instead of a class member.
    
    Instead of disposing this single cell in
    `AccessibleGridControl::disposing`,
    `AccessibleGridControlTable` should take care
    of disposing all of its cells, which will be
    added in a following commit
    (Change-Id Idffa76809cbfad746f27d18191fdfc905b64ee0e,
    "Related: tdf#147742 a11y: Dispose table cells as well").
    
    Change-Id: Ia7c84c65b45dde28850f48b12ab9558f2dc7d47c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131246
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/accessibility/inc/extended/AccessibleGridControl.hxx 
b/accessibility/inc/extended/AccessibleGridControl.hxx
index 6fa1a91b4919..79b4e19e47b1 100644
--- a/accessibility/inc/extended/AccessibleGridControl.hxx
+++ b/accessibility/inc/extended/AccessibleGridControl.hxx
@@ -149,9 +149,6 @@ private:
     /** The header bar for columns (first row of the table). */
     rtl::Reference<AccessibleGridControlHeader>               
m_xColumnHeaderBar;
 
-    /** The table cell child. */
-    rtl::Reference<AccessibleGridControlTableCell>            m_xCell;
-
     /** @return  The count of visible children. */
     inline sal_Int32 implGetAccessibleChildCount();
 };
diff --git a/accessibility/source/extended/AccessibleGridControl.cxx 
b/accessibility/source/extended/AccessibleGridControl.cxx
index 5d4ed3bc767c..81f3d121ab0f 100644
--- a/accessibility/source/extended/AccessibleGridControl.cxx
+++ b/accessibility/source/extended/AccessibleGridControl.cxx
@@ -57,11 +57,6 @@ void SAL_CALL AccessibleGridControl::disposing()
         m_xTable->dispose();
         m_xTable.clear();
     }
-    if ( m_xCell.is() )
-    {
-        m_xCell->dispose();
-        m_xCell.clear();
-    }
     if ( m_xRowHeaderBar.is() )
     {
         m_xRowHeaderBar->dispose();
@@ -281,8 +276,8 @@ void AccessibleGridControl::commitCellEvent(sal_Int16 
_nEventId,const Any& _rNew
                               + m_aTable.GetCurrentColumn();
                 if (nIndex < rCells.size() && rCells[nIndex])
                 {
-                    m_xCell = rCells[nIndex];
-                    m_xCell->commitEvent( _nEventId, _rNewValue, _rOldValue );
+                    rtl::Reference<AccessibleGridControlTableCell> xCell = 
rCells[nIndex];
+                    xCell->commitEvent( _nEventId, _rNewValue, _rOldValue );
                 }
             }
         }

Reply via email to