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 7b7347bb2112d89b2ad463a464cabe0c8926e0d0 Author: Patrick Luby <[email protected]> AuthorDate: Wed Aug 7 19:51:57 2024 -0400 Commit: Patrick Luby <[email protected]> CommitDate: Fri Aug 9 16:33:51 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 <[email protected]> Reviewed-by: Miklos Vajna <[email protected]> Tested-by: Jenkins diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx index 2b79bb6033f8..2652b56882f9 100644 --- a/sw/inc/doc.hxx +++ b/sw/inc/doc.hxx @@ -248,6 +248,7 @@ class 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 b048e8238aae..9f2331e89026 100644 --- a/sw/source/core/doc/docfmt.cxx +++ b/sw/source/core/doc/docfmt.cxx @@ -696,7 +696,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 02bce7f64017..51a8a3ddd487 100644 --- a/sw/source/core/doc/docnew.cxx +++ b/sw/source/core/doc/docnew.cxx @@ -236,6 +236,7 @@ SwDoc::SwDoc() mpDfltGrfFormatColl( new SwGrfFormatColl( GetAttrPool(), u"Graphikformatvorlage"_ustr ) ), mpFrameFormatTable( new sw::FrameFormats<SwFrameFormat*>() ), mpCharFormatTable( new SwCharFormats ), + mpCharFormatDeletionTable( new SwCharFormats ), mpSpzFrameFormatTable( new sw::FrameFormats<sw::SpzFrameFormat*>() ), mpSectionFormatTable( new SwSectionFormats ), mpTableFrameFormatTable( new sw::TableFrameFormats() ), @@ -594,6 +595,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(); @@ -748,6 +753,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() ) {
