From 726924917d84060e932b379dba6519e78cd8e79e Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Thu, 20 Mar 2025 00:18:30 +0100 Subject: [PATCH] Teach the mood parser to not leak on errors. Attempting to load an incomplete mood definition such as "1 &&" currently causes memory leaks because the memory for the partial syntax tree is never freed. Employ bison's %destructor directive to call mp_free_ast() whenever a syntax error happens. --- yy/mp.y | 3 +++ 1 file changed, 3 insertions(+) diff --git a/yy/mp.y b/yy/mp.y index dc04488f..f2f0756d 100644 --- a/yy/mp.y +++ b/yy/mp.y @@ -350,6 +350,9 @@ bool mp_eval_ast(struct mp_ast_node *root, struct mp_context *ctx) %type exp %type boolexp +/* Called when a symbol is automatically discarded due to a syntax error. */ +%destructor {mp_free_ast($$);} string exp boolexp + %% program: -- 2.39.5