diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2013-11-04 20:36:53 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@collabora.com> | 2013-11-06 20:40:21 -0500 |
commit | df8257faf64b01f3de26277742195693ddfe29fc (patch) | |
tree | 344e21796463d80d6fdb450864bceba9bdf5d8a7 /sc | |
parent | 55107688ea606d229ccdb12df6e570ae02db1999 (diff) |
Check all call sites of CompileString() and make sure we don't leak.
We *were* leaking quite a bit.
Change-Id: I3f53eff22beab27b34a055a4452311f2e2f771db
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/compiler.hxx | 9 | ||||
-rw-r--r-- | sc/source/filter/excel/xechart.cxx | 4 | ||||
-rw-r--r-- | sc/source/filter/oox/formulabuffer.cxx | 2 | ||||
-rw-r--r-- | sc/source/ui/miscdlgs/anyrefdg.cxx | 8 | ||||
-rw-r--r-- | sc/source/ui/vba/vbaname.cxx | 6 | ||||
-rw-r--r-- | sc/source/ui/vba/vbanames.cxx | 4 | ||||
-rw-r--r-- | sc/source/ui/vba/vbarange.cxx | 7 | ||||
-rw-r--r-- | sc/source/ui/view/tabvwsha.cxx | 4 | ||||
-rw-r--r-- | sc/source/ui/view/viewfun4.cxx | 9 |
9 files changed, 37 insertions, 16 deletions
diff --git a/sc/inc/compiler.hxx b/sc/inc/compiler.hxx index 28e4efebf013..c16f749cbeec 100644 --- a/sc/inc/compiler.hxx +++ b/sc/inc/compiler.hxx @@ -431,7 +431,14 @@ public: bool IsCorrected() { return bCorrected; } const OUString& GetCorrectedFormula() { return aCorrectedFormula; } - // Use convention from this->aPos by default + /** + * Tokenize formula expression string into an array of tokens. + * + * @param rFormula formula expression to tokenize. + * + * @return heap allocated token array object. The caller <i>must</i> + * manage the life cycle of this object. + */ ScTokenArray* CompileString( const OUString& rFormula ); ScTokenArray* CompileString( const OUString& rFormula, const OUString& rFormulaNmsp ); const ScDocument* GetDoc() const { return pDoc; } diff --git a/sc/source/filter/excel/xechart.cxx b/sc/source/filter/excel/xechart.cxx index e25e0d2cfc45..26deac38d176 100644 --- a/sc/source/filter/excel/xechart.cxx +++ b/sc/source/filter/excel/xechart.cxx @@ -70,6 +70,8 @@ #include "xepage.hxx" #include "xestyle.hxx" +#include <boost/scoped_ptr.hpp> + using ::com::sun::star::uno::Any; using ::com::sun::star::uno::Reference; using ::com::sun::star::uno::Sequence; @@ -917,7 +919,7 @@ sal_uInt16 XclExpChSourceLink::ConvertDataSequence( Reference< XDataSequence > x OUString aRangeRepr = xDataSeq->getSourceRangeRepresentation(); ScCompiler aComp( GetDocPtr(), ScAddress() ); aComp.SetGrammar( GetDocPtr()->GetGrammar() ); - ScTokenArray* pArray = aComp.CompileString( aRangeRepr ); + boost::scoped_ptr<ScTokenArray> pArray(aComp.CompileString(aRangeRepr)); if( !pArray ) return nDefCount; diff --git a/sc/source/filter/oox/formulabuffer.cxx b/sc/source/filter/oox/formulabuffer.cxx index 6022ae7c95ca..cf5b73eec4e7 100644 --- a/sc/source/filter/oox/formulabuffer.cxx +++ b/sc/source/filter/oox/formulabuffer.cxx @@ -211,7 +211,7 @@ void FormulaBuffer::applyArrayFormulas( const std::vector< TokenRangeAddressItem ScCompiler aComp(&rDocImport.getDoc(), aPos); aComp.SetGrammar(formula::FormulaGrammar::GRAM_ENGLISH_XL_OOX); - ScTokenArray* pArray = aComp.CompileString(it->maTokenAndAddress.maTokenStr); + boost::scoped_ptr<ScTokenArray> pArray(aComp.CompileString(it->maTokenAndAddress.maTokenStr)); if (pArray) rDocImport.setMatrixCells(aRange, *pArray, formula::FormulaGrammar::GRAM_ENGLISH_XL_OOX); } diff --git a/sc/source/ui/miscdlgs/anyrefdg.cxx b/sc/source/ui/miscdlgs/anyrefdg.cxx index a94369211044..17560892932e 100644 --- a/sc/source/ui/miscdlgs/anyrefdg.cxx +++ b/sc/source/ui/miscdlgs/anyrefdg.cxx @@ -43,6 +43,8 @@ #include "rangeutl.hxx" #include "tokenarray.hxx" +#include <boost/scoped_ptr.hpp> + ScFormulaReferenceHelper::ScFormulaReferenceHelper(IAnyRefDialog* _pDlg,SfxBindings* _pBindings) : m_pDlg(_pDlg) , pRefEdit (NULL) @@ -186,10 +188,9 @@ void ScFormulaReferenceHelper::ShowFormulaReference(const OUString& rStr) SCTAB nTab = pViewData->GetTabNo(); ScAddress aPos( nCol, nRow, nTab ); - ScTokenArray* pScTokA=pRefComp->CompileString(rStr); - //pRefComp->CompileTokenArray(); + boost::scoped_ptr<ScTokenArray> pScTokA(pRefComp->CompileString(rStr)); - if(pTabViewShell!=NULL && pScTokA!=NULL) + if (pTabViewShell && pScTokA) { pTabViewShell->DoneRefMode( false ); pTabViewShell->ClearHighlightRanges(); @@ -225,7 +226,6 @@ void ScFormulaReferenceHelper::ShowFormulaReference(const OUString& rStr) pToken = static_cast<const ScToken*>(pScTokA->GetNextReference()); } } - if(pScTokA!=NULL) delete pScTokA; } } } diff --git a/sc/source/ui/vba/vbaname.cxx b/sc/source/ui/vba/vbaname.cxx index fc5592b75276..3c3d44859750 100644 --- a/sc/source/ui/vba/vbaname.cxx +++ b/sc/source/ui/vba/vbaname.cxx @@ -34,6 +34,8 @@ #include "compiler.hxx" #include "tokenarray.hxx" +#include <boost/scoped_ptr.hpp> + using namespace ::ooo::vba; using namespace ::com::sun::star; @@ -135,8 +137,8 @@ void ScVbaName::setContent( const OUString& rContent, const formula::FormulaGra // Shorter way of doing this ? ScCompiler aComp( pDoc, pOldData->GetPos() ); aComp.SetGrammar( eGrammar ); - ScTokenArray aArray(*aComp.CompileString( sContent ) ); - pOldData->SetCode( aArray ); + boost::scoped_ptr<ScTokenArray> pArray(aComp.CompileString(sContent)); + pOldData->SetCode(*pArray); } } } diff --git a/sc/source/ui/vba/vbanames.cxx b/sc/source/ui/vba/vbanames.cxx index eb1c4ab39662..c3001c4b7789 100644 --- a/sc/source/ui/vba/vbanames.cxx +++ b/sc/source/ui/vba/vbanames.cxx @@ -34,6 +34,8 @@ #include "tokenarray.hxx" #include "cellsuno.hxx" +#include <boost/scoped_ptr.hpp> + using namespace ::ooo::vba; using namespace ::com::sun::star; @@ -158,7 +160,7 @@ ScVbaNames::Add( const css::uno::Any& Name , ScAddress aBlank; ScCompiler aComp( getScDocument(), aBlank ); aComp.SetGrammar( eGram ); - ScTokenArray* pTokens = aComp.CompileString( sFormula ); + boost::scoped_ptr<ScTokenArray> pTokens(aComp.CompileString(sFormula)); if ( pTokens ) { ScRange aRange; diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx index b533561d4a42..a5517806b3ab 100644 --- a/sc/source/ui/vba/vbarange.cxx +++ b/sc/source/ui/vba/vbarange.cxx @@ -172,6 +172,9 @@ #include <com/sun/star/bridge/oleautomation/Date.hpp> #include "tokenarray.hxx" #include "tokenuno.hxx" + +#include <boost/scoped_ptr.hpp> + using namespace ::ooo::vba; using namespace ::com::sun::star; using ::std::vector; @@ -901,7 +904,7 @@ protected: ScCompiler aCompiler( m_pDoc, aCellRanges.front()->aStart ); aCompiler.SetGrammar(m_eGrammar); // compile the string in the format passed in - aCompiler.CompileString( sFormula ); + boost::scoped_ptr<ScTokenArray> pArray(aCompiler.CompileString(sFormula)); // set desired convention to that of the document aCompiler.SetGrammar( formula::FormulaGrammar::GRAM_PODF_A1 ); OUString sConverted; @@ -944,7 +947,7 @@ public: ScRangeList aCellRanges = pUnoRangesBase->GetRangeList(); ScCompiler aCompiler( m_pDoc, aCellRanges.front()->aStart ); aCompiler.SetGrammar(formula::FormulaGrammar::GRAM_DEFAULT); - aCompiler.CompileString( sVal ); + boost::scoped_ptr<ScTokenArray> pArray(aCompiler.CompileString(sVal)); // set desired convention aCompiler.SetGrammar( m_eGrammar ); OUString sConverted; diff --git a/sc/source/ui/view/tabvwsha.cxx b/sc/source/ui/view/tabvwsha.cxx index c8917fac9599..09f482bdc695 100644 --- a/sc/source/ui/view/tabvwsha.cxx +++ b/sc/source/ui/view/tabvwsha.cxx @@ -53,6 +53,8 @@ #include "cellvalue.hxx" #include "tokenarray.hxx" +#include <boost/scoped_ptr.hpp> + sal_Bool ScTabViewShell::GetFunction( OUString& rFuncStr, sal_uInt16 nErrCode ) { OUString aStr; @@ -565,7 +567,7 @@ bool ScTabViewShell::IsRefInputMode() const ScCompiler aComp( pDoc, aPos ); aComp.SetGrammar(pDoc->GetGrammar()); aComp.SetCloseBrackets( false ); - ScTokenArray* pArr = aComp.CompileString( aString ); + boost::scoped_ptr<ScTokenArray> pArr(aComp.CompileString(aString)); if ( pArr && pArr->MayReferenceFollow() ) { return true; diff --git a/sc/source/ui/view/viewfun4.cxx b/sc/source/ui/view/viewfun4.cxx index 8f140c89d10d..e924b34b0203 100644 --- a/sc/source/ui/view/viewfun4.cxx +++ b/sc/source/ui/view/viewfun4.cxx @@ -64,6 +64,7 @@ #include "dociter.hxx" #include "reffind.hxx" #include "compiler.hxx" +#include "tokenarray.hxx" #include <boost/scoped_ptr.hpp> @@ -257,9 +258,11 @@ void ScViewFunc::DoRefConversion( sal_Bool bRecord ) OUString aNew = aFinder.GetText(); ScCompiler aComp( pDoc, aPos); aComp.SetGrammar(pDoc->GetGrammar()); - ScTokenArray* pArr = aComp.CompileString( aNew ); - ScFormulaCell* pNewCell = new ScFormulaCell( pDoc, aPos, - pArr,formula::FormulaGrammar::GRAM_DEFAULT, MM_NONE ); + boost::scoped_ptr<ScTokenArray> pArr(aComp.CompileString(aNew)); + ScFormulaCell* pNewCell = + new ScFormulaCell( + pDoc, aPos, pArr.get(), formula::FormulaGrammar::GRAM_DEFAULT, MM_NONE); + pDoc->SetFormulaCell(aPos, pNewCell); bOk = true; } |