Skip to content

[PRISM] Fix memory leak in iseq #9592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 18, 2024

Conversation

peterzhu2118
Copy link
Member

rb_iseq_compile_prism_node calls both rb_translate_prism and iseq_setup. Both of these functions call iseq_set_sequence. This means that the first iseq_set_sequence will leak because the iseq will be overwritten.

For example:

10.times do
  100_000.times do
    RubyVM::InstructionSequence.compile_prism("")
  end

  puts `ps -o rss= -p #{$$}`
end

Before:

20528
27328
33840
40208
46400
52960
59168
65600
71888
78352

After:

13696
13712
13712
13712
13712
14352
14352
14992
14992
14992

rb_iseq_compile_prism_node calls both rb_translate_prism and iseq_setup.
Both of these functions call iseq_set_sequence. This means that the first
iseq_set_sequence will leak because the iseq will be overwritten.

For example:

    10.times do
      100_000.times do
        RubyVM::InstructionSequence.compile_prism("")
      end

      puts `ps -o rss= -p #{$$}`
    end

Before:

    20528
    27328
    33840
    40208
    46400
    52960
    59168
    65600
    71888
    78352

After:

    13696
    13712
    13712
    13712
    13712
    14352
    14352
    14992
    14992
    14992
@peterzhu2118 peterzhu2118 merged commit 00814fd into ruby:master Jan 18, 2024
@peterzhu2118 peterzhu2118 deleted the prism-iseq-mem-leak branch January 18, 2024 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants