Fix memory leak for { $foo: bar }
Before adoption: this commit came in with the history the project adopted, so no landing records it.
{ BINDING: ExpD } wasn't freeing BINDING. Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=60865
authored by Emanuele Torre · committed by Nico Williams · parent 5b9d075 · Browse files · 3 files·+24 added−18 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+24 added−18 removed
- tests:+5 added−1 removed
- other:+19 added−17 removed
Provenance
- Commit
17889a1- Tree
6149a68- Author
Emanuele Torre <torreemanuele6@gmail.com>- Committer
Nico Williams <nico@cryptonector.com>- Parent
5b9d075
3 files changed+24 added−18 removed
modified:src/parser.c+18 added-17 removed
978 unmodified lines979 830, 833, 838, 841, 846, 850, 853, 858, 861, 866,980 869, 874, 877, 880, 883, 886, 889, 897, 903, 906,981 909, 912, 915, 918, 921, 924, 927, 930, 933, 936,982 939, 942, 945, 948, 951, 954, 959, 962, 963, 964,983- 967, 970, 973, 976, 980, 984, 988, 992, 996, 1000,984- 1008983+ 967, 970, 973, 976, 980, 985, 989, 993, 997, 1001,984+ 1009985 };986 #endif987 988 /** Accessing symbol of state STATE. */3075 unmodified lines4064 #line 980 "src/parser.y"4065 {4066 (yyval.blk) = gen_dictpair(gen_location((yyloc), locations, gen_op_unbound(LOADV, jv_string_value((yyvsp[-2].literal)))),4067 (yyvsp[0].blk));4068+ jv_free((yyvsp[-2].literal));4069 }4069-#line 4070 "src/parser.c"4070+#line 4071 "src/parser.c"4071 break;4072 4073 case 165: /* MkDictPair: BINDING */4073-#line 984 "src/parser.y"4074+#line 985 "src/parser.y"4075 {4076 (yyval.blk) = gen_dictpair(gen_const((yyvsp[0].literal)),4077 gen_location((yyloc), locations, gen_op_unbound(LOADV, jv_string_value((yyvsp[0].literal)))));4078 }4078-#line 4079 "src/parser.c"4079+#line 4080 "src/parser.c"4080 break;4081 4082 case 166: /* MkDictPair: IDENT */4082-#line 988 "src/parser.y"4083+#line 989 "src/parser.y"4084 {4085 (yyval.blk) = gen_dictpair(gen_const(jv_copy((yyvsp[0].literal))),4086 gen_index(gen_noop(), gen_const((yyvsp[0].literal))));4087 }4087-#line 4088 "src/parser.c"4088+#line 4089 "src/parser.c"4089 break;4090 4091 case 167: /* MkDictPair: "$__loc__" */4091-#line 992 "src/parser.y"4092+#line 993 "src/parser.y"4093 {4094 (yyval.blk) = gen_dictpair(gen_const(jv_string("__loc__")),4095 gen_loc_object(&(yyloc), locations));4096 }4096-#line 4097 "src/parser.c"4097+#line 4098 "src/parser.c"4098 break;4099 4100 case 168: /* MkDictPair: Keyword */4100-#line 996 "src/parser.y"4101+#line 997 "src/parser.y"4102 {4103 (yyval.blk) = gen_dictpair(gen_const(jv_copy((yyvsp[0].literal))),4104 gen_index(gen_noop(), gen_const((yyvsp[0].literal))));4105 }4105-#line 4106 "src/parser.c"4106+#line 4107 "src/parser.c"4107 break;4108 4109 case 169: /* MkDictPair: '(' Exp ')' ':' ExpD */4109-#line 1000 "src/parser.y"4110+#line 1001 "src/parser.y"4111 {4112 jv msg = check_object_key((yyvsp[-3].blk));4113 if (jv_is_valid(msg)) {4114 FAIL((yyloc), jv_string_value(msg));4115 }4116 jv_free(msg);4117 (yyval.blk) = gen_dictpair((yyvsp[-3].blk), (yyvsp[0].blk));4118 }4118-#line 4119 "src/parser.c"4119+#line 4120 "src/parser.c"4120 break;4121 4122 case 170: /* MkDictPair: error ':' ExpD */4122-#line 1008 "src/parser.y"4123+#line 1009 "src/parser.y"4124 {4125 FAIL((yyloc), "May need parentheses around object key expression");4126 (yyval.blk) = (yyvsp[0].blk);4127 }4127-#line 4128 "src/parser.c"4128+#line 4129 "src/parser.c"4129 break;4130 4131 4131-#line 4132 "src/parser.c"4132+#line 4133 "src/parser.c"4133 4134 default: break;4135 }4136 /* User semantic actions sometimes alter yychar, and that requires220 unmodified lines4357 YYSTACK_FREE (yymsg);4358 return yyresult;4359 }4360 4360-#line 1012 "src/parser.y"4361+#line 1013 "src/parser.y"4362 4363 4364 int jq_parse(struct locfile* locations, block* answer) {4365 struct lexer_param scanner;25 unmodified linesmodified:src/parser.y+1 added
978 unmodified lines979 }980 | BINDING ':' ExpD {981 $$ = gen_dictpair(gen_location(@$, locations, gen_op_unbound(LOADV, jv_string_value($1))),982 $3);983+ jv_free($1);984 }985 | BINDING {986 $$ = gen_dictpair(gen_const($1),987 gen_location(@$, locations, gen_op_unbound(LOADV, jv_string_value($1))));54 unmodified linesmodified:tests/jq.test+5 added-1 removed
1847 unmodified lines1848 [10,9,8,7]1849 [10,19,27,34]1850 1851 1852-# { $__loc__ } works1852+# Object construction1853 1854 { a, $__loc__, c }1855 {"a":[1,2,3],"b":"foo","c":{"hi":"hey"}}1856 {"a":[1,2,3],"__loc__":{"file":"<top-level>","line":1},"c":{"hi":"hey"}}1857 1858+1 as $x | "2" as $y | "3" as $z | { $x, as, $y: 4, ($z): 5, if: 6, foo: 7 }1859+{"as":8}1860+{"x":1,"as":8,"2":4,"3":5,"if":6,"foo":7}1861 1862+1863 # nan is parsed as a valid NaN value from JSON1864 1865 fromjson | isnan1866 "nan"82 unmodified lines