sw/qa/extras/uiwriter/uiwriter7.cxx |    4 ++--
 sw/source/uibase/inc/textsh.hxx     |    2 +-
 sw/source/uibase/shells/textsh.cxx  |   34 +++++++++++++++++-----------------
 3 files changed, 20 insertions(+), 20 deletions(-)

New commits:
commit b808ca42aa6eb902bae22d1ae48c9c99e27f544d
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Mon Aug 26 17:35:08 2024 +0100
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Tue Aug 27 12:01:44 2024 +0200

    cid#1557116 dangling reference
    
    CreateFrameTabDialog takes an argument of a reference
    to the aSet ItemSet and SwFrameDlg keeps that reference
    but the SwFrameDlg will outlive that local.
    
    Change-Id: I9a0c55b86baf84cfa586952755e5a470a44562c7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172435
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Tested-by: Jenkins

diff --git a/sw/qa/extras/uiwriter/uiwriter7.cxx 
b/sw/qa/extras/uiwriter/uiwriter7.cxx
index 16afe5f205c0..33d873044849 100644
--- a/sw/qa/extras/uiwriter/uiwriter7.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter7.cxx
@@ -2400,10 +2400,10 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf88986)
     // Create the item set that is normally passed to the insert frame dialog.
     SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
     SwFlyFrameAttrMgr aMgr(true, pWrtShell, Frmmgr_Type::TEXT, nullptr);
-    SfxItemSet aSet = aShell.CreateInsertFrameItemSet(aMgr);
+    auto xSet = aShell.CreateInsertFrameItemSet(aMgr);
 
     // This was missing along with the gradient and other tables.
-    CPPUNIT_ASSERT(aSet.HasItem(SID_COLOR_TABLE));
+    CPPUNIT_ASSERT(xSet->HasItem(SID_COLOR_TABLE));
 }
 
 CPPUNIT_TEST_FIXTURE(SwUiWriterTest7, testTdf78150)
diff --git a/sw/source/uibase/inc/textsh.hxx b/sw/source/uibase/inc/textsh.hxx
index f965370e08c6..5bafaa2ea16b 100644
--- a/sw/source/uibase/inc/textsh.hxx
+++ b/sw/source/uibase/inc/textsh.hxx
@@ -83,7 +83,7 @@ public:
              SwTextShell(SwView &rView);
     virtual ~SwTextShell() override;
     /// Create item set for the insert frame dialog.
-    SfxItemSet CreateInsertFrameItemSet(SwFlyFrameAttrMgr& rMgr);
+    std::shared_ptr<SfxItemSet> CreateInsertFrameItemSet(SwFlyFrameAttrMgr& 
rMgr);
 };
 
 #endif
diff --git a/sw/source/uibase/shells/textsh.cxx 
b/sw/source/uibase/shells/textsh.cxx
index 29242d99463b..59b571a289ca 100644
--- a/sw/source/uibase/shells/textsh.cxx
+++ b/sw/source/uibase/shells/textsh.cxx
@@ -522,7 +522,7 @@ void SwTextShell::ExecInsert(SfxRequest &rReq)
         }
         else
         {
-            SfxItemSet aSet = CreateInsertFrameItemSet(aMgr);
+            auto xSet = CreateInsertFrameItemSet(aMgr);
 
             FieldUnit eMetric = ::GetDfltMetric(dynamic_cast<SwWebDocShell*>( 
GetView().GetDocShell()) != nullptr );
             SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< 
sal_uInt16 >(eMetric)));
@@ -530,8 +530,8 @@ void SwTextShell::ExecInsert(SfxRequest &rReq)
             VclPtr<SfxAbstractTabDialog> 
pDlg(pFact->CreateFrameTabDialog("FrameDialog",
                                                   GetView().GetViewFrame(),
                                                   GetView().GetFrameWeld(),
-                                                  aSet));
-            pDlg->StartExecuteAsync([aSet, pDlg, nSlot, this](sal_Int32 
nResult) {
+                                                  *xSet));
+            pDlg->StartExecuteAsync([xSet=std::move(xSet), pDlg, nSlot, 
this](sal_Int32 nResult) {
                 if (nResult == RET_OK && pDlg->GetOutputItemSet())
                 {
                     SwFlyFrameAttrMgr aAttrMgr( true, GetShellPtr(), 
Frmmgr_Type::TEXT, nullptr );
@@ -542,7 +542,7 @@ void SwTextShell::ExecInsert(SfxRequest &rReq)
                     rShell.StartUndo(SwUndoId::INSERT);
 
                     SfxItemSet aOutSet(*pDlg->GetOutputItemSet());
-                    const SvxBoxItem* pBox = aSet.GetItem(RES_BOX);
+                    const SvxBoxItem* pBox = xSet->GetItem(RES_BOX);
                     if (pBox && !aOutSet.HasItem(RES_BOX))
                     {
                         // The input set had border info but the output set 
not, then copy it over
@@ -907,9 +907,9 @@ SwTextShell::~SwTextShell()
 {
 }
 
-SfxItemSet SwTextShell::CreateInsertFrameItemSet(SwFlyFrameAttrMgr& rMgr)
+std::shared_ptr<SfxItemSet> 
SwTextShell::CreateInsertFrameItemSet(SwFlyFrameAttrMgr& rMgr)
 {
-    SfxItemSet aSet(GetPool(), svl::Items<
+    auto xSet = std::make_shared<SfxItemSet>(GetPool(), svl::Items<
         RES_FRMATR_BEGIN,       RES_FRMATR_END-1,
         XATTR_FILL_FIRST,       XATTR_FILL_LAST, // tdf#95003
         SID_ATTR_BORDER_INNER,  SID_ATTR_BORDER_INNER,
@@ -918,38 +918,38 @@ SfxItemSet 
SwTextShell::CreateInsertFrameItemSet(SwFlyFrameAttrMgr& rMgr)
         SID_HTML_MODE,          SID_HTML_MODE,
         FN_GET_PRINT_AREA,      FN_GET_PRINT_AREA,
         FN_SET_FRM_NAME,        FN_SET_FRM_NAME>);
-    aSet.Put(SfxUInt16Item(SID_HTML_MODE, 
::GetHtmlMode(GetView().GetDocShell())));
+    xSet->Put(SfxUInt16Item(SID_HTML_MODE, 
::GetHtmlMode(GetView().GetDocShell())));
 
     // For the Area tab page.
-    
GetShell().GetDoc()->getIDocumentDrawModelAccess().GetDrawModel()->PutAreaListItems(aSet);
+    
GetShell().GetDoc()->getIDocumentDrawModelAccess().GetDrawModel()->PutAreaListItems(*xSet);
 
     const SwRect &rPg = GetShell().GetAnyCurRect(CurRectType::Page);
     SwFormatFrameSize aFrameSize(SwFrameSize::Variable, rPg.Width(), 
rPg.Height());
     aFrameSize.SetWhich(GetPool().GetWhich(SID_ATTR_PAGE_SIZE));
-    aSet.Put(aFrameSize);
+    xSet->Put(aFrameSize);
 
     const SwRect &rPr = GetShell().GetAnyCurRect(CurRectType::PagePrt);
     SwFormatFrameSize aPrtSize(SwFrameSize::Variable, rPr.Width(), 
rPr.Height());
     aPrtSize.SetWhich(GetPool().GetWhich(FN_GET_PRINT_AREA));
-    aSet.Put(aPrtSize);
+    xSet->Put(aPrtSize);
 
-    aSet.Put(rMgr.GetAttrSet());
-    aSet.SetParent( rMgr.GetAttrSet().GetParent() );
+    xSet->Put(rMgr.GetAttrSet());
+    xSet->SetParent( rMgr.GetAttrSet().GetParent() );
 
     // Delete minimum size in columns.
-    SvxBoxInfoItem aBoxInfo(aSet.Get(SID_ATTR_BORDER_INNER));
-    const SvxBoxItem& rBox = aSet.Get(RES_BOX);
+    SvxBoxInfoItem aBoxInfo(xSet->Get(SID_ATTR_BORDER_INNER));
+    const SvxBoxItem& rBox = xSet->Get(RES_BOX);
     aBoxInfo.SetMinDist(false);
     aBoxInfo.SetDefDist(rBox.GetDistance(SvxBoxItemLine::LEFT));
-    aSet.Put(aBoxInfo);
+    xSet->Put(aBoxInfo);
 
     if (!SwFlyFrameAttrMgr::SingleTableSelected(GetShell()))
     {
         SwFormatAnchor aAnchor(RndStdIds::FLY_AT_CHAR);
-        aSet.Put(aAnchor);
+        xSet->Put(aAnchor);
     }
 
-    return aSet;
+    return xSet;
 }
 
 void SwTextShell::InsertSymbol( SfxRequest& rReq )

Reply via email to