From 60149b33c1073adf044fd3723812f4e58faabce0 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 17 Dec 2007 17:55:21 -0500 Subject: [PATCH] BUG: Fixed memory-leaks in fortran parser. --- Source/cmDependsFortranParser.cxx | 69 ++++++++++++++++++++----------- Source/cmDependsFortranParser.y | 15 +++++-- 2 files changed, 55 insertions(+), 29 deletions(-) diff --git a/Source/cmDependsFortranParser.cxx b/Source/cmDependsFortranParser.cxx index bbc2ffd21..4c5fb01cc 100644 --- a/Source/cmDependsFortranParser.cxx +++ b/Source/cmDependsFortranParser.cxx @@ -611,11 +611,11 @@ static const yytype_int8 yyrhs[] = /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const yytype_uint16 yyrline[] = { - 0, 161, 161, 161, 163, 163, 165, 168, 178, 211, - 212, 219, 225, 231, 237, 243, 248, 253, 258, 263, - 264, 265, 266, 271, 271, 271, 272, 272, 273, 273, - 274, 274, 275, 275, 276, 276, 277, 277, 278, 278, - 279, 279, 280, 280, 283, 284, 285, 286, 287 + 0, 161, 161, 161, 163, 163, 165, 171, 181, 211, + 216, 223, 229, 235, 241, 247, 252, 257, 262, 267, + 271, 272, 273, 278, 278, 278, 279, 279, 280, 280, + 281, 281, 282, 282, 283, 283, 284, 284, 285, 285, + 286, 286, 287, 287, 290, 291, 292, 293, 294 }; #endif @@ -1580,8 +1580,15 @@ yyreduce: YY_REDUCE_PRINT (yyn); switch (yyn) { - case 7: -#line 169 "cmDependsFortranParser.y" + case 6: +#line 166 "cmDependsFortranParser.y" + { + free((yyvsp[(1) - (4)].string)); + } + break; + + case 7: +#line 172 "cmDependsFortranParser.y" { if (cmDependsFortranParserIsKeyword((yyvsp[(1) - (2)].string), "interface")) { @@ -1594,28 +1601,25 @@ yyreduce: break; case 8: -#line 179 "cmDependsFortranParser.y" +#line 182 "cmDependsFortranParser.y" { if (cmDependsFortranParserIsKeyword((yyvsp[(1) - (4)].string), "use")) { cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner); cmDependsFortranParser_RuleUse(parser, (yyvsp[(2) - (4)].string)); - free((yyvsp[(2) - (4)].string)); } else if (cmDependsFortranParserIsKeyword((yyvsp[(1) - (4)].string), "module")) { cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner); cmDependsFortranParser_RuleModule(parser, (yyvsp[(2) - (4)].string)); - free((yyvsp[(2) - (4)].string)); } else if (cmDependsFortranParserIsKeyword((yyvsp[(1) - (4)].string), "interface")) { cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner); cmDependsFortranParser_SetInInterface(parser, true); - free((yyvsp[(2) - (4)].string)); } else if (cmDependsFortranParserIsKeyword((yyvsp[(2) - (4)].string), "interface") && cmDependsFortranParserIsKeyword((yyvsp[(1) - (4)].string), "end")) @@ -1623,14 +1627,22 @@ yyreduce: cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner); cmDependsFortranParser_SetInInterface(parser, false); - free((yyvsp[(2) - (4)].string)); } free((yyvsp[(1) - (4)].string)); + free((yyvsp[(2) - (4)].string)); + } + break; + + case 9: +#line 212 "cmDependsFortranParser.y" + { + free((yyvsp[(1) - (4)].string)); + free((yyvsp[(2) - (4)].string)); } break; case 10: -#line 213 "cmDependsFortranParser.y" +#line 217 "cmDependsFortranParser.y" { cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner); @@ -1640,7 +1652,7 @@ yyreduce: break; case 11: -#line 220 "cmDependsFortranParser.y" +#line 224 "cmDependsFortranParser.y" { cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner); cmDependsFortranParser_RuleDefine(parser, (yyvsp[(2) - (4)].string)); @@ -1649,7 +1661,7 @@ yyreduce: break; case 12: -#line 226 "cmDependsFortranParser.y" +#line 230 "cmDependsFortranParser.y" { cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner); cmDependsFortranParser_RuleUndef(parser, (yyvsp[(2) - (4)].string)); @@ -1658,7 +1670,7 @@ yyreduce: break; case 13: -#line 232 "cmDependsFortranParser.y" +#line 236 "cmDependsFortranParser.y" { cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner); cmDependsFortranParser_RuleIfdef(parser, (yyvsp[(2) - (4)].string)); @@ -1667,7 +1679,7 @@ yyreduce: break; case 14: -#line 238 "cmDependsFortranParser.y" +#line 242 "cmDependsFortranParser.y" { cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner); cmDependsFortranParser_RuleIfndef(parser, (yyvsp[(2) - (4)].string)); @@ -1676,7 +1688,7 @@ yyreduce: break; case 15: -#line 244 "cmDependsFortranParser.y" +#line 248 "cmDependsFortranParser.y" { cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner); cmDependsFortranParser_RuleIf(parser); @@ -1684,7 +1696,7 @@ yyreduce: break; case 16: -#line 249 "cmDependsFortranParser.y" +#line 253 "cmDependsFortranParser.y" { cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner); cmDependsFortranParser_RuleElif(parser); @@ -1692,7 +1704,7 @@ yyreduce: break; case 17: -#line 254 "cmDependsFortranParser.y" +#line 258 "cmDependsFortranParser.y" { cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner); cmDependsFortranParser_RuleElse(parser); @@ -1700,26 +1712,33 @@ yyreduce: break; case 18: -#line 259 "cmDependsFortranParser.y" +#line 263 "cmDependsFortranParser.y" { cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner); cmDependsFortranParser_RuleEndif(parser); } break; + case 19: +#line 268 "cmDependsFortranParser.y" + { + free((yyvsp[(1) - (4)].string)); + } + break; + case 44: -#line 283 "cmDependsFortranParser.y" +#line 290 "cmDependsFortranParser.y" { free ((yyvsp[(1) - (1)].string)); } break; case 45: -#line 284 "cmDependsFortranParser.y" +#line 291 "cmDependsFortranParser.y" { free ((yyvsp[(1) - (1)].string)); } break; /* Line 1267 of yacc.c. */ -#line 1723 "cmDependsFortranParser.cxx" +#line 1742 "cmDependsFortranParser.cxx" default: break; } YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); @@ -1935,7 +1954,7 @@ yyreturn: } -#line 290 "cmDependsFortranParser.y" +#line 297 "cmDependsFortranParser.y" /* End of grammar */ diff --git a/Source/cmDependsFortranParser.y b/Source/cmDependsFortranParser.y index 8e6456d0e..13c5f3233 100644 --- a/Source/cmDependsFortranParser.y +++ b/Source/cmDependsFortranParser.y @@ -163,6 +163,9 @@ code: /* empty */ | code stmt; stmt: keyword_stmt | assignment_stmt; assignment_stmt: WORD ASSIGNMENT_OP other EOSTMT /* Ignore */ + { + free($1); + } keyword_stmt: WORD EOSTMT @@ -182,21 +185,18 @@ keyword_stmt: cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner); cmDependsFortranParser_RuleUse(parser, $2); - free($2); } else if (cmDependsFortranParserIsKeyword($1, "module")) { cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner); cmDependsFortranParser_RuleModule(parser, $2); - free($2); } else if (cmDependsFortranParserIsKeyword($1, "interface")) { cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner); cmDependsFortranParser_SetInInterface(parser, true); - free($2); } else if (cmDependsFortranParserIsKeyword($2, "interface") && cmDependsFortranParserIsKeyword($1, "end")) @@ -204,11 +204,15 @@ keyword_stmt: cmDependsFortranParser* parser = cmDependsFortran_yyget_extra(yyscanner); cmDependsFortranParser_SetInInterface(parser, false); - free($2); } free($1); + free($2); } | WORD STRING other EOSTMT /* Ignore */ + { + free($1); + free($2); + } | include STRING other EOSTMT { cmDependsFortranParser* parser = @@ -261,6 +265,9 @@ keyword_stmt: cmDependsFortranParser_RuleEndif(parser); } | WORD GARBAGE other EOSTMT /* Ignore */ + { + free($1); + } | GARBAGE other EOSTMT | EOSTMT | error