Skip to content

Commit c341399

Browse files
committed
Fix memory leak in pm_parse_process
pm_parse_process initializes the index_lookup_table but nothing seems to use it after it has been allocated. However, pm_compile_scope_node will overwrite the index_lookup_table and cause it to leak memory. This can be seen during bootup with the following memory leaks reported by ASAN: #0 0x60dba31b7af3 in malloc #1 0x60dba32e0718 in rb_gc_impl_malloc gc/default/default.c:8287:5 #2 0x60dba32c7aa7 in ruby_xmalloc_body gc.c:5373:12 #3 0x60dba32c4a54 in ruby_xmalloc gc.c:5355:34 #4 0x60dba3260314 in pm_index_lookup_table_init_heap prism_compile.h:89:29 #5 0x60dba3209388 in pm_parse_process prism_compile.c:11366:5
1 parent 77b803c commit c341399

1 file changed

Lines changed: 0 additions & 6 deletions

File tree

prism_compile.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11362,12 +11362,6 @@ pm_parse_process(pm_parse_result_t *result, pm_node_t *node, VALUE *script_lines
1136211362
pm_intern_constants_ctx_t intern_ctx = { .constants = scope_node->constants, .encoding = scope_node->encoding, .index = 0 };
1136311363
pm_parser_constants_each(parser, pm_intern_constants_callback, &intern_ctx);
1136411364

11365-
pm_constant_id_list_t *locals = &scope_node->locals;
11366-
pm_index_lookup_table_init_heap(&scope_node->index_lookup_table, (int) constants_size);
11367-
for (size_t index = 0; index < locals->size; index++) {
11368-
pm_index_lookup_table_insert(&scope_node->index_lookup_table, locals->ids[index], (int) index);
11369-
}
11370-
1137111365
// If we got here, this is a success and we can return Qnil to indicate that
1137211366
// no error should be raised.
1137311367
result->parsed = true;

0 commit comments

Comments
 (0)