[Libreoffice-commits] core.git: include/sfx2 sfx2/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Mon Oct 7 08:28:39 UTC 2019


 include/sfx2/docinsert.hxx    |    2 +-
 sfx2/source/doc/docinsert.cxx |   29 +++++++++++++++++------------
 2 files changed, 18 insertions(+), 13 deletions(-)

New commits:
commit 8f6f9e4217d03d874fb1ce391730a1c893ab6844
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Mon Oct 7 09:40:41 2019 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Mon Oct 7 10:28:03 2019 +0200

    tdf#127958 crash adding 2 or more files into writer master document
    
    clean up the memory management here, the SfxMedium wants to own the
    passed-in SfxItemSet
    
    Change-Id: I1bafa520ca7b833c4d2df7593649c3720c46e2ce
    Reviewed-on: https://gerrit.libreoffice.org/80332
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/sfx2/docinsert.hxx b/include/sfx2/docinsert.hxx
index 56c16ac2653b..0148b854fed2 100644
--- a/include/sfx2/docinsert.hxx
+++ b/include/sfx2/docinsert.hxx
@@ -50,7 +50,7 @@ private:
 
     std::unique_ptr<sfx2::FileDialogHelper>
                             m_pFileDlg;
-    SfxItemSet*             m_pItemSet;
+    std::unique_ptr<SfxItemSet> m_xItemSet;
     std::vector<OUString>   m_pURLList;
 
     DECL_LINK(DialogClosedHdl, sfx2::FileDialogHelper*, void);
diff --git a/sfx2/source/doc/docinsert.cxx b/sfx2/source/doc/docinsert.cxx
index b24806a1b460..ec25e6a39fd5 100644
--- a/sfx2/source/doc/docinsert.cxx
+++ b/sfx2/source/doc/docinsert.cxx
@@ -79,7 +79,6 @@ DocumentInserter::DocumentInserter(weld::Window* pParent, const OUString& rFacto
     , m_sDocFactory             ( rFactory )
     , m_nDlgFlags               ( lcl_map_mode_to_flags(mode) )
     , m_nError                  ( ERRCODE_NONE )
-    , m_pItemSet                ( nullptr )
 {
 }
 
@@ -103,12 +102,15 @@ void DocumentInserter::StartExecuteModal( const Link<sfx2::FileDialogHelper*,voi
 std::unique_ptr<SfxMedium> DocumentInserter::CreateMedium(char const*const pFallbackHack)
 {
     std::unique_ptr<SfxMedium> pMedium;
-    if (!m_nError && m_pItemSet && !m_pURLList.empty())
+    if (!m_nError && m_xItemSet && !m_pURLList.empty())
     {
         DBG_ASSERT( m_pURLList.size() == 1, "DocumentInserter::CreateMedium(): invalid URL list count" );
+        std::unique_ptr<SfxItemSet> xItemSet;
+        if (m_xItemSet)
+            xItemSet = std::make_unique<SfxItemSet>(*m_xItemSet);
         pMedium.reset(new SfxMedium(
                 m_pURLList[0], SFX_STREAM_READONLY,
-                SfxGetpApp()->GetFilterMatcher().GetFilter4FilterName( m_sFilter ), std::unique_ptr<SfxItemSet>(m_pItemSet) ));
+                SfxGetpApp()->GetFilterMatcher().GetFilter4FilterName( m_sFilter ), std::move(xItemSet) ));
         pMedium->UseInteractionHandler( true );
         std::unique_ptr<SfxFilterMatcher> pMatcher;
         if ( !m_sDocFactory.isEmpty() )
@@ -139,13 +141,16 @@ std::unique_ptr<SfxMedium> DocumentInserter::CreateMedium(char const*const pFall
 SfxMediumList DocumentInserter::CreateMediumList()
 {
     SfxMediumList aMediumList;
-    if (!m_nError && m_pItemSet && !m_pURLList.empty())
+    if (!m_nError && m_xItemSet && !m_pURLList.empty())
     {
         for (auto const& url : m_pURLList)
         {
+            std::unique_ptr<SfxItemSet> xItemSet;
+            if (m_xItemSet)
+                xItemSet = std::make_unique<SfxItemSet>(*m_xItemSet);
             std::unique_ptr<SfxMedium> pMedium(new SfxMedium(
                     url, SFX_STREAM_READONLY,
-                    SfxGetpApp()->GetFilterMatcher().GetFilter4FilterName( m_sFilter ), std::unique_ptr<SfxItemSet>(m_pItemSet) ));
+                    SfxGetpApp()->GetFilterMatcher().GetFilter4FilterName( m_sFilter ), std::move(xItemSet) ));
 
             pMedium->UseInteractionHandler( true );
 
@@ -196,7 +201,7 @@ IMPL_LINK_NOARG(DocumentInserter, DialogClosedHdl, sfx2::FileDialogHelper*, void
     if ( xCtrlAccess.is() )
     {
         // always create a new itemset
-        m_pItemSet = new SfxAllItemSet( SfxGetpApp()->GetPool() );
+        m_xItemSet.reset(new SfxAllItemSet( SfxGetpApp()->GetPool() ));
 
         short nDlgType = m_pFileDlg->GetDialogType();
         bool bHasPassword = (
@@ -218,11 +223,11 @@ IMPL_LINK_NOARG(DocumentInserter, DialogClosedHdl, sfx2::FileDialogHelper*, void
                     short nRet = aPasswordDlg.run();
                     if ( RET_OK == nRet )
                     {
-                        m_pItemSet->Put( SfxStringItem( SID_PASSWORD, aPasswordDlg.GetPassword() ) );
+                        m_xItemSet->Put( SfxStringItem( SID_PASSWORD, aPasswordDlg.GetPassword() ) );
                     }
                     else
                     {
-                        DELETEZ( m_pItemSet );
+                        m_xItemSet.reset();
                         return;
                     }
                 }
@@ -237,7 +242,7 @@ IMPL_LINK_NOARG(DocumentInserter, DialogClosedHdl, sfx2::FileDialogHelper*, void
                 Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_SELECTION, 0 );
                 bool bSelection = false;
                 if ( aValue >>= bSelection )
-                    m_pItemSet->Put( SfxBoolItem( SID_SELECTION, bSelection ) );
+                    m_xItemSet->Put( SfxBoolItem( SID_SELECTION, bSelection ) );
             }
             catch( const IllegalArgumentException& )
             {
@@ -248,7 +253,7 @@ IMPL_LINK_NOARG(DocumentInserter, DialogClosedHdl, sfx2::FileDialogHelper*, void
 
         // set the read-only flag. When inserting a file, this flag is always set
         if ( m_nDlgFlags & FileDialogFlags::Insert )
-            m_pItemSet->Put( SfxBoolItem( SID_DOC_READONLY, true ) );
+            m_xItemSet->Put( SfxBoolItem( SID_DOC_READONLY, true ) );
         else
         {
             if ( TemplateDescription::FILEOPEN_READONLY_VERSION == nDlgType )
@@ -258,7 +263,7 @@ IMPL_LINK_NOARG(DocumentInserter, DialogClosedHdl, sfx2::FileDialogHelper*, void
                     Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_READONLY, 0 );
                     bool bReadOnly = false;
                     if ( ( aValue >>= bReadOnly ) && bReadOnly )
-                        m_pItemSet->Put( SfxBoolItem( SID_DOC_READONLY, bReadOnly ) );
+                        m_xItemSet->Put( SfxBoolItem( SID_DOC_READONLY, bReadOnly ) );
                 }
                 catch( const IllegalArgumentException& )
                 {
@@ -276,7 +281,7 @@ IMPL_LINK_NOARG(DocumentInserter, DialogClosedHdl, sfx2::FileDialogHelper*, void
                 sal_Int32 nVersion = 0;
                 if ( ( aValue >>= nVersion ) && nVersion > 0 )
                     // open a special version; 0 == current version
-                    m_pItemSet->Put( SfxInt16Item( SID_VERSION, static_cast<short>(nVersion) ) );
+                    m_xItemSet->Put( SfxInt16Item( SID_VERSION, static_cast<short>(nVersion) ) );
             }
             catch( const IllegalArgumentException& ){}
         }


More information about the Libreoffice-commits mailing list