basic/source/classes/propacc.cxx                      |   15 +++----------
 basic/source/inc/propacc.hxx                          |    3 ++
 comphelper/source/property/propertysetinfo.cxx        |   20 ------------------
 framework/source/fwi/uielement/constitemcontainer.cxx |   14 +++++++++++-
 include/comphelper/propertysetinfo.hxx                |    1 
 5 files changed, 20 insertions(+), 33 deletions(-)

New commits:
commit a6856795267509aaf0b4f59a9fb3a626411d1cb6
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Mon May 30 12:24:42 2022 +0100
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Mon May 30 16:00:35 2022 +0200

    cid#1504574 Resource leak
    
    make an owner for the PropertyMapEntries
    
    Change-Id: Ie915a8a312f2b24488566814ad67fdeef89b5941
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135123
    Tested-by: Jenkins
    Tested-by: Caolán McNamara <caol...@redhat.com>
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/basic/source/classes/propacc.cxx b/basic/source/classes/propacc.cxx
index 06bba39073d7..4c948c3038af 100644
--- a/basic/source/classes/propacc.cxx
+++ b/basic/source/classes/propacc.cxx
@@ -54,17 +54,10 @@ Reference< XPropertySetInfo > 
SbPropertyValues::getPropertySetInfo()
     // create on demand?
     if (!m_xInfo.is())
     {
-        uno::Sequence<beans::Property> props(m_aPropVals.size());
-        for (size_t n = 0; n < m_aPropVals.size(); ++n)
-        {
-            Property &rProp = props.getArray()[n];
-            const PropertyValue &rPropVal = m_aPropVals[n];
-            rProp.Name = rPropVal.Name;
-            rProp.Handle = rPropVal.Handle;
-            rProp.Type = cppu::UnoType<void>::get();
-            rProp.Attributes = 0;
-        }
-        m_xInfo.set(new ::comphelper::PropertySetInfo(props));
+        assert(m_aPropInfos.empty());
+        for (auto const& it : m_aPropVals)
+            m_aPropInfos.emplace_back(it.Name, it.Handle, 
cppu::UnoType<void>::get(), 0, 0);
+        m_xInfo.set(new ::comphelper::PropertySetInfo(m_aPropInfos));
     }
     return m_xInfo;
 }
diff --git a/basic/source/inc/propacc.hxx b/basic/source/inc/propacc.hxx
index 66dd26cefe63..bb2d13d50216 100644
--- a/basic/source/inc/propacc.hxx
+++ b/basic/source/inc/propacc.hxx
@@ -22,11 +22,13 @@
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/beans/XPropertySetInfo.hpp>
 #include <com/sun/star/beans/XPropertyAccess.hpp>
+#include <comphelper/propertysetinfo.hxx>
 #include <cppuhelper/implbase.hxx>
 
 #include <vector>
 
 typedef std::vector<css::beans::PropertyValue> SbPropertyValueArr_Impl;
+typedef std::vector<comphelper::PropertyMapEntry> SbPropertyInfoArr_Impl;
 
 typedef ::cppu::WeakImplHelper< css::beans::XPropertySet,
                                 css::beans::XPropertyAccess > 
SbPropertyValuesHelper;
@@ -35,6 +37,7 @@ typedef ::cppu::WeakImplHelper< css::beans::XPropertySet,
 class SbPropertyValues final : public SbPropertyValuesHelper
 {
     SbPropertyValueArr_Impl m_aPropVals;
+    SbPropertyInfoArr_Impl m_aPropInfos;
     css::uno::Reference< css::beans::XPropertySetInfo > m_xInfo;
 
 private:
diff --git a/comphelper/source/property/propertysetinfo.cxx 
b/comphelper/source/property/propertysetinfo.cxx
index 6385965c0d56..206129c5f595 100644
--- a/comphelper/source/property/propertysetinfo.cxx
+++ b/comphelper/source/property/propertysetinfo.cxx
@@ -47,26 +47,6 @@ PropertySetInfo::PropertySetInfo( o3tl::span<const 
PropertyMapEntry> pMap ) noex
     }
 }
 
-PropertySetInfo::PropertySetInfo(uno::Sequence<beans::Property> const& rProps) 
noexcept
-{
-    PropertyMapEntry * pEntries(new PropertyMapEntry[rProps.getLength()]);
-    PropertyMapEntry * pEntry(&pEntries[0]);
-    for (auto const& it : rProps)
-    {
-        // check for duplicates
-        assert(maPropertyMap.find(it.Name) == maPropertyMap.end());
-
-        pEntry->maName = it.Name;
-        pEntry->mnHandle = it.Handle;
-        pEntry->maType = it.Type;
-        pEntry->mnAttributes = it.Attributes;
-        pEntry->mnMemberId = 0;
-
-        maPropertyMap.emplace(it.Name, pEntry);
-        ++pEntry;
-    }
-}
-
 PropertySetInfo::~PropertySetInfo() noexcept
 {
 }
diff --git a/framework/source/fwi/uielement/constitemcontainer.cxx 
b/framework/source/fwi/uielement/constitemcontainer.cxx
index f9840d52ec3b..7e43a5009c36 100644
--- a/framework/source/fwi/uielement/constitemcontainer.cxx
+++ b/framework/source/fwi/uielement/constitemcontainer.cxx
@@ -190,12 +190,24 @@ Any SAL_CALL ConstItemContainer::getByIndex( sal_Int32 
Index )
     return Any( m_aItemVector[Index] );
 }
 
+namespace
+{
+    std::vector<comphelper::PropertyMapEntry> makePropertyMap(const 
css::uno::Sequence<css::beans::Property>& rProps)
+    {
+        std::vector<comphelper::PropertyMapEntry> aEntries;
+        for (auto const& it : rProps)
+            aEntries.emplace_back(it.Name, it.Handle, it.Type, it.Attributes, 
0);
+        return aEntries;
+    }
+}
+
 // XPropertySet
 Reference< XPropertySetInfo > SAL_CALL ConstItemContainer::getPropertySetInfo()
 {
     // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
     // (Use method "getInfoHelper()".)
-    static Reference< XPropertySetInfo > xInfo(new 
comphelper::PropertySetInfo(getInfoHelper().getProperties()));
+    static std::vector<comphelper::PropertyMapEntry> 
aPropertyInfos(makePropertyMap(getInfoHelper().getProperties()));
+    static Reference< XPropertySetInfo > xInfo(new 
comphelper::PropertySetInfo(aPropertyInfos));
 
     return xInfo;
 }
diff --git a/include/comphelper/propertysetinfo.hxx 
b/include/comphelper/propertysetinfo.hxx
index 4f7ac39c29f3..ee26d86982e4 100644
--- a/include/comphelper/propertysetinfo.hxx
+++ b/include/comphelper/propertysetinfo.hxx
@@ -91,7 +91,6 @@ class COMPHELPER_DLLPUBLIC PropertySetInfo final
 public:
     PropertySetInfo() noexcept;
     PropertySetInfo( o3tl::span<const PropertyMapEntry> pMap ) noexcept;
-    PropertySetInfo(css::uno::Sequence<css::beans::Property> const &) noexcept;
     virtual ~PropertySetInfo() noexcept override;
 
     /** returns a stl map with all PropertyMapEntry pointer.<p>

Reply via email to