From 0467033855b2f0b51178c9f2ba8d3afc6798a3cb Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 3 Jan 2017 10:58:52 +0200 Subject: [PATCH] Fix potential memory leak. --HG-- branch : develop --- src/libs/ifc/xml/vabstractpattern.cpp | 4 ++-- src/libs/ifc/xml/vpatternconverter.cpp | 4 ++-- src/libs/qmuparser/qmutokenparser.cpp | 7 +++---- src/libs/vpatterndb/vtranslatevars.cpp | 7 +++---- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 169abd868..e1e5071c5 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -185,9 +185,9 @@ QStringList VAbstractPattern::ListMeasurements() const const QStringList expressions = ListExpressions(); for (int i=0; i < expressions.size(); ++i) { - qmu::QmuTokenParser *cal = new qmu::QmuTokenParser(expressions.at(i), false, false);// Eval formula + QScopedPointer cal(new qmu::QmuTokenParser(expressions.at(i), false, false));// Eval formula const QMap tokens = cal->GetTokens();// Tokens (variables, measurements) - delete cal; + delete cal.take(); const QList tValues = tokens.values(); for (int j = 0; j < tValues.size(); ++j) diff --git a/src/libs/ifc/xml/vpatternconverter.cpp b/src/libs/ifc/xml/vpatternconverter.cpp index 6fff85b5a..189c90d53 100644 --- a/src/libs/ifc/xml/vpatternconverter.cpp +++ b/src/libs/ifc/xml/vpatternconverter.cpp @@ -854,9 +854,9 @@ void VPatternConverter::ConvertPathPointExpressionsToV0_2_0(const QMap &names) { - qmu::QmuTokenParser *cal = new qmu::QmuTokenParser(formula, false, false);// Eval formula + QScopedPointer cal(new qmu::QmuTokenParser(formula, false, false));// Eval formula QMap tokens = cal->GetTokens();// Tokens (variables, measurements) - delete cal; + delete cal.take(); QList tKeys = tokens.keys();// Take all tokens positions QList tValues = tokens.values(); diff --git a/src/libs/qmuparser/qmutokenparser.cpp b/src/libs/qmuparser/qmutokenparser.cpp index 85f03c520..47bc6cbe3 100644 --- a/src/libs/qmuparser/qmutokenparser.cpp +++ b/src/libs/qmuparser/qmutokenparser.cpp @@ -88,11 +88,11 @@ bool QmuTokenParser::IsSingle(const QString &formula) return false;// if don't know say no } - QmuTokenParser *cal = new QmuTokenParser(); + QScopedPointer cal(new QmuTokenParser()); // Parser doesn't know any variable on this stage. So, we just use variable factory that for each unknown // variable set value to 0. - cal->SetVarFactory(AddVariable, cal); + cal->SetVarFactory(AddVariable, cal.data()); cal->SetSepForEval();//Reset separators options try @@ -108,8 +108,7 @@ bool QmuTokenParser::IsSingle(const QString &formula) QMap tokens = cal->GetTokens();// Tokens (variables, measurements) const QMap numbers = cal->GetNumbers();// All numbers in expression - - delete cal; + delete cal.take(); // Remove "-" from tokens list if exist. If don't do that unary minus operation will broken. RemoveAll(tokens, QStringLiteral("-")); diff --git a/src/libs/vpatterndb/vtranslatevars.cpp b/src/libs/vpatterndb/vtranslatevars.cpp index ac20fb359..9328a70d6 100644 --- a/src/libs/vpatterndb/vtranslatevars.cpp +++ b/src/libs/vpatterndb/vtranslatevars.cpp @@ -727,10 +727,10 @@ QString VTranslateVars::FormulaFromUser(const QString &formula, bool osSeparator } QString newFormula = formula;// Local copy for making changes - qmu::QmuTokenParser *cal = new qmu::QmuTokenParser(formula, osSeparator);// Eval formula + QScopedPointer cal(new qmu::QmuTokenParser(formula, osSeparator));// Eval formula QMap tokens = cal->GetTokens();// Tokens (variables, measurements) QMap numbers = cal->GetNumbers();// All numbers in expression for changing decimal separator - delete cal; + delete cal.take(); QList tKeys = tokens.keys();// Take all tokens positions QList tValues = tokens.values(); @@ -848,10 +848,9 @@ QString VTranslateVars::FormulaToUser(const QString &formula, bool osSeparator) QMap numbers; try { - qmu::QmuTokenParser *cal = new qmu::QmuTokenParser(formula, false);// Eval formula + QScopedPointer cal(new qmu::QmuTokenParser(formula, false, false));// Eval formula tokens = cal->GetTokens();// Tokens (variables, measurements) numbers = cal->GetNumbers();// All numbers in expression for changing decimal separator - delete cal; } catch (qmu::QmuParserError &e) {