From 19910c461230f70bb9e98ad44db3525f0d755724 Mon Sep 17 00:00:00 2001 From: Julien Nabet Date: Thu, 28 Sep 2017 00:18:05 +0200 Subject: tdf#112658: fix leak when calling TextEngine::SetAttrib TextCharAttribList::RemoveAttrib lets a dangling pointer when release unique_ptr obj maAttribs[n] So retrieve a unique_ptr from the different layers until SentenceEditWindow_Impl::ChangeMarkedWord (SpellDialog.cxx). Change-Id: I734909dce86ec28d69c09b2a8c0fc4a6941f422a Reviewed-on: https://gerrit.libreoffice.org/42881 Reviewed-by: Noel Grandin Tested-by: Jenkins Reviewed-by: Michael Stahl --- cui/source/dialogs/SpellDialog.cxx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'cui') diff --git a/cui/source/dialogs/SpellDialog.cxx b/cui/source/dialogs/SpellDialog.cxx index 82c91910d130..57358d89ad3a 100644 --- a/cui/source/dialogs/SpellDialog.cxx +++ b/cui/source/dialogs/SpellDialog.cxx @@ -1643,11 +1643,14 @@ void SentenceEditWindow_Impl::ChangeMarkedWord(const OUString& rNewWord, Languag ExtTextEngine* pTextEngine = GetTextEngine(); pTextEngine->UndoActionStart(); const TextCharAttrib* pErrorAttrib = pTextEngine->FindCharAttrib( TextPaM(0, m_nErrorStart), TEXTATTR_SPELL_ERROR ); + std::unique_ptr pReleasedErrorAttrib; + std::unique_ptr pReleasedLangAttrib; + std::unique_ptr pReleasedBackAttrib; DBG_ASSERT(pErrorAttrib, "no error attribute found"); const SpellErrorDescription* pSpellErrorDescription = nullptr; if(pErrorAttrib) { - pTextEngine->RemoveAttrib(0, *pErrorAttrib); + pReleasedErrorAttrib = pTextEngine->RemoveAttrib(0, *pErrorAttrib); pSpellErrorDescription = &static_cast(pErrorAttrib->GetAttr()).GetErrorDescription(); } const TextCharAttrib* pBackAttrib = pTextEngine->FindCharAttrib( TextPaM(0, m_nErrorStart), TEXTATTR_SPELL_BACKGROUND ); @@ -1666,7 +1669,7 @@ void SentenceEditWindow_Impl::ChangeMarkedWord(const OUString& rNewWord, Languag nTextLen) { SpellLanguageAttrib aNewLangAttrib( static_cast(pLangAttrib->GetAttr()).GetLanguage()); - pTextEngine->RemoveAttrib(0, *pLangAttrib); + pReleasedLangAttrib = pTextEngine->RemoveAttrib(0, *pLangAttrib); pTextEngine->SetAttrib( aNewLangAttrib, 0, m_nErrorEnd + nDiffLen, nTextLen ); } } @@ -1675,7 +1678,7 @@ void SentenceEditWindow_Impl::ChangeMarkedWord(const OUString& rNewWord, Languag { std::unique_ptr pNewBackground(pBackAttrib->GetAttr().Clone()); const sal_Int32 nStart = pBackAttrib->GetStart(); - pTextEngine->RemoveAttrib(0, *pBackAttrib); + pReleasedBackAttrib = pTextEngine->RemoveAttrib(0, *pBackAttrib); pTextEngine->SetAttrib(*pNewBackground, 0, nStart, m_nErrorStart); } pTextEngine->SetModified(true); -- cgit