sw/source/core/unocore/unofield.cxx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
New commits: commit 6c065a2b031b16865238c96620b798aecad862f6 Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Sun Dec 18 21:12:24 2022 +0000 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Wed Dec 21 16:33:33 2022 +0000 crashtesting: related to failure on load of forum-en-7529.odt save SwDoc* before calling DeleteAndJoin, so SetFormatField doesn't use m_pImpl->m_pDoc potentially cleared by it Change-Id: Ia130f224fcccd35e1dfafbbaf5c461c9bd032f9d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144418 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> (cherry picked from commit d109630ec481b826ab5df728191694e9a67ce7a4) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144595 Reviewed-by: Michael Stahl <michael.st...@allotropia.de> Reviewed-by: Caolán McNamara <caol...@redhat.com> Tested-by: Caolán McNamara <caol...@redhat.com> diff --git a/sw/source/core/unocore/unofield.cxx b/sw/source/core/unocore/unofield.cxx index 53eb083e8156..945ee2dca67d 100644 --- a/sw/source/core/unocore/unofield.cxx +++ b/sw/source/core/unocore/unofield.cxx @@ -1999,7 +1999,8 @@ void SAL_CALL SwXTextField::attach( && m_pImpl->m_pDoc != nullptr && m_pImpl->m_nServiceId == SwServiceType::FieldTypeAnnotation ) { - SwUnoInternalPaM aIntPam( *m_pImpl->m_pDoc ); + SwDoc* pDoc = m_pImpl->m_pDoc; + SwUnoInternalPaM aIntPam( *pDoc ); if ( !::sw::XTextRangeToSwPaM( aIntPam, xTextRange ) ) throw lang::IllegalArgumentException(); @@ -2007,13 +2008,13 @@ void SAL_CALL SwXTextField::attach( // value. if (!aIntPam.HasMark() || *aIntPam.Start() != *aIntPam.End()) { - UnoActionContext aCont( m_pImpl->m_pDoc ); + UnoActionContext aCont( pDoc ); // insert copy of annotation at new text range std::unique_ptr<SwPostItField> pPostItField(static_cast< SwPostItField* >(m_pImpl->GetFormatField()->GetField()->CopyField().release())); SwFormatField aFormatField( *pPostItField ); pPostItField.reset(); SwPaM aEnd( *aIntPam.End(), *aIntPam.End() ); - m_pImpl->m_pDoc->getIDocumentContentOperations().InsertPoolItem( aEnd, aFormatField ); + pDoc->getIDocumentContentOperations().InsertPoolItem( aEnd, aFormatField ); // delete former annotation { const SwTextField* pTextField = m_pImpl->GetFormatField()->GetTextField(); @@ -2021,14 +2022,14 @@ void SAL_CALL SwXTextField::attach( SwPaM aPam( rTextNode, pTextField->GetStart() ); aPam.SetMark(); aPam.Move(); - m_pImpl->m_pDoc->getIDocumentContentOperations().DeleteAndJoin(aPam); + pDoc->getIDocumentContentOperations().DeleteAndJoin(aPam); } // keep inserted annotation { SwTextField* pTextAttr = aEnd.GetNode().GetTextNode()->GetFieldTextAttrAt( aEnd.End()->nContent.GetIndex()-1, true ); if ( pTextAttr != nullptr ) { - m_pImpl->SetFormatField(const_cast<SwFormatField*>(&pTextAttr->GetFormatField()), m_pImpl->m_pDoc); + m_pImpl->SetFormatField(const_cast<SwFormatField*>(&pTextAttr->GetFormatField()), pDoc); if ( *aIntPam.GetPoint() != *aIntPam.GetMark() ) {