forms/source/richtext/parametrizedattributedispatcher.cxx |   14 +++++++-------
 forms/source/richtext/parametrizedattributedispatcher.hxx |    6 +++---
 forms/source/richtext/specialdispatchers.cxx              |   14 ++++++++++----
 forms/source/richtext/specialdispatchers.hxx              |    2 +-
 4 files changed, 21 insertions(+), 15 deletions(-)

New commits:
commit 24d78fcb5399b2c783ab7908263a1b54bb687a22
Author:     Armin Le Grand (allotropia) <armin.le.grand.ext...@allotropia.de>
AuthorDate: Tue May 7 13:59:18 2024 +0200
Commit:     Armin Le Grand <armin.le.gr...@me.com>
CommitDate: Wed May 8 20:49:51 2024 +0200

    tdf#160906 use SfxPoolItemHolder
    
    to avoid handling already deleted SfxPoolItems.
    
    Change-Id: I1f1f8f93cae8db7f7c8df66c2c7f3c02b59a39c3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167274
    Reviewed-by: Armin Le Grand <armin.le.gr...@me.com>
    Tested-by: Jenkins

diff --git a/forms/source/richtext/parametrizedattributedispatcher.cxx 
b/forms/source/richtext/parametrizedattributedispatcher.cxx
index 15b69b0888b6..a86441cd87dd 100644
--- a/forms/source/richtext/parametrizedattributedispatcher.cxx
+++ b/forms/source/richtext/parametrizedattributedispatcher.cxx
@@ -88,7 +88,7 @@ namespace frm
     }
 
 
-    const SfxPoolItem* 
OParametrizedAttributeDispatcher::convertDispatchArgsToItem( const Sequence< 
PropertyValue >& _rArguments )
+    SfxPoolItemHolder 
OParametrizedAttributeDispatcher::convertDispatchArgsToItem( const Sequence< 
PropertyValue >& _rArguments )
     {
         // get the real slot id. This may differ from our attribute id: for 
instance, both
         // SID_ATTR_CHAR_HEIGHT and SID_ATTR_CHAR_LATIN_HEIGHT are mapped to 
the same which id
@@ -97,16 +97,16 @@ namespace frm
         SfxAllItemSet aParameterSet( getEditView()->GetEmptyItemSet() );
         TransformParameters( nSlotId, _rArguments, aParameterSet );
 
-        const SfxPoolItem* pArgument = nullptr;
         if ( aParameterSet.Count() )
         {
             OSL_ENSURE( aParameterSet.Count() == 1, 
"OParametrizedAttributeDispatcher::convertDispatchArgsToItem: Arguments which 
form more than 1 item? How this?" );
             WhichId nAttributeWhich = 
aParameterSet.GetPool()->GetWhichIDFromSlotID( nSlotId );
-            pArgument = aParameterSet.GetItem( nAttributeWhich );
-            OSL_ENSURE( pArgument, 
"OParametrizedAttributeDispatcher::convertDispatchArgsToItem: suspicious: there 
were arguments, but they're not for my slot!" );
+            SfxPoolItemHolder aArgument(*aParameterSet.GetPool(), 
aParameterSet.GetItem(nAttributeWhich));
+            OSL_ENSURE( aArgument.getItem(), 
"OParametrizedAttributeDispatcher::convertDispatchArgsToItem: suspicious: there 
were arguments, but they're not for my slot!" );
+            return aArgument;
         }
 
-        return pArgument;
+        return SfxPoolItemHolder();
     }
 
 
@@ -116,8 +116,8 @@ namespace frm
         OSL_ENSURE( _rURL.Complete == getFeatureURL().Complete, 
"OParametrizedAttributeDispatcher::dispatch: invalid URL!" );
         if ( m_pMasterDispatcher )
         {
-            const SfxPoolItem* pConvertedArgument = convertDispatchArgsToItem( 
_rArguments );
-            m_pMasterDispatcher->executeAttribute( m_nAttributeId, 
pConvertedArgument );
+            const SfxPoolItemHolder 
aConvertedArgument(convertDispatchArgsToItem(_rArguments));
+            m_pMasterDispatcher->executeAttribute(m_nAttributeId, 
aConvertedArgument.getItem());
         }
     }
 
diff --git a/forms/source/richtext/parametrizedattributedispatcher.hxx 
b/forms/source/richtext/parametrizedattributedispatcher.hxx
index 69844731612e..8a68486c131b 100644
--- a/forms/source/richtext/parametrizedattributedispatcher.hxx
+++ b/forms/source/richtext/parametrizedattributedispatcher.hxx
@@ -21,7 +21,7 @@
 
 #include "attributedispatcher.hxx"
 
-class SfxPoolItem;
+class SfxPoolItemHolder;
 
 namespace frm
 {
@@ -47,10 +47,10 @@ namespace frm
 
     protected:
         // own overridables
-        /** convert the arguments as got in a XDispatch::dispatch call into an 
SfxPoolItem, which can
+        /** convert the arguments as got in a XDispatch::dispatch call into an 
SfxPoolItemHolder, which can
             be used with a IMultiAttributeDispatcher::executeAttribute
         */
-        virtual const SfxPoolItem* convertDispatchArgsToItem(
+        virtual SfxPoolItemHolder convertDispatchArgsToItem(
             const css::uno::Sequence< css::beans::PropertyValue >& _rArguments 
);
     };
 
diff --git a/forms/source/richtext/specialdispatchers.cxx 
b/forms/source/richtext/specialdispatchers.cxx
index 283f0db8e09a..b13d29aeeb98 100644
--- a/forms/source/richtext/specialdispatchers.cxx
+++ b/forms/source/richtext/specialdispatchers.cxx
@@ -23,6 +23,7 @@
 #include <editeng/editview.hxx>
 #include <editeng/scriptspaceitem.hxx>
 #include <osl/diagnose.h>
+#include <svl/itemset.hxx>
 
 
 namespace frm
@@ -139,7 +140,7 @@ namespace frm
     }
 
 
-    const SfxPoolItem* OAsianFontLayoutDispatcher::convertDispatchArgsToItem( 
const Sequence< PropertyValue >& _rArguments )
+    SfxPoolItemHolder OAsianFontLayoutDispatcher::convertDispatchArgsToItem( 
const Sequence< PropertyValue >& _rArguments )
     {
         // look for the "Enable" parameter
         const PropertyValue* pLookup = _rArguments.getConstArray();
@@ -154,13 +155,18 @@ namespace frm
         {
             bool bEnable = true;
             OSL_VERIFY( pLookup->Value >>= bEnable );
+
             if ( m_nAttributeId == sal_uInt16(SID_ATTR_PARA_SCRIPTSPACE) )
-                return new SvxScriptSpaceItem( bEnable, 
static_cast<WhichId>(m_nAttributeId) );
-            return new SfxBoolItem( static_cast<WhichId>(m_nAttributeId), 
bEnable );
+                return SfxPoolItemHolder(
+                    *getEditView()->GetEmptyItemSet().GetPool(),
+                    new SvxScriptSpaceItem(bEnable, 
static_cast<WhichId>(m_nAttributeId)));
+            return SfxPoolItemHolder(
+                *getEditView()->GetEmptyItemSet().GetPool(),
+                new SfxBoolItem(static_cast<WhichId>(m_nAttributeId), 
bEnable));
         }
 
         OSL_FAIL( "OAsianFontLayoutDispatcher::convertDispatchArgsToItem: did 
not find the one and only argument!" );
-        return nullptr;
+        return SfxPoolItemHolder();
     }
 
 
diff --git a/forms/source/richtext/specialdispatchers.hxx 
b/forms/source/richtext/specialdispatchers.hxx
index 9b4bfa1b7939..cca2b75ccac6 100644
--- a/forms/source/richtext/specialdispatchers.hxx
+++ b/forms/source/richtext/specialdispatchers.hxx
@@ -80,7 +80,7 @@ namespace frm
 
     protected:
         // OParametrizedAttributeDispatcher
-        virtual const SfxPoolItem* convertDispatchArgsToItem(
+        virtual SfxPoolItemHolder convertDispatchArgsToItem(
             const css::uno::Sequence< css::beans::PropertyValue >& _rArguments 
) override;
     };
 

Reply via email to