diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2017-03-11 21:24:26 +0000 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2017-03-11 21:24:26 +0000 |
commit | de1f50c2bfa7dfc3b758a0cb89c856534c4ab3a1 (patch) | |
tree | 647378ab21d4c8ba9dae2179aa0c0c3b1b4cd933 | |
parent | c83c8f224e66d7e21e30546bae308ac5fd52677e (diff) | |
download | Compiler-de1f50c2bfa7dfc3b758a0cb89c856534c4ab3a1.tar.gz Compiler-de1f50c2bfa7dfc3b758a0cb89c856534c4ab3a1.zip |
improving memory leaks
-rw-r--r-- | c_compiler/src/c_parser.y | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/c_compiler/src/c_parser.y b/c_compiler/src/c_parser.y index d36c5ca..f262f58 100644 --- a/c_compiler/src/c_parser.y +++ b/c_compiler/src/c_parser.y @@ -97,7 +97,7 @@ ExternalDeclaration: // FUNCTION DEFINITION FunctionDefinition: - DeclarationSpec T_IDENTIFIER T_LRB ParameterList T_RRB CompoundStatement { $$ = new Function(*$2, $4, $6); } +DeclarationSpec T_IDENTIFIER T_LRB ParameterList T_RRB CompoundStatement { $$ = new Function(*$2, $4, $6); delete $2; } ; ParameterList: @@ -107,7 +107,7 @@ ParameterList: ; Parameter: - DeclarationSpec T_IDENTIFIER { $$ = new Declaration(*$2); } +DeclarationSpec T_IDENTIFIER { $$ = new Declaration(*$2); delete $2; } ; // Declaration @@ -142,13 +142,13 @@ DeclarationSpec: ; InitDeclaratorList: - InitDeclarator { $$ = new Declaration(*$1); } +InitDeclarator { $$ = new Declaration(*$1); delete $1;} | InitDeclaratorList T_CMA InitDeclarator { $3->addList($$); $$ = $3; } ; InitDeclarator: - Declarator { $$ = new Declaration(*$1); } -| Declarator T_EQ AssignmentExpression { $$ = new Declaration(*$1, $3); } +Declarator { $$ = new Declaration(*$1); delete $1; } +| Declarator T_EQ AssignmentExpression { $$ = new Declaration(*$1, $3); delete $1; } ; Declarator: @@ -278,7 +278,7 @@ ShiftExpression: AdditiveExpression: MultiplicativeExpression { $$ = $1; } -| AdditiveExpression T_ADDSUB_OP MultiplicativeExpression { $$ = new AdditiveExpression($1, *$2, $3); } +| AdditiveExpression T_ADDSUB_OP MultiplicativeExpression { $$ = new AdditiveExpression($1, *$2, $3); delete $2; } ; MultiplicativeExpression: @@ -333,7 +333,7 @@ ArgumentExpressionList: ; PrimaryExpression: - T_IDENTIFIER { $$ = new Identifier(*$1); } +T_IDENTIFIER { $$ = new Identifier(*$1); delete $1; } | Constant { $$ = $1; } | T_LRB Expression T_RRB { $$ = $2; } ; |