From 4f7658b2719fab77561d65c37bf06974ce5027db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 9 Feb 2017 09:47:43 +0100 Subject: [PATCH] [apps] Ensure to reset pointers when their content have been deleted Change-Id: I4c236c045cbe5e6ba215cbf56b27eba92133b675 --- apps/calculation/calculation.cpp | 4 ++++ apps/graph/values/values_controller.cpp | 2 +- apps/sequence/list/list_parameter_controller.cpp | 2 ++ apps/sequence/list/sequence_title_cell.cpp | 4 +++- apps/sequence/list/type_parameter_controller.cpp | 2 ++ apps/sequence/sequence.cpp | 4 ++++ apps/shared/curve_view.cpp | 2 +- apps/shared/function.cpp | 2 ++ 8 files changed, 19 insertions(+), 3 deletions(-) diff --git a/apps/calculation/calculation.cpp b/apps/calculation/calculation.cpp index 44dcf428f..0055b2b02 100644 --- a/apps/calculation/calculation.cpp +++ b/apps/calculation/calculation.cpp @@ -15,15 +15,19 @@ Calculation::Calculation() : Calculation::~Calculation() { if (m_inputLayout != nullptr) { delete m_inputLayout; + m_inputLayout = nullptr; } if (m_input != nullptr) { delete m_input; + m_input = nullptr; } if (m_output != nullptr) { delete m_output; + m_output = nullptr; } if (m_outputLayout != nullptr) { delete m_outputLayout; + m_outputLayout = nullptr; } } diff --git a/apps/graph/values/values_controller.cpp b/apps/graph/values/values_controller.cpp index c70e8f66b..a00b5d705 100644 --- a/apps/graph/values/values_controller.cpp +++ b/apps/graph/values/values_controller.cpp @@ -1,7 +1,7 @@ #include "values_controller.h" +#include "../app.h" #include "../../constant.h" #include "../../apps_container.h" -#include "../app.h" #include using namespace Poincare; diff --git a/apps/sequence/list/list_parameter_controller.cpp b/apps/sequence/list/list_parameter_controller.cpp index 65da9d4b9..0b1088907 100644 --- a/apps/sequence/list/list_parameter_controller.cpp +++ b/apps/sequence/list/list_parameter_controller.cpp @@ -17,6 +17,7 @@ ListParameterController::ListParameterController(Responder * parentResponder, Se ListParameterController::~ListParameterController() { if (m_typeLayout) { delete m_typeLayout; + m_typeLayout = nullptr; } } @@ -29,6 +30,7 @@ void ListParameterController::setSequence(Sequence * sequence) { m_sequence = sequence; if (m_typeLayout != nullptr) { delete m_typeLayout; + m_typeLayout = nullptr; } if (m_sequence->type() == Sequence::Type::Explicite) { m_typeLayout = new BaselineRelativeLayout(new StringLayout(m_sequence->name(), 1), new StringLayout("n", 1, KDText::FontSize::Small), BaselineRelativeLayout::Type::Subscript); diff --git a/apps/sequence/list/sequence_title_cell.cpp b/apps/sequence/list/sequence_title_cell.cpp index 35cda2364..1f99ccc16 100644 --- a/apps/sequence/list/sequence_title_cell.cpp +++ b/apps/sequence/list/sequence_title_cell.cpp @@ -21,6 +21,7 @@ SequenceTitleCell::~SequenceTitleCell() { for (int i = 0; i < 3; i++) { if (m_expressionLayouts[i]) { delete m_expressionLayouts[i]; + m_expressionLayouts[i] = nullptr; } } } @@ -28,8 +29,9 @@ SequenceTitleCell::~SequenceTitleCell() { void SequenceTitleCell::setSequence(Sequence * sequence) { SequenceCell::setSequence(sequence); for (int i = 0; i < 3; i++) { - if (m_expressionLayouts[i]) { + if (m_expressionLayouts[i]!= nullptr) { delete m_expressionLayouts[i]; + m_expressionLayouts[i] = nullptr; } } if (m_numberOfSubCells == 1) { diff --git a/apps/sequence/list/type_parameter_controller.cpp b/apps/sequence/list/type_parameter_controller.cpp index f22c4b9c7..980865867 100644 --- a/apps/sequence/list/type_parameter_controller.cpp +++ b/apps/sequence/list/type_parameter_controller.cpp @@ -21,6 +21,7 @@ TypeParameterController::~TypeParameterController() { for (int i = 0; i < k_totalNumberOfCell; i++) { if (m_expressionLayouts[i]) { delete m_expressionLayouts[i]; + m_expressionLayouts[i] = nullptr; } } } @@ -73,6 +74,7 @@ void TypeParameterController::willDisplayCellAtLocation(TableViewCell * cell, in const char * subscripts[3] = {"n", "n+1", "n+2"}; if (m_expressionLayouts[j]) { delete m_expressionLayouts[j]; + m_expressionLayouts[j] = nullptr; } m_expressionLayouts[j] = new BaselineRelativeLayout(new StringLayout(nextName, 1), new StringLayout(subscripts[j], strlen(subscripts[j]), KDText::FontSize::Small), BaselineRelativeLayout::Type::Subscript); TextExpressionMenuListCell * myCell = (TextExpressionMenuListCell *)cell; diff --git a/apps/sequence/sequence.cpp b/apps/sequence/sequence.cpp index 4bb0909f2..27d39409a 100644 --- a/apps/sequence/sequence.cpp +++ b/apps/sequence/sequence.cpp @@ -21,15 +21,19 @@ Sequence::~Sequence() { ((Function *)this)->Shared::Function::~Function(); if (m_firstInitialConditionLayout != nullptr) { delete m_firstInitialConditionLayout; + m_firstInitialConditionLayout = nullptr; } if (m_secondInitialConditionLayout != nullptr) { delete m_secondInitialConditionLayout; + m_secondInitialConditionLayout = nullptr; } if (m_firstInitialConditionExpression != nullptr) { delete m_firstInitialConditionExpression; + m_firstInitialConditionExpression = nullptr; } if (m_secondInitialConditionExpression != nullptr) { delete m_secondInitialConditionExpression; + m_secondInitialConditionExpression = nullptr; } } diff --git a/apps/shared/curve_view.cpp b/apps/shared/curve_view.cpp index 31a5b703b..6a124cb6e 100644 --- a/apps/shared/curve_view.cpp +++ b/apps/shared/curve_view.cpp @@ -1,9 +1,9 @@ #include "curve_view.h" #include "../constant.h" #include +#include #include #include -#include using namespace Poincare; diff --git a/apps/shared/function.cpp b/apps/shared/function.cpp index d15caa4e9..48b87df25 100644 --- a/apps/shared/function.cpp +++ b/apps/shared/function.cpp @@ -36,9 +36,11 @@ void Function::setColor(KDColor color) { Function::~Function() { if (m_layout != nullptr) { delete m_layout; + m_layout = nullptr; } if (m_expression != nullptr) { delete m_expression; + m_expression = nullptr; } }