Prevent local stack memory leakage when parsing (#302)

We need to resets current_block to a nullptr after parsing the template
in `parse_into`, otherwise, current_block will refer to local stack
space after we return from Parser::parse.
This commit is contained in:
Florian Sattler
2025-03-19 02:20:34 +01:00
committed by GitHub
parent 808c3711d0
commit 34514c2658
2 changed files with 4 additions and 0 deletions

View File

@@ -573,6 +573,7 @@ class Parser {
throw_parser_error("unmatched for");
}
}
current_block = nullptr;
return;
case Token::Kind::Text: {
current_block->nodes.emplace_back(std::make_shared<TextNode>(tok.text.data() - tmpl.content.c_str(), tok.text.size()));
@@ -617,6 +618,7 @@ class Parser {
} break;
}
}
current_block = nullptr;
}
public:

View File

@@ -2016,6 +2016,7 @@ class Parser {
throw_parser_error("unmatched for");
}
}
current_block = nullptr;
return;
case Token::Kind::Text: {
current_block->nodes.emplace_back(std::make_shared<TextNode>(tok.text.data() - tmpl.content.c_str(), tok.text.size()));
@@ -2060,6 +2061,7 @@ class Parser {
} break;
}
}
current_block = nullptr;
}
public: