patterns: Fixed memory leak when using format attribute

This commit is contained in:
WerWolv
2022-03-03 12:11:47 +01:00
parent 2880ca00da
commit 949a26ca0e
16 changed files with 51 additions and 49 deletions

View File

@@ -15,6 +15,8 @@
#include <hex/pattern_language/patterns/pattern_string.hpp>
#include <hex/pattern_language/patterns/pattern_enum.hpp>
#include <hex/helpers/logger.hpp>
namespace hex::pl {
void Evaluator::createParameterPack(const std::string &name, const std::vector<Token::Literal> &values) {
@@ -56,7 +58,7 @@ namespace hex::pl {
pattern = std::unique_ptr<Pattern>(new PatternCharacter(this, 0));
else if (std::get_if<std::string>(&value.value()) != nullptr)
pattern = std::unique_ptr<Pattern>(new PatternString(this, 0, 1));
else if (auto patternValue = std::get_if<std::shared_ptr<Pattern>>(&value.value()); patternValue != nullptr) {
else if (auto patternValue = std::get_if<Pattern *>(&value.value()); patternValue != nullptr) {
pattern = (*patternValue)->clone();
referenceType = true;
} else
@@ -127,7 +129,7 @@ namespace hex::pl {
else
LogConsole::abortEvaluation(hex::format("cannot cast type 'string' to type '{}'", pattern->getTypeName()));
},
[&](const std::shared_ptr<Pattern> &value) -> Token::Literal {
[&](Pattern *value) -> Token::Literal {
if (value->getTypeName() == pattern->getTypeName())
return value;
else