sw/inc/doc.hxx                |    1 +
 sw/source/core/doc/docfmt.cxx |    3 ++-
 sw/source/core/doc/docnew.cxx |    6 ++++++
 3 files changed, 9 insertions(+), 1 deletion(-)

New commits:
commit 23829f6e1cebf808f4e6ff6ed4856123ad8e8e38
Author:     Patrick Luby <guibmac...@gmail.com>
AuthorDate: Wed Aug 7 19:51:57 2024 -0400
Commit:     Adolfo Jayme Barrientos <fit...@ubuntu.com>
CommitDate: Mon Aug 12 09:21:57 2024 +0200

    tdf#140061 keep SwCharFormat instances alive while SwDoc is alive
    
    Change-Id: I22a7fc1e109e641932f348e9ac3b85f11ce46c9d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171608
    Reviewed-by: Patrick Luby <guibomac...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins
    (cherry picked from commit 7b7347bb2112d89b2ad463a464cabe0c8926e0d0)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171677
    Reviewed-by: Adolfo Jayme Barrientos <fit...@ubuntu.com>

diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index b5028561fb66..17f0ce4ea36f 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -248,6 +248,7 @@ class SW_DLLPUBLIC SwDoc final
 
     std::unique_ptr<sw::FrameFormats<SwFrameFormat*>>    mpFrameFormatTable;   
 //< Format table
     std::unique_ptr<SwCharFormats>     mpCharFormatTable;
+    std::unique_ptr<SwCharFormats>     mpCharFormatDeletionTable;
     std::unique_ptr<sw::FrameFormats<sw::SpzFrameFormat*>>    
mpSpzFrameFormatTable;
     std::unique_ptr<SwSectionFormats>  mpSectionFormatTable;
     std::unique_ptr<sw::TableFrameFormats>    mpTableFrameFormatTable; //< For 
tables
diff --git a/sw/source/core/doc/docfmt.cxx b/sw/source/core/doc/docfmt.cxx
index 3390a506052c..755ee2541fde 100644
--- a/sw/source/core/doc/docfmt.cxx
+++ b/sw/source/core/doc/docfmt.cxx
@@ -691,7 +691,8 @@ void SwDoc::DelCharFormat(size_t nFormat, bool bBroadcast)
             std::make_unique<SwUndoCharFormatDelete>(pDel, *this));
     }
 
-    delete (*mpCharFormatTable)[nFormat];
+    // tdf#140061 keep SwCharFormat instances alive while SwDoc is alive
+    mpCharFormatDeletionTable->insert(pDel);
     mpCharFormatTable->erase(mpCharFormatTable->begin() + nFormat);
 
     getIDocumentState().SetModified();
diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx
index d6e885e8219a..3c1adbd3012e 100644
--- a/sw/source/core/doc/docnew.cxx
+++ b/sw/source/core/doc/docnew.cxx
@@ -234,6 +234,7 @@ SwDoc::SwDoc()
     mpDfltGrfFormatColl( new SwGrfFormatColl( GetAttrPool(), 
"Graphikformatvorlage" ) ),
     mpFrameFormatTable( new sw::FrameFormats<SwFrameFormat*>() ),
     mpCharFormatTable( new SwCharFormats ),
+    mpCharFormatDeletionTable( new SwCharFormats ),
     mpSpzFrameFormatTable( new sw::FrameFormats<sw::SpzFrameFormat*>() ),
     mpSectionFormatTable( new SwSectionFormats ),
     mpTableFrameFormatTable( new sw::TableFrameFormats() ),
@@ -591,6 +592,10 @@ SwDoc::~SwDoc()
     mpStyleAccess.reset();
 
     mpCharFormatTable.reset();
+    // tdf#140061 keep SwCharFormat instances alive while SwDoc is alive
+    if (mpCharFormatDeletionTable)
+        mpCharFormatDeletionTable->DeleteAndDestroyAll(/*keepDefault*/false);
+    mpCharFormatDeletionTable.reset();
     mpSectionFormatTable.reset();
     mpTableFrameFormatTable.reset();
     mpDfltTextFormatColl.reset();
@@ -745,6 +750,7 @@ void SwDoc::ClearDoc()
     mpTextFormatCollTable->DeleteAndDestroy(1, mpTextFormatCollTable->size());
     mpGrfFormatCollTable->DeleteAndDestroy(1, mpGrfFormatCollTable->size());
     mpCharFormatTable->DeleteAndDestroyAll(/*keepDefault*/true);
+    mpCharFormatDeletionTable->DeleteAndDestroyAll(/*keepDefault*/false);
 
     if( getIDocumentLayoutAccess().GetCurrentViewShell() )
     {

Reply via email to