From 35a9753609018768c9e5788ceb2dab16eeed81af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 24 Aug 2017 17:30:21 +0200 Subject: [PATCH] [poincare][apps] Memory leaks Change-Id: I2338760fb52bcf57997f7d82fd1f5cee68e95266 --- apps/calculation/calculation.cpp | 1 + poincare/src/complex_matrix.cpp | 4 +++- poincare/src/opposite.cpp | 8 ++++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/apps/calculation/calculation.cpp b/apps/calculation/calculation.cpp index 21066e263..52feb88f1 100644 --- a/apps/calculation/calculation.cpp +++ b/apps/calculation/calculation.cpp @@ -86,6 +86,7 @@ Evaluation * Calculation::output(Context * context) { Expression * exp = Expression::parse(m_outputText); if (exp != nullptr) { m_output = exp->evaluate(*context); + delete exp; } else { m_output = new Complex(Complex::Float(NAN)); } diff --git a/poincare/src/complex_matrix.cpp b/poincare/src/complex_matrix.cpp index 3619a7787..bf8c623dd 100644 --- a/poincare/src/complex_matrix.cpp +++ b/poincare/src/complex_matrix.cpp @@ -91,7 +91,9 @@ Evaluation * ComplexMatrix::templatedEvaluate(Context& context, Expression for (int i = 0; i < m_numberOfColumns*m_numberOfRows; i++) { values[i] = Complex::Cartesian(m_values[i].a(), m_values[i].b()); } - return new ComplexMatrix(values, m_numberOfRows, m_numberOfColumns); + Evaluation * result = new ComplexMatrix(values, m_numberOfRows, m_numberOfColumns); + delete [] values; + return result; } diff --git a/poincare/src/opposite.cpp b/poincare/src/opposite.cpp index 031032136..73bf68d75 100644 --- a/poincare/src/opposite.cpp +++ b/poincare/src/opposite.cpp @@ -62,10 +62,14 @@ Evaluation * Opposite::computeOnMatrix(Evaluation * m) { template Evaluation * Opposite::templatedEvaluate(Context& context, AngleUnit angleUnit) const { Evaluation * operandEvalutation = m_operand->evaluate(context, angleUnit); + Evaluation * result = nullptr; if (operandEvalutation->numberOfRows() == 1 && operandEvalutation->numberOfColumns() == 1) { - return new Complex(compute(*(operandEvalutation->complexOperand(0)))); + result = new Complex(compute(*(operandEvalutation->complexOperand(0)))); + } else { + result = computeOnMatrix(operandEvalutation); } - return computeOnMatrix(operandEvalutation); + delete operandEvalutation; + return result; } ExpressionLayout * Opposite::privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const {