From abeb4953354b7afb57ea71cf63184afae2b30edd Mon Sep 17 00:00:00 2001 From: A404M Date: Sun, 15 Jun 2025 00:04:44 +0330 Subject: fix double free bug in global variables --- src/runner/runner.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/runner/runner.c b/src/runner/runner.c index a847327..a1251a2 100644 --- a/src/runner/runner.c +++ b/src/runner/runner.c @@ -139,8 +139,7 @@ bool runAstTree(AstTreeRoots roots) { AstTreeVariable *mainVariable = NULL; - AstTreeScope *scope = a404m_malloc(sizeof(*scope)); - *scope = (AstTreeScope){ + AstTreeScope scope = { .expressions = a404m_malloc(0), .expressions_size = 0, .variables.data = a404m_malloc(0), @@ -165,7 +164,8 @@ bool runAstTree(AstTreeRoots roots) { } if (!variable->isConst) { runnerVariableSetValueWihtoutConstCheck(variable, variable->initValue, - scope); + &scope); + variable->initValue = NULL; } } } @@ -183,12 +183,11 @@ bool runAstTree(AstTreeRoots roots) { return false; } - AstTree *res = runAstTreeFunction(main, NULL, 0, scope, false); + AstTree *res = runAstTreeFunction(main, NULL, 0, &scope, false); const bool ret = res == &AST_TREE_VOID_VALUE; astTreeDelete(res); astTreeDelete(main); - astTreeDelete( - newAstTree(AST_TREE_TOKEN_SCOPE, scope, &AST_TREE_VOID_TYPE, NULL, NULL)); + astTreeScopeDestroy(scope); return ret; } -- cgit v1.2.3