Skip to content

Commit 0071bee

Browse files
committed
Fix memory leak from constant write node creation
1 parent 3c8a8f9 commit 0071bee

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/yarp.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,18 +1701,18 @@ yp_constant_read_node_create(yp_parser_t *parser, const yp_token_t *name) {
17011701

17021702
// Allocate a new ConstantWriteNode node.
17031703
static yp_constant_write_node_t *
1704-
yp_constant_write_node_create(yp_parser_t *parser, yp_constant_read_node_t *target, const yp_token_t *operator, yp_node_t *value) {
1704+
yp_constant_write_node_create(yp_parser_t *parser, yp_location_t *name_loc, const yp_token_t *operator, yp_node_t *value) {
17051705
yp_constant_write_node_t *node = YP_ALLOC_NODE(parser, yp_constant_write_node_t);
17061706

17071707
*node = (yp_constant_write_node_t) {
17081708
{
17091709
.type = YP_NODE_CONSTANT_WRITE_NODE,
17101710
.location = {
1711-
.start = target->base.location.start,
1712-
.end = value != NULL ? value->location.end : target->base.location.end
1711+
.start = name_loc->start,
1712+
.end = value != NULL ? value->location.end : name_loc->end
17131713
},
17141714
},
1715-
.name_loc = YP_LOCATION_NODE_VALUE((yp_node_t *) target),
1715+
.name_loc = *name_loc,
17161716
.operator_loc = YP_OPTIONAL_LOCATION_TOKEN_VALUE(operator),
17171717
.value = value
17181718
};
@@ -7582,8 +7582,12 @@ parse_target(yp_parser_t *parser, yp_node_t *target, yp_token_t *operator, yp_no
75827582
}
75837583
case YP_NODE_CONSTANT_PATH_NODE:
75847584
return (yp_node_t *) yp_constant_path_write_node_create(parser, target, operator, value);
7585-
case YP_NODE_CONSTANT_READ_NODE:
7586-
return (yp_node_t *) yp_constant_write_node_create(parser, (yp_constant_read_node_t *) target, operator, value);
7585+
case YP_NODE_CONSTANT_READ_NODE: {
7586+
yp_constant_write_node_t *node = yp_constant_write_node_create(parser, &target->location, operator, value);
7587+
yp_node_destroy(parser, target);
7588+
7589+
return (yp_node_t *) node;
7590+
}
75877591
case YP_NODE_BACK_REFERENCE_READ_NODE:
75887592
case YP_NODE_NUMBERED_REFERENCE_READ_NODE:
75897593
yp_diagnostic_list_append(&parser->error_list, target->location.start, target->location.end, "Can't set variable");

0 commit comments

Comments
 (0)