]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Teach the mood parser to not leak on errors.
authorAndre Noll <maan@tuebingen.mpg.de>
Wed, 19 Mar 2025 23:18:30 +0000 (00:18 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Mon, 24 Mar 2025 21:42:49 +0000 (22:42 +0100)
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

diff --git a/yy/mp.y b/yy/mp.y
index dc04488f7145dbbc48079cb7c7ba35ad4bf995d3..f2f0756d5c0348efde016bfcc4c9dcd97433e06c 100644 (file)
--- 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 <node> exp
 %type <node> boolexp
 
+/* Called when a symbol is automatically discarded due to a syntax error. */
+%destructor {mp_free_ast($$);} string exp boolexp
+
 %%
 
 program: