Fix potential memory leak.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2017-01-03 10:58:52 +02:00
parent 86f4b21879
commit 0467033855
4 changed files with 10 additions and 12 deletions

View File

@ -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<qmu::QmuTokenParser> cal(new qmu::QmuTokenParser(expressions.at(i), false, false));// Eval formula
const QMap<int, QString> tokens = cal->GetTokens();// Tokens (variables, measurements)
delete cal;
delete cal.take();
const QList<QString> tValues = tokens.values();
for (int j = 0; j < tValues.size(); ++j)

View File

@ -854,9 +854,9 @@ void VPatternConverter::ConvertPathPointExpressionsToV0_2_0(const QMap<QString,
//---------------------------------------------------------------------------------------------------------------------
QString VPatternConverter::FixMeasurementInFormulaToV0_2_0(const QString &formula, const QMap<QString, QString> &names)
{
qmu::QmuTokenParser *cal = new qmu::QmuTokenParser(formula, false, false);// Eval formula
QScopedPointer<qmu::QmuTokenParser> cal(new qmu::QmuTokenParser(formula, false, false));// Eval formula
QMap<int, QString> tokens = cal->GetTokens();// Tokens (variables, measurements)
delete cal;
delete cal.take();
QList<int> tKeys = tokens.keys();// Take all tokens positions
QList<QString> tValues = tokens.values();

View File

@ -88,11 +88,11 @@ bool QmuTokenParser::IsSingle(const QString &formula)
return false;// if don't know say no
}
QmuTokenParser *cal = new QmuTokenParser();
QScopedPointer<QmuTokenParser> 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<int, QString> tokens = cal->GetTokens();// Tokens (variables, measurements)
const QMap<int, QString> 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("-"));

View File

@ -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<qmu::QmuTokenParser> cal(new qmu::QmuTokenParser(formula, osSeparator));// Eval formula
QMap<int, QString> tokens = cal->GetTokens();// Tokens (variables, measurements)
QMap<int, QString> numbers = cal->GetNumbers();// All numbers in expression for changing decimal separator
delete cal;
delete cal.take();
QList<int> tKeys = tokens.keys();// Take all tokens positions
QList<QString> tValues = tokens.values();
@ -848,10 +848,9 @@ QString VTranslateVars::FormulaToUser(const QString &formula, bool osSeparator)
QMap<int, QString> numbers;
try
{
qmu::QmuTokenParser *cal = new qmu::QmuTokenParser(formula, false);// Eval formula
QScopedPointer<qmu::QmuTokenParser> 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)
{