diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2019-03-12 12:20:56 +0100 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-03-12 18:55:49 +0100 |
commit | 661d22e86175fe919e956c9c6a1278d73758d54c (patch) | |
tree | 26514d2288ec35fc3255f735b54ec0df69b204bf /sc | |
parent | 1b75ec3a9de7491a16f3ac99b3a418251de16cb5 (diff) |
fix a possible ScTokenArray leak
To me it looks like pArr is leaked in the bAgain = true case, or the code
is rather misleading.
Change-Id: I41ea26052671f127141d5421d0c446da4606da28
Reviewed-on: https://gerrit.libreoffice.org/69091
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/ui/view/viewfunc.cxx | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx index 12b78243c34d..00c0678ba32c 100644 --- a/sc/source/ui/view/viewfunc.cxx +++ b/sc/source/ui/view/viewfunc.cxx @@ -409,17 +409,19 @@ void ScViewFunc::EnterData( SCCOL nCol, SCROW nRow, SCTAB nTab, aComp.SetExtendedErrorDetection( ScCompiler::EXTENDED_ERROR_DETECTION_NAME_BREAK ); } OUString aFormula( rString ); - ScTokenArray* pArr; + std::unique_ptr< ScTokenArray > pArr; bool bAgain; do { bAgain = false; bool bAddEqual = false; - ScTokenArray* pArrFirst = pArr = aComp.CompileString( aFormula ).release(); + pArr = aComp.CompileString( aFormula ); bool bCorrected = aComp.IsCorrected(); + std::unique_ptr< ScTokenArray > pArrFirst; if ( bCorrected ) { // try to parse with first parser-correction - pArr = aComp.CompileString( aComp.GetCorrectedFormula() ).release(); + pArrFirst = std::move( pArr ); + pArr = aComp.CompileString( aComp.GetCorrectedFormula() ); } if ( pArr->GetCodeError() == FormulaError::NONE ) { @@ -454,17 +456,12 @@ void ScViewFunc::EnterData( SCCOL nCol, SCROW nRow, SCTAB nTab, if ( nResult == RET_YES ) { aFormula = aCorrectedFormula; - if ( pArr != pArrFirst ) - delete pArrFirst; bAgain = true; } else { - if ( pArr != pArrFirst ) - { - delete pArr; - pArr = pArrFirst; - } + if ( pArrFirst ) + pArr = std::move( pArrFirst ); } } } while ( bAgain ); @@ -507,8 +504,7 @@ void ScViewFunc::EnterData( SCCOL nCol, SCROW nRow, SCTAB nTab, } } - ScFormulaCell aCell(pDoc, aPos, *pArr, formula::FormulaGrammar::GRAM_DEFAULT, ScMatrixMode::NONE); - delete pArr; + ScFormulaCell aCell(pDoc, aPos, std::move( pArr ), formula::FormulaGrammar::GRAM_DEFAULT, ScMatrixMode::NONE); SvNumberFormatter* pFormatter = pDoc->GetFormatTable(); for (const auto& rTab : rMark) |