From 82c82ae93ddd19cb8cbcc5fffe1710dc8a8d66de Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sat, 27 Jul 2019 18:30:05 +0200 Subject: [PATCH] Fixed memory issue when assigning new method options --- src/Evaluator/EvalValues/ScriptFunctionEvalValue.hpp | 11 ++++++----- src/Evaluator/Evaluator.cpp | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Evaluator/EvalValues/ScriptFunctionEvalValue.hpp b/src/Evaluator/EvalValues/ScriptFunctionEvalValue.hpp index 46e8100..d2eb5b9 100644 --- a/src/Evaluator/EvalValues/ScriptFunctionEvalValue.hpp +++ b/src/Evaluator/EvalValues/ScriptFunctionEvalValue.hpp @@ -25,15 +25,15 @@ namespace Porygon::Evaluation { public: EvaluationScriptFunctionOption(shared_ptr innerBlock, shared_ptr scope) - : _innerBlock(std::move(innerBlock)), _scope(std::move(scope)) { + : GenericFunctionOption(), _innerBlock(std::move(innerBlock)), _scope(std::move(scope)) { } - ~EvaluationScriptFunctionOption() final = default; + ~EvaluationScriptFunctionOption() final{}; - inline std::shared_ptr GetInnerBlock() const { + [[nodiscard]] inline std::shared_ptr GetInnerBlock() const { return _innerBlock; } - inline const std::shared_ptr &GetScope() const { + [[nodiscard]] inline const std::shared_ptr &GetScope() const { return _scope; } }; @@ -50,7 +50,8 @@ namespace Porygon::Evaluation { public: GenericFunctionEvalValue(shared_ptr type, size_t hash) : _type(move(type)), - _hash(hash), _options(make_shared>>()){ + _hash(hash), + _options(make_shared>>()){ } GenericFunctionEvalValue(const GenericFunctionEvalValue& _) = delete; diff --git a/src/Evaluator/Evaluator.cpp b/src/Evaluator/Evaluator.cpp index 105082b..8c8ee40 100644 --- a/src/Evaluator/Evaluator.cpp +++ b/src/Evaluator/Evaluator.cpp @@ -108,9 +108,9 @@ namespace Porygon::Evaluation { auto value = EvalValuePointer(p); this->_evaluationScope->CreateVariable(key, value); } else { - auto var = (GenericFunctionEvalValue*)this -> _evaluationScope ->GetVariable(key).Get(); + auto var = (GenericFunctionEvalValue*)this -> _evaluationScope ->GetVariable(key).Take(); var->RegisterOption(option); - //this->_evaluationScope->SetVariable(key, var); + delete var; } }