Skip to content

Commit 677286e

Browse files
committed
[ruby/prism] Ensure allocations to the constant pool are through the arena
ruby/prism@f5ae7b73ee
1 parent c133e04 commit 677286e

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

prism/prism.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20717,11 +20717,9 @@ parse_regular_expression_named_capture(pm_parser_t *parser, const pm_string_t *c
2071720717
start = parser->start + PM_NODE_START(call->receiver);
2071820718
end = parser->start + PM_NODE_END(call->receiver);
2071920719

20720-
void *memory = xmalloc(length);
20721-
if (memory == NULL) abort();
20722-
20720+
uint8_t *memory = (uint8_t *) pm_arena_alloc(parser->arena, length, 1);
2072320721
memcpy(memory, source, length);
20724-
name = pm_parser_constant_id_owned(parser, (uint8_t *) memory, length);
20722+
name = pm_parser_constant_id_owned(parser, memory, length);
2072520723
}
2072620724

2072720725
// Add this name to the list of constants if it is valid, not duplicated,
@@ -22267,11 +22265,9 @@ pm_parser_init(pm_arena_t *arena, pm_parser_t *parser, const uint8_t *source, si
2226722265
const uint8_t *source = pm_string_source(local);
2226822266
size_t length = pm_string_length(local);
2226922267

22270-
void *allocated = xmalloc(length);
22271-
if (allocated == NULL) continue;
22272-
22268+
uint8_t *allocated = (uint8_t *) pm_arena_alloc(&parser->metadata_arena, length, 1);
2227322269
memcpy(allocated, source, length);
22274-
pm_parser_local_add_owned(parser, (uint8_t *) allocated, length);
22270+
pm_parser_local_add_owned(parser, allocated, length);
2227522271
}
2227622272
}
2227722273
}

0 commit comments

Comments
 (0)