fix memory leak on error

This commit is contained in:
r4 2021-12-21 14:04:50 +01:00
parent 005309d1eb
commit 61d5661b96
2 changed files with 3 additions and 1 deletions

View File

@ -371,7 +371,7 @@ IRToks parse(TokList *toks) {
for (;;) {
if (toks->begin->tok.kind == TokOp && toks->begin->tok.Op == OpEOF)
break;
TRY_RET(stmt(&s, &global_scope, toks->begin), ir);
TRY_RET_ELSE(stmt(&s, &global_scope, toks->begin), ir, term_scope(&global_scope));
}
term_scope(&global_scope);
return ir;

2
util.h
View File

@ -32,7 +32,9 @@ extern char errbuf[ERRSZ];
extern bool err;
extern size_t err_ln, err_col;
#define TRY(expr) {expr; if (err) return;}
#define TRY_ELSE(expr, onerr) {expr; if (err) {onerr; return;}}
#define TRY_RET(expr, ret) {expr; if (err) return (ret);}
#define TRY_RET_ELSE(expr, ret, onerr) {expr; if (err) {onerr; return (ret);}}
void set_err(const char *fmt, ...);
#define ASSERT_UNREACHED() { fprintf(stderr, "Illegal code position reached in %s:%d\n", __FILE__, __LINE__); exit(1); }