From 15717e4349d5ecb58d3449bb3a21c1edc5f6ea60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Fri, 1 Dec 2017 14:39:27 +0100 Subject: [PATCH] [poincare] Fix leak in multiplication::distributeOnOperandAtIndex Change-Id: Iba88f1c80a68b5b5c34d8448717e9b492f94c451 --- poincare/src/multiplication.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/poincare/src/multiplication.cpp b/poincare/src/multiplication.cpp index 49048bad1..69e2afa02 100644 --- a/poincare/src/multiplication.cpp +++ b/poincare/src/multiplication.cpp @@ -437,11 +437,12 @@ Expression * Multiplication::distributeOnOperandAtIndex(int i, Context & context // This function turns a*(b+c) into a*b + a*c // We avoid deleting and creating a new addition Addition * a = static_cast(editableOperand(i)); + removeOperand(a, false); for (int j = 0; j < a->numberOfOperands(); j++) { + Multiplication * m = static_cast(clone()); Expression * termJ = a->editableOperand(j); - replaceOperand(operand(i), termJ->clone(), false); - Expression * m = clone(); - a->replaceOperand(termJ, m, true); + a->replaceOperand(termJ, m, false); + m->addOperand(termJ); m->shallowReduce(context, angleUnit); // pi^(-1)*(pi + x) -> pi^(-1)*pi + pi^(-1)*x -> 1 + pi^(-1)*x } replaceWith(a, true);