From fe6314a6e06ca93579fc403e5a0bf5ce164d79d7 Mon Sep 17 00:00:00 2001 From: yhirose Date: Thu, 23 Jan 2020 21:57:13 -0500 Subject: [PATCH] Fixed semantic values stack leak --- peglib.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/peglib.h b/peglib.h index 906507f..1369fd4 100644 --- a/peglib.h +++ b/peglib.h @@ -829,12 +829,15 @@ public: , enablePackratParsing(a_enablePackratParsing) , cache_registered(enablePackratParsing ? def_count * (l + 1) : 0) , cache_success(enablePackratParsing ? def_count * (l + 1) : 0) - , tracer(a_tracer) - { + , tracer(a_tracer) { args_stack.resize(1); capture_scope_stack.resize(1); } + ~Context() { + assert(!value_stack_size); + } + template void packrat(const char* a_s, size_t def_id, size_t& len, any& val, T fn) { if (!enablePackratParsing) { @@ -948,6 +951,7 @@ public: size_t parse(const char* s, size_t n, SemanticValues& sv, Context& c, any& dt) const override { c.trace("Sequence", s, n, sv, dt); auto& chldsv = c.push(); + auto pop_se = make_scope_exit([&]() { c.pop(); }); size_t i = 0; for (const auto& ope : opes_) { c.nest_level++;