sc/source/ui/view/viewfunc.cxx |   11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

New commits:
commit ffb4747aa6ee82791ce8a8ee35efaacd811f64d2
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Mon Oct 7 20:12:17 2024 +0100
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Tue Oct 8 10:37:39 2024 +0200

    Resolves: tdf#163275 crash in async dialog use after free
    
    since:
    
    commit b39c6082aa975ed8e5696c3dc24c3025ed07bbb6
    CommitDate: Wed Jan 31 10:33:48 2024 +0100
    
        Implement Async AutoCorrectQuery Dialogs for Formula Check in calc
    
    Change-Id: Ie184f72cfa858ed1fc6d9eb5205dea985767eec5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174645
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    Tested-by: Jenkins

diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx
index b207f7677282..b944d66aadae 100644
--- a/sc/source/ui/view/viewfunc.cxx
+++ b/sc/source/ui/view/viewfunc.cxx
@@ -143,7 +143,7 @@ struct FormulaProcessingContext
     std::shared_ptr<ScTokenArray> pArr;
     std::shared_ptr<ScTokenArray> pArrFirst;
 
-    const EditTextObject* pData;
+    std::shared_ptr<EditTextObject> xTextObject;
     ScMarkData aMark;
     ScViewFunc& rViewFunc;
 
@@ -558,10 +558,10 @@ namespace
             if (nType == SvNumFormatType::TEXT ||
                     ((context->aString[0] == '+' || context->aString[0] == 
'-') && nError != FormulaError::NONE && context->aString == context->aFormula))
             {
-                if ( context->pData )
+                if ( context->xTextObject )
                 {
-                    // A clone of context->pData will be stored in the cell.
-                    context->GetDocFunc().SetEditCell(*(context->aPos), 
*context->pData, true);
+                    // A clone of context->xTextObject will be stored in the 
cell.
+                    context->GetDocFunc().SetEditCell(*(context->aPos), 
*context->xTextObject, true);
                 }
                 else
                     context->GetDocFunc().SetStringCell(*(context->aPos), 
context->aFormula, true);
@@ -725,6 +725,7 @@ void ScViewFunc::EnterData( SCCOL nCol, SCROW nRow, SCTAB 
nTab,
         i = rMark.GetFirstSelected();
         auto aPosPtr = std::make_shared<ScAddress>(nCol, nRow, i);
         auto aCompPtr = std::make_shared<ScCompiler>(rDoc, *aPosPtr, 
rDoc.GetGrammar(), true, false);
+        std::unique_ptr<EditTextObject> xTextObject(pData ? pData->Clone() : 
nullptr);
 
         //2do: enable/disable autoCorrection via calcoptions
         aCompPtr->SetAutoCorrection( true );
@@ -736,7 +737,7 @@ void ScViewFunc::EnterData( SCCOL nCol, SCROW nRow, SCTAB 
nTab,
         OUString aFormula( rString );
 
         FormulaProcessingContext context_instance{
-            aPosPtr, aCompPtr, xModificator,  nullptr,        nullptr,        
pData,
+            aPosPtr, aCompPtr, xModificator,  nullptr,        nullptr,        
std::move(xTextObject),
             rMark,   *this,    OUString(),    aFormula,       rString,        
nCol,
             nRow,    nTab,     bMatrixExpand, bNumFmtChanged, bRecord
         };

Reply via email to