sfx2/source/devtools/DocumentModelTreeHandler.cxx |   14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

New commits:
commit 36b9475e7be42c904580154751aece697883a30a
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Sun Mar 21 20:49:22 2021 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Sun Mar 21 15:57:44 2021 +0100

    devtools: don't store locally the object as XIndexAccess
    
    This doesn't correctly read the IndexAccess if we remember it into
    a member variable, because we can't rely that the input object is
    cast to XIndexAccess, but use a getMainObject method to get a
    different object and cast that to XIndexAccess. So the instance
    of the object can change (object can be removed or and a new one
    added) and we have no way of knowing what the implementation does.
    
    It is possible to cache the XIndexAccess object into a member
    variable (if done carefully), but it is prone to the described
    problems so let's not remember any intermediate objects for
    all DocumentModelTreeEntry subclasses unless we actually have a
    performance problem.
    
    Change-Id: I9d9d30d2b43846d473d118d419d407e34d0b1666
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112836
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/sfx2/source/devtools/DocumentModelTreeHandler.cxx 
b/sfx2/source/devtools/DocumentModelTreeHandler.cxx
index a5b14ca42ab9..e099d3d9cc9d 100644
--- a/sfx2/source/devtools/DocumentModelTreeHandler.cxx
+++ b/sfx2/source/devtools/DocumentModelTreeHandler.cxx
@@ -658,13 +658,9 @@ public:
 /** Represents a list of (Calc) sheet */
 class SheetsEntry : public DocumentModelTreeEntry
 {
-private:
-    uno::Reference<container::XIndexAccess> mxIndexAccess;
-
 public:
     SheetsEntry(OUString const& rString, 
css::uno::Reference<css::uno::XInterface> const& xObject)
         : DocumentModelTreeEntry(rString, xObject)
-        , mxIndexAccess(xObject, uno::UNO_QUERY)
     {
     }
 
@@ -678,18 +674,20 @@ public:
 
     bool shouldShowExpander() override
     {
-        return mxIndexAccess.is() && mxIndexAccess->getCount() > 0;
+        uno::Reference<container::XIndexAccess> xIndexAccess(getMainObject(), 
uno::UNO_QUERY);
+        return xIndexAccess.is() && xIndexAccess->getCount() > 0;
     }
 
     void fill(std::unique_ptr<weld::TreeView>& pDocumentModelTree,
               weld::TreeIter const& rParent) override
     {
-        if (!mxIndexAccess.is())
+        uno::Reference<container::XIndexAccess> xIndexAccesss(getMainObject(), 
uno::UNO_QUERY);
+        if (!xIndexAccesss.is())
             return;
 
-        for (sal_Int32 i = 0; i < mxIndexAccess->getCount(); ++i)
+        for (sal_Int32 i = 0; i < xIndexAccesss->getCount(); ++i)
         {
-            uno::Reference<sheet::XSpreadsheet> 
xSheet(mxIndexAccess->getByIndex(i),
+            uno::Reference<sheet::XSpreadsheet> 
xSheet(xIndexAccesss->getByIndex(i),
                                                        uno::UNO_QUERY);
             OUString aString = lclGetNamed(xSheet);
             if (aString.isEmpty())
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to