Skip to content

Commit 0b74087

Browse files
authored
Merge pull request #23 from LangProc/fix-mem-leak
Fixed memory leaks in parser
2 parents 574d65e + e58cb78 commit 0b74087

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/parser.y

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
extern FILE *yyin;
1212
int yylex(void);
1313
void yyerror(const char *);
14+
int yylex_destroy(void);
1415
}
1516

1617
// Represents the value associated with any kind of AST node.
@@ -202,5 +203,7 @@ Node *ParseAST(std::string file_name)
202203
}
203204
g_root = nullptr;
204205
yyparse();
206+
fclose(yyin);
207+
yylex_destroy();
205208
return g_root;
206209
}

src/parser_full.y.example

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
extern FILE *yyin;
88
int yylex(void);
99
void yyerror(const char *);
10+
int yylex_destroy(void);
1011
}
1112

1213
// Represents the value associated with any kind of AST node.
@@ -468,5 +469,7 @@ Node *ParseAST(std::string file_name)
468469
}
469470
g_root = nullptr;
470471
yyparse();
472+
fclose(yyin);
473+
yylex_destroy();
471474
return g_root;
472475
}

0 commit comments

Comments
 (0)